private void Selltoday_Click(object sender, RoutedEventArgs e)
        {
            Selltoday go = new Selltoday();

            go.Show();
        }
        private void Insert2DB()
        {
            try
            {
                using (con)
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        cmd.Connection = con;

                        for (int i = 0; i < dataGrid.Items.Count; i++)
                        {
                            count += 1;

                            object item = dataGrid.Items[i];

                            string showidProduct     = (dataGrid.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text;
                            string shownameProduct   = (dataGrid.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text;
                            string showtotalProduct  = (dataGrid.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text;
                            string showdeleteProduct = (dataGrid.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text;
                            string showallTotal      = (dataGrid.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text;
                            string showPrice         = (dataGrid.SelectedCells[5].Column.GetCellContent(item) as TextBlock).Text;
                            string showType          = (dataGrid.SelectedCells[6].Column.GetCellContent(item) as TextBlock).Text;
                            string showPriceall      = (dataGrid.SelectedCells[7].Column.GetCellContent(item) as TextBlock).Text;
                            string showNote          = (dataGrid.SelectedCells[8].Column.GetCellContent(item) as TextBlock).Text;

                            con.Open();
                            string          sqlproID  = "SELECT proID FROM product WHERE proCode='" + showidProduct + "'";
                            MySqlCommand    cmdproID  = new MySqlCommand(sqlproID, con);
                            MySqlDataReader readproID = cmdproID.ExecuteReader();

                            while (readproID.Read())
                            {
                                getproID = readproID["proID"].ToString();
                            }
                            con.Close();

                            con.Open();
                            string          getValue   = "SELECT stockTotal FROM stock WHERE proID='" + getproID + "'";
                            MySqlCommand    getCommand = new MySqlCommand(getValue, con);
                            MySqlDataReader getReader  = getCommand.ExecuteReader();

                            getTotal = Double.Parse(showallTotal);
                            while (getReader.Read())
                            {
                                getStockTotal = Convert.ToDouble(getReader["stockTotal"]);
                                Totalall      = getStockTotal - getTotal;
                            }
                            con.Close();

                            con.Open();
                            MySqlCommand    cmdgettype = new MySqlCommand("SELECT typepID FROM typeproduct WHERE typepName='" + showType + "'", con);
                            MySqlDataReader readtype   = cmdgettype.ExecuteReader();
                            while (readtype.Read())
                            {
                                getTypeid = readtype.GetString(readtype.GetOrdinal("typepID"));
                            }
                            con.Close();

                            if (count >= 1)
                            {
                                con.Open();
                                cmd.CommandText = @"INSERT INTO selltoday(docID,sellDate,cusID,cusName,cusLastname,cusPlate,sellCode,sellName,sellTotal,sellDtotal,sellTotalall,sellPrice,typepID,sellAllprice,sellInfo) 
                                                        VALUES (@Bill,@DATE,@cusID,@nameCus,@lastnameCus,@plateCus,@buyCode,@buyName,@buyTotal,@buyDtotal,@buyTotalall,@buyPrice,@buyType,@buyAllprice,@buyInfo);     
                                                        UPDATE stock SET stockTotal='" + Totalall + "' WHERE proID='" + getproID + "'";
                                cmd.Parameters.AddWithValue("@Bill", ShowBill.Text);
                                cmd.Parameters.AddWithValue("@DATE", Convert.ToDateTime(txtDate.Text).ToString("yyyy/MM/dd"));
                                cmd.Parameters.AddWithValue("@nameCus", txtName.Text);
                                cmd.Parameters.AddWithValue("@lastnameCus", txtLname.Text);
                                cmd.Parameters.AddWithValue("@plateCus", txtPlate.Text);
                                cmd.Parameters.AddWithValue("@buyCode", showidProduct);
                                cmd.Parameters.AddWithValue("@buyName", shownameProduct);
                                cmd.Parameters.AddWithValue("@buyTotal", showtotalProduct);
                                cmd.Parameters.AddWithValue("@buyDtotal", showdeleteProduct);
                                cmd.Parameters.AddWithValue("@buyTotalall", showallTotal);
                                cmd.Parameters.AddWithValue("@buyPrice", showPrice);
                                cmd.Parameters.AddWithValue("@buyType", getTypeid);
                                cmd.Parameters.AddWithValue("@buyAllprice", showPriceall);
                                cmd.Parameters.AddWithValue("@buyInfo", showNote);
                                if (calcusID == 1)
                                {
                                    cmd.Parameters.AddWithValue("@cusID", txtID.Text);
                                }
                                else if (calcusID == 2)
                                {
                                    cmd.Parameters.AddWithValue("@cusID", varcusID);
                                }
                                cmd.ExecuteNonQuery();
                                cmd.Parameters.Clear();
                                con.Close();
                            }
                            else
                            {
                                con.Open();
                                cmd.CommandText = @"INSERT INTO selltoday(docID,sellDate,cusID,cusName,cusLastname,cusPlate,sellCode,sellName,sellTotal,sellDtotal,sellTotalall,sellPrice,typepID,sellAllprice,sellInfo) 
                                                        VALUES (@Bill,@DATE,@cusID,@nameCus,@lastnameCus,@plateCus,@buyCode,@buyName,@buyTotal,@buyDtotal,@buyTotalall,@buyPrice,@buyType,@buyAllprice,@buyInfo);
                                                        INSERT INTO receiptsell(receiptDate,receiptCode,cusID,cusName,cusLastname,cusPlate,receiptInfo,receiptPriceall) VALUES(@DATE,@Bill,@cusID,@nameCus,@lastnameCus,@plateCus,@buyInfo,@buyAllprice);
                                                        UPDATE stock SET stockTotal='" + Totalall + "' WHERE proID='" + getproID + "'";
                                cmd.Parameters.AddWithValue("@Bill", ShowBill.Text);
                                cmd.Parameters.AddWithValue("@DATE", Convert.ToDateTime(txtDate.Text).ToString("yyyy/MM/dd"));
                                cmd.Parameters.AddWithValue("@nameCus", txtName.Text);
                                cmd.Parameters.AddWithValue("@lastnameCus", txtLname.Text);
                                cmd.Parameters.AddWithValue("@plateCus", txtPlate.Text);
                                cmd.Parameters.AddWithValue("@buyCode", showidProduct);
                                cmd.Parameters.AddWithValue("@buyName", shownameProduct);
                                cmd.Parameters.AddWithValue("@buyTotal", showtotalProduct);
                                cmd.Parameters.AddWithValue("@buyDtotal", showdeleteProduct);
                                cmd.Parameters.AddWithValue("@buyTotalall", showallTotal);
                                cmd.Parameters.AddWithValue("@buyPrice", showPrice);
                                cmd.Parameters.AddWithValue("@buyType", getTypeid);
                                cmd.Parameters.AddWithValue("@buyAllprice", showPriceall);
                                cmd.Parameters.AddWithValue("@buyInfo", showNote);
                                if (calcusID == 1)
                                {
                                    cmd.Parameters.AddWithValue("@cusID", txtID.Text);
                                }
                                else if (calcusID == 2)
                                {
                                    cmd.Parameters.AddWithValue("@cusID", varcusID);
                                }
                                cmd.ExecuteNonQuery();
                                cmd.Parameters.Clear();
                                con.Close();
                            }
                        } // ปิด LOOP
                    }     // ปิด Using
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            MessageBox.Show("บันทึกเรียบร้อยแล้ว", "สำเร็จ");
            Selltoday go = new Selltoday();

            this.Close();
            go.Show();
        }