C#.net

Milk Inventory System C#.net with Print Receipt

The Milk Inventory Management System is developed using c#.net and sqlserver. The project is built to manage sales and transactions. To make a new transaction, fields such as: Milk type, qty,price and payment needs to be selected. If you like to learn point of sales systems step by step, this is the right place to learn from the beginning. In this tutorial, we will learn crystal reports step by step and design and  print receipts for the payments.

Learn how to make this System Step by step

Step1 : Create the database named with “milk “ on Sqlserver.establish the database connection

SqlConnection con = new SqlConnection("Data Source=.; Initial Catalog=millk; User ID=sa; password=admin123;");

The system shall be able to select the relevant milk type.

Add the Product details into the DataGridView

After selected milk type where the user has the option to add the qty by clicking the add button to see all products details which will be shown in the below table.

Paste this code inside the add button

 private void button1_Click(object sender, EventArgs e)
        {
            string name;
            int price = 0;
            int qty;
            int tot = 0;
            if(chk1.Checked)
            {
                name = "Strawberry Milk";
                qty = int.Parse(stwqty.Value.ToString());
                price = 100;
                tot = qty * price;
                this.dataGridView1.Rows.Add(name, price,qty,tot);
            }
            if (chk2.Checked)
            {
                name = "Mango Milk";
                qty = int.Parse(manqty.Value.ToString());
                price = 80;
                tot = qty * price;
                this.dataGridView1.Rows.Add(name, price, qty, tot);
            }

            if (chk3.Checked)
            {
                name = "Vanilla Milk";
                qty = int.Parse(vanqty.Value.ToString());
                price = 50;
                tot = qty * price;
                this.dataGridView1.Rows.Add(name, price, qty, tot);
            }
            
            if (chk4.Checked)
            {
                name = "Chocolate Milk";
                qty = int.Parse(choqty.Value.ToString());
                price = 150;
                tot = qty * price;
                this.dataGridView1.Rows.Add(name, price, qty, tot);

            }

            if (chk5.Checked)
            {
                name = "Coffee Milk";
                qty = int.Parse(cofqty.Value.ToString());
                price = 70;
                tot = qty * price;
                this.dataGridView1.Rows.Add(name, price, qty, tot);

            }

            int sum = 0;
            for(int row= 0; row< dataGridView1.Rows.Count; row++)
            {
                sum = sum + Convert.ToInt32(dataGridView1.Rows[row].Cells[3].Value);
            }

            txttot.Text = sum.ToString();

        }

Calculating the Total and balance

Remove items

if you want remove items from the datagridview. select the row of table which item need to be remove. then click delete button in the datagridview.

 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if(e.ColumnIndex == dataGridView1.Columns["delete"].Index && e.RowIndex >= 0)
            {
                dataGridView1.Rows.Remove(dataGridView1.Rows[e.RowIndex]);

                int sum = 0;
                for (int row = 0; row < dataGridView1.Rows.Count; row++)
                {
                    sum = sum + Convert.ToInt32(dataGridView1.Rows[row].Cells[3].Value);
                }

                txttot.Text = sum.ToString();


            }
        }

After that  create the method Salessave().we have to create two different tables to store data into the database. we also have to create the following tables from database..
sales tables consist of following colums – id,subtotal,pay,balance.
sales_products tables consist of following colums –id,sales_id,prodname,price,qty,total

 public void salessave()
        {
            string tot = txttot.Text;
            string pay = txtpay.Text;
            string bal = txtbal.Text;
            string sql1;
            string sql2;

            sql1 = "insert into sales(subtotal,pay,balance)values(@subtotal,@pay,@balance) select @@identity; ";
            con.Open();
            cmd1 = new SqlCommand(sql1,con);
            cmd1.Parameters.AddWithValue("@subtotal", tot);
            cmd1.Parameters.AddWithValue("@pay", pay);
            cmd1.Parameters.AddWithValue("@balance", bal);
            int lastinserid = int.Parse(cmd1.ExecuteScalar().ToString());

            string prodname;
            int price = 0;
            int qty = 0;
            int total = 0;

            for(int row=0; row<dataGridView1.Rows.Count; row++)
            {
                prodname = dataGridView1.Rows[row].Cells[0].Value.ToString();
                price = int.Parse(dataGridView1.Rows[row].Cells[1].Value.ToString());
                qty = int.Parse(dataGridView1.Rows[row].Cells[2].Value.ToString());
                total = int.Parse(dataGridView1.Rows[row].Cells[3].Value.ToString());
                sql2 = "insert into sales_product(sales_id,prodname,price,qty,total)values(@sales_id,@prodname,@price,@qty,@total)";
                cmd2 = new SqlCommand(sql2, con);
                cmd2.Parameters.AddWithValue("@sales_id", lastinserid);
                cmd2.Parameters.AddWithValue("@prodname", prodname);
                cmd2.Parameters.AddWithValue("@price", price);
                cmd2.Parameters.AddWithValue("@qty", qty);
                cmd2.Parameters.AddWithValue("@total", total);
                cmd2.ExecuteNonQuery();
            }

            print p = new print();
            p.SalesID = lastinserid;
            p.Show();
            con.Close();
        }

Call the Salessave() method inside the Print Invoice button. after calculating the total Print receipt will be released. This print receipt is design by crystal reports.

Paste this code inside the Print Invoice button

 private void button2_Click(object sender, EventArgs e)
        {

            int pay = int.Parse(txtpay.Text);
            int total = int.Parse(txttot.Text);
            int bal = pay - total;
            txtbal.Text = bal.ToString();
            salessave();

        }

Print Receipt

i have attached the video link below. which will do this tutorials step by step.

admin

Recent Posts

ChatGPT Free Online Download the ChatGPT App Easily

Have you ever wanted to talk to a friendly, smart robot that helps you with…

2 days ago

Free GPT Chat? DeepSeek AI Does It Better

DeepSeek AI is becoming a friendly and powerful new tool in the world of artificial…

2 weeks ago

Spring Boot MySQL Complete CRUD REST API [ Free Sourecode ]

Do you want to become an expert in Spring Boot CRUD operations? This comprehensive tutorial…

2 weeks ago

CREATE Responsive Navigation Bar with FlexBox CSS!

Modern websites must have a navigation bar that is clear and responsive. FlexBox CSS is…

4 weeks ago

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

2 months ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

3 months ago