Programming for Everybody: csharp
Showing posts with label csharp. Show all posts
Showing posts with label csharp. 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;

            }

        }

          

    }

}


Simple and Effective: Creating Invoices with Crystal Reports in C# With Source code

Source Code:
 SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=products;Integrated Security=True");
            conn.Open();
            SqlCommand cmd = new SqlCommand("Select * From View_3 Where n_invoice=@n_invoice", conn);
            cmd.Parameters.AddWithValue("n_invoice", textBox1.Text.Trim());
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            dt.Clear();
            da.Fill(dt);
            conn.Close();
            CrystalReport1 report = new CrystalReport1();
            report.SetDataSource(dt);
            crystalReportViewer1.ReportSource = report;
            crystalReportViewer1.Refresh();



c# tutorial for beginners: How to store images update and delete in sql database with code





using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Data.SqlClient;

using System.IO;


namespace Images

{

    public partial class Form2 : Form

    {

        public Form2()

        {

            InitializeComponent();

        }

        SqlConnection conn = new SqlConnection("Data source=.;Initial catalog=images3;Integrated Security = true");

        SqlCommand cmd;

        private void button1_Click(object sender, EventArgs e)

        {

            openFileDialog1.Filter = "Select image(*.JpG; *.png; *.Gif)|*.JpG; *.png; *.Gif";

            if (openFileDialog1.ShowDialog()== DialogResult.OK)

            {

                pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);

            }

        }


        private void button2_Click(object sender, EventArgs e)

        {

            cmd = new SqlCommand("Insert Into table1(name_image,image1)Values(@name_image,@image1)", conn);

            cmd.Parameters.AddWithValue("name_image", textBox1.Text);

            MemoryStream memstr = new MemoryStream();

            pictureBox1.Image.Save(memstr, pictureBox1.Image.RawFormat);

            cmd.Parameters.AddWithValue("image1", memstr.ToArray());

            conn.Open();

            cmd.ExecuteNonQuery();

            conn.Close();

            MessageBox.Show("Data Inserted Successfully");

            load_data();

        }

        private void load_data()

        {

            cmd = new SqlCommand("Select * from table1 order by id desc", conn);

            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd;

            DataTable dt = new DataTable();

            dt.Clear();

            da.Fill(dt);

            dataGridView1.RowTemplate.Height = 75;

            dataGridView1.DataSource = dt;

            DataGridViewImageColumn pic1 = new DataGridViewImageColumn();

            pic1 = (DataGridViewImageColumn)dataGridView1.Columns[2];

            pic1.ImageLayout = DataGridViewImageCellLayout.Stretch;

        }


        private void Form2_Load(object sender, EventArgs e)

        {

            load_data();

        }


        private void dataGridView1_Click(object sender, EventArgs e)

        {

            id1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();

            textBox1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();

            MemoryStream ms = new MemoryStream((byte[])dataGridView1.CurrentRow.Cells[2].Value);

            pictureBox1.Image = Image.FromStream(ms);

        }


        private void button3_Click(object sender, EventArgs e)

        {

            cmd = new SqlCommand("Update table1 Set name_image = @name_image,image1=@image1 Where id=@id", conn);

            cmd.Parameters.AddWithValue("name_image", textBox1.Text);

            MemoryStream memstr = new MemoryStream();

            pictureBox1.Image.Save(memstr, pictureBox1.Image.RawFormat);

            cmd.Parameters.AddWithValue("image1", memstr.ToArray());

            cmd.Parameters.AddWithValue("id", id1.Text);

            conn.Open();

            cmd.ExecuteNonQuery();

            conn.Close();

            load_data();

        }


        private void button4_Click(object sender, EventArgs e)

        {

            cmd = new SqlCommand("Delete from table1 where id=@id", conn);

            cmd.Parameters.AddWithValue("id", id1.Text);

            conn.Open();

            cmd.ExecuteNonQuery();

            conn.Close();

            load_data();

            pictureBox1.Image = null;

            textBox1.Text = "";

            id1.Text = "";

        }

    }

}


Programming with C # tutorial: Login Form in C # with SQL Server

 





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;
using System.Data.SqlClient;


namespace login
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data source=.; initial catalog=users;integrated security=true");

            SqlCommand cmd = new SqlCommand("select * from login1 where user1=@user1 and pass1=@pass1", conn);

            cmd.Parameters.Add("@user1", SqlDbType.VarChar).Value = textBox1.Text;

            cmd.Parameters.Add("@pass1", SqlDbType.VarChar).Value = textBox2.Text;


            SqlDataAdapter adapter1 = new SqlDataAdapter(cmd);

            DataTable table = new DataTable();

            adapter1.Fill(table);

            if (table.Rows.Count == 1)
            {

                Form2 gg = new Form2();

                gg.Show();

                this.Hide();

            }
            else
            {
                MessageBox.Show("Error username or password");


            }



        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox1.Checked == true)
            {
                textBox2.UseSystemPasswordChar = false;
            }
            else
            {

                textBox2.UseSystemPasswordChar = true;
            }



        }

       
    }

    }