Beispiel #1
0
        private void btnBill_Click(object sender, EventArgs e)
        {
            string orderid = "";

            SqlCommand cmd1 = con.CreateCommand();

            cmd1.CommandType = CommandType.Text;
            cmd1.CommandText = "insert into orderUser values('" + txtFirstName.Text + "','" + txtLastName.Text + "','" + cbbillType.Text + "','" + dtpBillDate.Value.ToString("dd/mm/yyyy") + "')";
            cmd1.ExecuteNonQuery();

            // To Make order to the corresponding ID
            SqlCommand cmd2 = con.CreateCommand();

            cmd2.CommandType = CommandType.Text;
            cmd2.CommandText = "select top 1 * from orderUser order by id desc";
            cmd2.ExecuteNonQuery();

            DataTable      dt2 = new DataTable();
            SqlDataAdapter da2 = new SqlDataAdapter(cmd2);

            da2.Fill(dt2);
            foreach (DataRow dr2 in dt2.Rows)
            {
                orderid = dr2["id"].ToString();
            }

            foreach (DataRow dr in dt.Rows)
            {
                int    qty   = 0;
                string pname = "";

                SqlCommand cmd3 = new SqlCommand("insert into items(order_id,product,price,qty,total) values('" + orderid.ToString() + "', '" + dr["Product"].ToString() + "' , '" + dr["Price"].ToString() + "' , '" + dr["Qty"].ToString() + "', '" + dr["Total"].ToString() + "')", con);
                cmd3.ExecuteNonQuery();

                qty   = Convert.ToInt32(dr["Qty"].ToString());
                pname = dr["Product"].ToString();

                SqlCommand cmd4 = new SqlCommand("update stock set product_qty = product_qty - " + qty + " where product_name = '" + pname + "' ", con);
                cmd4.ExecuteNonQuery();
            }

            txtFirstName.Text   = "";
            txtLastName.Text    = "";
            txtPrice.Text       = "";
            txtQty.Text         = "";
            txtTotal.Text       = "";
            cbShowProducts.Text = "";
            cbbillType.Text     = "";

            dt.Clear();
            dgvShowAll.DataSource = dt;
            MessageBox.Show("Records Inserted Successfully");

            frmGenerateBill gbl = new frmGenerateBill();

            gbl.get_value(Convert.ToInt32(orderid.ToString()));
            gbl.Show();
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                if (textBox2.Text != "")
                {
                    if ((textBox1.Text == "admin" || textBox1.Text == "Admin" || textBox1.Text == "ADMIN") && textBox2.Text == "admin786")
                    {
                        frmAdminPanel admin = new frmAdminPanel();
                        this.Hide();
                        admin.Show();
                    }
                    else
                    {
                        bool isval;
                        bool isvalpass;
                        localhost.Service1 ser = new localhost.Service1();
                        ser.isvaliduser(textBox1.Text, textBox2.Text, out isval, out isvalpass);
                        if (isval)
                        {
                            //frmEmployee emp = new frmEmployee();
                            frmGenerateBill gb = new frmGenerateBill();
                            gb.Show();

                            //emp.Show();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("Invalid User");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please Enter Password");
                }
            }
            else
            {
                MessageBox.Show("Please Enter User Name");
            }
        }