Ejemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedCells.Count > 0)
            {
                int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex];

                string a     = Convert.ToString(selectedRow.Cells["Client_ID"].Value);
                string b     = Convert.ToString(selectedRow.Cells["Product_ID"].Value);
                string c     = Convert.ToString(selectedRow.Cells["Order_date"].Value);
                string d     = Convert.ToString(selectedRow.Cells["Delivery_date"].Value);
                string ee    = Convert.ToString(selectedRow.Cells["Quantity"].Value);
                string f     = Convert.ToString(selectedRow.Cells["Selling_price"].Value);
                string g     = Convert.ToString(selectedRow.Cells["Color"].Value);
                string h     = Convert.ToString(selectedRow.Cells["Size"].Value);
                string tk    = Convert.ToString(selectedRow.Cells["Single_price"].Value);
                string k     = Convert.ToString(selectedRow.Cells["Pname"].Value);
                string l     = Convert.ToString(selectedRow.Cells["Cname"].Value);
                string main  = Convert.ToString(selectedRow.Cells["Order_ID"].Value);
                string pcost = Convert.ToString(selectedRow.Cells["Pcost"].Value);



                //MessageBox.Show(a);
                conn.Open();
                try
                {
                    int m = Int32.Parse(ee);
                    pcost = pcost.TrimEnd('$');
                    int n = Int32.Parse(pcost);
                    f = f.TrimEnd('$');
                    int o    = Int32.Parse(f);
                    int rslt = o - (m * n);
                    f = f + "$";
                    string i = rslt.ToString() + "$";


                    DialogResult dialogResult = MessageBox.Show("Are You Sure!! This order is delivered?", "Confirmation", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        OleDbCommand cmd1 = new OleDbCommand("insert into Sales_record(Client_ID,Product_ID,Order_ID,Order_date,Delivery_date,Quantity,Selling_Price,Color,[Size],Profit,Pname,Cname) values('" + a + "','" + b + "','" + main + "','" + c + "','" + d + "','" + ee + "','" + f + "','" + g + "','" + h + "','" + i + "','" + k + "','" + l + "')", conn);
                        cmd1.ExecuteNonQuery();
                        OleDbCommand cmd = new OleDbCommand("Delete * from Order_list  where Order_ID= " + main, conn);
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("Recorded in sells list");

                        Form10 f6 = new Form10();
                        f6.Show();
                        this.Close();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Occur: " + ex);
                }
                conn.Close();
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            int na = 0;

            foreach (Control child in panel2.Controls)
            {
                if (child is TextBox)
                {
                    TextBox tb = child as TextBox;
                    if (string.IsNullOrEmpty(tb.Text))
                    {
                        na++;
                    }
                }
            }
            if (na > 0)
            {
                MessageBox.Show("Fillup all the field. " + na + " field missing!!");
            }
            else
            {
                conn.Open();
                try
                {
                    string str = "";
                    for (int i = 0; i < checkedListBox1.Items.Count; i++)
                    {
                        if (checkedListBox1.GetItemChecked(i))
                        {
                            str += (string)checkedListBox1.Items[i] + ",";
                        }
                    }
                    str            = str.TrimEnd(',');
                    textBox6.Text += "$";


                    DialogResult dialogResult = MessageBox.Show("Are you sure all information are correct? ", "Confirmation", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        OleDbCommand cmd = new OleDbCommand("insert into Order_list(Client_ID,Product_ID,Order_date,Delivery_date,Quantity,Selling_Price,Color,[Size],Single_price,Pname,Cname,Pcost) values('" + label17.Text + "','" + label15.Text + "','" + dateTimePicker2.Value + "','" + dateTimePicker1.Value + "','" + textBox5.Text + "','" + label8.Text + "','" + textBox3.Text + "','" + str + "','" + textBox6.Text + "','" + label16.Text + "','" + label18.Text + "','" + label14.Text + "')", conn);
                        // cmd.Parameters.Add("@Date", OleDbType.Date).Value = dateTimePicker1.Value;
                        //conv_photo();
                        int n = cmd.ExecuteNonQuery();
                        if (n > 0)
                        {
                            MessageBox.Show("record inserted");
                        }
                        else
                        {
                            MessageBox.Show("insertion failed");
                        }

                        Form10 f7 = new Form10();
                        f7.Show();
                        this.Close();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                    }
                }
                catch (Exception ea)
                {
                    MessageBox.Show("Uncertain Error Occur :( !! " + ea);
                }
                conn.Close();
            }
        }