예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox1, "Please Enter Customer name");
            }
            else if (textBox2.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox2, "Please Enter Street");
            }
            else if (textBox3.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox3, "Please Enter City");
            }
            else if (textBox4.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox4, "Please Enter Province");
            }
            else if (textBox5.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox5, "Please Enter Postalcode");
            }
            else if (textBox6.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox6, "Please Enter Phone number");
            }

            else if (textBox9.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox9, "Please Enter Purchase Date");
            }
            else if (comboBox5.SelectedIndex == -1 && comboBox5.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox5, "Please Select Car Serial Number");
            }

            else if (comboBox1.SelectedIndex == -1)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox1, "Please Select Model");
            }
            else if (comboBox2.SelectedIndex == -1)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox2, "Please Select Trim");
            }
            else if (comboBox3.SelectedIndex == -1)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox3, "Please Select Color");
            }
            else if (comboBox4.SelectedIndex == -1)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox4, "Please Select Year");
            }

            else if (textBox8.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox8, "Please Enter Total Price");
            }
            else if (textBox10.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox10, "Please Enter Purchase Invoice");
            }

            else
            {
                errorProvider1.Clear();

                conn();

                string Cid = "";

                cmd1.CommandText = "insert into Customer(Name,Street,City,Prov,Pcode,Phone)values(@name,@street,@city,@prov,@pcode,@pno)";

                cmd1.Parameters.AddWithValue("@name", textBox1.Text);
                cmd1.Parameters.AddWithValue("@street", textBox2.Text);
                cmd1.Parameters.AddWithValue("@city", textBox3.Text);
                cmd1.Parameters.AddWithValue("@prov", textBox4.Text);
                cmd1.Parameters.AddWithValue("@pcode", textBox5.Text);
                cmd1.Parameters.AddWithValue("@pno", textBox6.Text);
                cmd1.ExecuteNonQuery();


                cmd2.CommandText = "select ID from Customer where Name=@cname";
                cmd2.Parameters.AddWithValue("@cname", textBox1.Text);

                SqlDataReader dr = cmd2.ExecuteReader();
                while (dr.Read())
                {
                    Cid = dr[0].ToString();
                }
                dr.Close();
                cmd2.ExecuteNonQuery();

                cmd3.CommandText = "Update Car SET Cid=@cid,Purchinv=@pinv,Purchdate=@pdate,Sold=@sold where Serial = @serial";
                cmd3.Parameters.AddWithValue("@cid", Cid);
                cmd3.Parameters.AddWithValue("@serial", comboBox5.SelectedItem.ToString());
                cmd3.Parameters.AddWithValue("@pinv", textBox10.Text);
                cmd3.Parameters.AddWithValue("@pdate", textBox9.Text);
                cmd3.Parameters.AddWithValue("@sold", "YES");

                cmd3.ExecuteNonQuery();

                scon.Close();

                AddDone ad = new AddDone();
                ad.Show();

                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();
                textBox5.Clear();
                textBox6.Clear();
                comboBox5.Text = "";
                textBox8.Clear();
                textBox9.Clear();
                textBox10.Clear();
                comboBox1.Text = "";
                comboBox2.Text = "";
                comboBox3.Text = "";
                comboBox4.Text = "";

                scon.Close();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox1, "Please Enter Serial Number");
            }
            else if (textBox2.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox2, "Please Enter Customer Name");
            }
            else if (textBox3.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox3, "Please Enter Salesman Name");
            }
            else if (comboBox1.SelectedIndex == -1)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox1, "Please Select Model");
            }
            else if (comboBox2.SelectedIndex == -1)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox2, "Please Select Trim");
            }
            else if (comboBox3.SelectedIndex == -1)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox3, "Please Select Color");
            }
            else if (comboBox4.SelectedIndex == -1)
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox4, "Please Select Year");
            }
            else if (textBox5.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox5, "Please Select Delivery Date");
            }
            else if (textBox6.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox6, "Please Enter Total Amount");
            }
            else
            {
                errorProvider1.Clear();
                conn();

                string insurance = "";
                if (radioButton1.Checked)
                {
                    insurance = "YES";
                }
                else
                {
                    insurance = "NO";
                }

                cmd2.CommandText = "select Carid,Cid from Car where Serial=@serial";
                cmd2.Parameters.AddWithValue("@serial", textBox1.Text);


                string        Cid   = "";
                string        Carid = "";
                SqlDataReader dr    = cmd2.ExecuteReader();
                while (dr.Read())
                {
                    Carid = dr[0].ToString();
                    Cid   = dr[1].ToString();
                }
                dr.Close();
                cmd2.ExecuteNonQuery();


                cmd.CommandText = "Insert into Saleinv(Carid,Cid,Cname,Salesman,Saledate,Price,Insurance)values(@carid,@cid,@cname,@sname,@sdate,@price,@insurance)";
                cmd.Parameters.AddWithValue("@carid", Carid);
                cmd.Parameters.AddWithValue("@cid", Cid);
                cmd.Parameters.AddWithValue("@cname", textBox2.Text);
                cmd.Parameters.AddWithValue("@sname", LoginPage.Username);
                cmd.Parameters.AddWithValue("@sdate", textBox5.Text);
                cmd.Parameters.AddWithValue("@price", textBox6.Text);
                cmd.Parameters.AddWithValue("@insurance", insurance);

                cmd.ExecuteNonQuery();

                AddDone ad = new AddDone();
                ad.Show();

                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox5.Clear();
                textBox6.Clear();
                comboBox1.Text = "";
                comboBox2.Text = "";
                comboBox3.Text = "";
                comboBox4.Text = "";
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox1, "Please Enter Serial Number");
            }
            else if (textBox2.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox2, "Please Select Service Date");
            }
            else if (textBox3.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox3, "Please Enter Customer Name");
            }
            else if (textBox4.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox4, "Please Enter Parts Cost");
            }
            else if (textBox5.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox5, "Please Enter Labor Cost");
            }
            else if (textBox6.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox6, "Please Enter Total Price");
            }
            else if (richTextBox2.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(richTextBox2, "Please Enter Service Description");
            }
            else
            {
                errorProvider1.Clear();
                conn();

                double taxPercent = 1.13;

                double partscost = double.Parse(textBox4.Text);
                double laborcost = double.Parse(textBox5.Text);

                double total = (partscost + laborcost) * taxPercent;

                double tax = (partscost + laborcost) * (taxPercent - 1);

                cmd2.CommandText = "select Carid,Cid from Car where Serial=@serial";
                cmd2.Parameters.AddWithValue("@serial", textBox1.Text);


                string        Cid   = "";
                string        Carid = "";
                SqlDataReader dr    = cmd2.ExecuteReader();
                while (dr.Read())
                {
                    Carid = dr[0].ToString();
                    Cid   = dr[1].ToString();
                }
                dr.Close();
                cmd2.ExecuteNonQuery();

                string s = "insert into Service(Cid,Carid,Serdate,Cname,Serial,Partscost,Laborcost,Tax,Totalcost,Description)values(@cid,@carid,@sd,@cn,@serno,@pc,@lc,@tax,@total,@desc)";


                cmd.CommandText = s;

                cmd.Parameters.AddWithValue("@carid", Carid);
                cmd.Parameters.AddWithValue("@cid", Cid);
                cmd.Parameters.AddWithValue("@serno", textBox1.Text);
                cmd.Parameters.AddWithValue("@sd", textBox2.Text);
                cmd.Parameters.AddWithValue("@cn", textBox3.Text);
                cmd.Parameters.AddWithValue("@pc", textBox4.Text);
                cmd.Parameters.AddWithValue("@lc", textBox5.Text);
                cmd.Parameters.AddWithValue("@tax", tax);
                cmd.Parameters.AddWithValue("@total", total);
                cmd.Parameters.AddWithValue("@desc", richTextBox2.Text);

                cmd.ExecuteNonQuery();

                scon.Close();

                richTextBox1.Text = richTextBox1.Text + " Serial No:" + textBox1.Text +
                                    "\n Service Date:" + textBox2.Text +
                                    "\n Customer Name:" + textBox3.Text +
                                    "\n Parts Cost:" + textBox4.Text +
                                    "\n Labor Cost:" + textBox5.Text +
                                    "\n Service Price:" + total +
                                    "\n Service Description:" + richTextBox2.Text;


                //MessageBox.Show("Service queued!!!!");
                AddDone ad = new AddDone();
                ad.Show();

                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();
                textBox5.Clear();
                textBox6.Clear();

                richTextBox2.Clear();
                richTextBox1.Clear();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox1, "Please Enter Serial Number");
            }
            else if (comboBox1.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox1, "Please Select Model");
            }
            else if (comboBox2.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox2, "Please Select Trim");
            }
            else if (comboBox3.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox3, "Please Select Color");
            }
            else if (comboBox4.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(comboBox4, "Please Select Year");
            }
            else if (textBox2.Text == "")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(textBox2, "Please Enter Total Price");
            }

            else
            {
                errorProvider1.Clear();

                conn();

                string s = "insert into Car(Serial,Model,Trim,Color,Year,Price,Sold)values(@sn,@model,@trim,@color,@year,@price,@sold)";


                cmd.CommandText = s;

                cmd.Parameters.AddWithValue("@sn", textBox1.Text);
                cmd.Parameters.AddWithValue("@model", comboBox1.SelectedItem.ToString());
                cmd.Parameters.AddWithValue("@trim", comboBox2.SelectedItem.ToString());
                cmd.Parameters.AddWithValue("@color", comboBox3.SelectedItem.ToString());
                cmd.Parameters.AddWithValue("@year", int.Parse(comboBox4.SelectedItem.ToString()));
                cmd.Parameters.AddWithValue("@price", int.Parse(textBox2.Text));
                cmd.Parameters.AddWithValue("@sold", "NO");

                cmd.ExecuteNonQuery();

                scon.Close();

                AddDone ad = new AddDone();
                ad.Show();

                textBox1.Clear();
                textBox2.Clear();
                comboBox1.Text = "";
                comboBox2.Text = "";
                comboBox3.Text = "";
                comboBox4.Text = "";
            }
        }