Programming for Everybody: beginner c# tutorial
Showing posts with label beginner c# tutorial. Show all posts
Showing posts with label beginner c# tutorial. Show all posts

programming in C# : System calculates installments and due dates With Source code



using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;


namespace System_calculate_installments

{

    public partial class Form2 : Form

    {

        public Form2()

        {

            InitializeComponent();

        }

        DataTable dt = new DataTable();

        private void Form2_Load(object sender, EventArgs e)

        {

            dt.Columns.Add("Installment", typeof(string));

            dt.Columns.Add("Value", typeof(double));

            dt.Columns.Add("Due_date", typeof(DateTime));

            dataGridView1.DataSource = dt;

        }


        private void button1_Click(object sender, EventArgs e)

        {

            double price_v, adv_payment, installment_value, n_installments,final_installment;

            price_v = double.Parse(textBox1.Text);

            adv_payment = double.Parse(textBox2.Text);

            installment_value = double.Parse(textBox3.Text);

            n_installments = Math.Ceiling((price_v - adv_payment) / installment_value);

            final_installment = (price_v - adv_payment) % installment_value;

            dataGridView1.DataSource = null;

            dt.Clear();

            dataGridView1.DataSource = dt;

            for (int i = 1; i <= n_installments; i++)

            {

                var date_payment = (DateTime.Today.AddMonths(i)).ToString("MM-dd-yyyy");

                dt.Rows.Add("Installment" + i, textBox3.Text, date_payment);

            }

            if (final_installment != 0)

            {

                int lastrow = dataGridView1.Rows.Count - 1;

                dataGridView1.Rows[lastrow].Cells[1].Value = final_installment;

            }

        }

          

    }

}


ASP.NET C# insert update delete using SQL database and Load data in Gridview (WITH CODE)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;



using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Configuration;

public partial class _Default : System.Web.UI.Page

{

    public SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["webaspConnectionString"].ConnectionString);

    protected void Page_Load(object sender, EventArgs e)

    {

        GridView1.DataBind();

    }


    protected void Button1_Click(object sender, EventArgs e)

    {

        SqlCommand cmd = new SqlCommand("Insert Into Table1(firstname,lastname,marks)Values(@firstname,@lastname,@marks)", conn);

        cmd.Parameters.AddWithValue("firstname", ftxt.Text.Trim());

        cmd.Parameters.AddWithValue("lastname", ltxt.Text.Trim());

        cmd.Parameters.AddWithValue("marks", mtxt.Text.Trim());

        conn.Open();

        cmd.ExecuteNonQuery();

        conn.Close();

        result_lbl.Visible = true;

        result_lbl.ForeColor = System.Drawing.Color.Green;

        result_lbl.Text = "Data Inserted Successfully";

        GridView1.DataBind();

    }


    protected void Button2_Click(object sender, EventArgs e)

    {

        ftxt.Text = "";

        ltxt.Text = "";

        mtxt.Text = "";

        id_lbl.Text = "";

        result_lbl.Text = "";

    }


    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

        id_lbl.Text = GridView1.SelectedRow.Cells[0].Text.ToString();

        ftxt.Text = GridView1.SelectedRow.Cells[1].Text.ToString();

        ltxt.Text = GridView1.SelectedRow.Cells[2].Text.ToString();

        mtxt.Text = GridView1.SelectedRow.Cells[3].Text.ToString();

    }


    protected void Button3_Click(object sender, EventArgs e)

    {

        SqlCommand cmd = new SqlCommand("Update Table1 Set firstname=@firstname,lastname=@lastname,marks=@marks Where id=@id", conn);

        cmd.Parameters.AddWithValue("firstname", ftxt.Text.Trim());

        cmd.Parameters.AddWithValue("lastname", ltxt.Text.Trim());

        cmd.Parameters.AddWithValue("marks", mtxt.Text.Trim());

        cmd.Parameters.AddWithValue("id", id_lbl.Text.Trim());

        conn.Open();

        cmd.ExecuteNonQuery();

        conn.Close();

        result_lbl.Visible = true;

        result_lbl.ForeColor = System.Drawing.Color.Green;

        result_lbl.Text = "Data Updated Successfully";

        GridView1.DataBind();

    }


    protected void Button4_Click(object sender, EventArgs e)

    {

        SqlCommand cmd = new SqlCommand("Delete From Table1 Where id=@id", conn);

                cmd.Parameters.AddWithValue("id", id_lbl.Text.Trim());

        conn.Open();

        cmd.ExecuteNonQuery();

        conn.Close();

        result_lbl.Visible = true;

        result_lbl.ForeColor = System.Drawing.Color.Red;

        result_lbl.Text = "Data Deleted Successfully";

        GridView1.DataBind();

        ftxt.Text = "";

        ltxt.Text = "";

        mtxt.Text = "";

        id_lbl.Text = "";

        

    }