Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection Connection = new SqlConnection(Con.ConnectionString());

            if (Cat.SelectedIndex == -1)
            {
                toolStripStatusLabel1.Text = "Please Select a Catagory and Enter Sub Catagory for that";
                Cat.Focus();
            }
            else if ((SubCat.Text.ToString().Trim(' ')).ToString() == "")
            {
                toolStripStatusLabel1.Text = "Please Enter Sub Catagory Name";
                SubCat.Text = "";
                SubCat.Focus();
            }
            else if (unit.SelectedIndex == -1)
            {
                toolStripStatusLabel1.Text = "Please Select a Unit for the Sub Catagory";
                unit.Focus();
            }
            else if ((Sup1.Checked == false) && (Sup2.Checked == false) && (Sup3.Checked == false))
            {
                toolStripStatusLabel1.Text = "Please Select atleast one Supplier for this Sub Catagory";
                Sup1.Focus();
            }
            else
            {
                try
                {
                    if (button1.Text.ToString() == "Save")
                    {
                        SqlCommand INSERT = new SqlCommand("INSERT INTO SubCatagory(Catagory,SubCatagory,Descriptions,Supplier1,Supplier2,Supplier3,Units) VALUES(@Catagory,@SubCatagory,@Descriptions,@Supplier1,@Supplier2,@Supplier3,@Units)", Connection);
                        INSERT.Parameters.AddWithValue("@Catagory", Cat.SelectedItem.ToString());
                        INSERT.Parameters.AddWithValue("@SubCatagory", SubCat.Text.ToString());
                        INSERT.Parameters.AddWithValue("@Descriptions", Des.Text.ToString());
                        if (Sup1.Checked == true)
                        {
                            INSERT.Parameters.AddWithValue("@Supplier1", Sup1.Text.ToString());
                        }
                        else
                        {
                            INSERT.Parameters.AddWithValue("@Supplier1", " ");
                        }
                        if (Sup2.Checked == true)
                        {
                            INSERT.Parameters.AddWithValue("@Supplier2", Sup2.Text.ToString());
                        }
                        else
                        {
                            INSERT.Parameters.AddWithValue("@Supplier2", " ");
                        }
                        if (Sup3.Checked == true)
                        {
                            INSERT.Parameters.AddWithValue("@Supplier3", Sup3.Text.ToString());
                        }
                        else
                        {
                            INSERT.Parameters.AddWithValue("@Supplier3", " ");
                        }

                        INSERT.Parameters.AddWithValue("@Units", unit.SelectedItem.ToString());
                        Connection.Open();
                        int a = INSERT.ExecuteNonQuery();
                        Connection.Close();
                        if (a == 1)
                        {
                            toolStripStatusLabel1.Text = "Successfully Saved";
                            SubCat.Text        = "";
                            Des.Text           = "";
                            Sup1.Checked       = true;
                            Sup2.Checked       = true;
                            Sup3.Checked       = true;
                            unit.SelectedIndex = 0;
                            SubCat.Focus();
                        }
                        else
                        {
                            toolStripStatusLabel1.Text = "Error SubCatagory Not Saved";
                        }
                    }
                    else
                    {
                        SqlCommand UPDES = new SqlCommand("UPDATE SubCatagory SET Descriptions=@Description WHERE Catagory=@Catagory AND SubCatagory=@SubCatagory ", Connection);
                        UPDES.Parameters.AddWithValue("@Description", Des.Text.ToString());
                        UPDES.Parameters.AddWithValue("@Catagory", Cat.SelectedItem.ToString());
                        UPDES.Parameters.AddWithValue("@SubCatagory", SubCat.Text.ToString());

                        SqlCommand UPSUP1 = new SqlCommand("UPDATE SubCatagory SET Supplier1=@Supplier1 WHERE Catagory=@Catagory AND SubCatagory=@SubCatagory ", Connection);
                        UPSUP1.Parameters.AddWithValue("@Catagory", Cat.SelectedItem.ToString());
                        UPSUP1.Parameters.AddWithValue("@SubCatagory", SubCat.Text.ToString());
                        if (Sup1.Checked == true)
                        {
                            UPSUP1.Parameters.AddWithValue("@Supplier1", Sup1.Text.ToString());
                        }
                        else
                        {
                            UPSUP1.Parameters.AddWithValue("@Supplier1", " ");
                        }

                        SqlCommand UPSUP2 = new SqlCommand("UPDATE SubCatagory SET Supplier2=@Supplier2 WHERE Catagory=@Catagory AND SubCatagory=@SubCatagory ", Connection);
                        UPSUP2.Parameters.AddWithValue("@Catagory", Cat.SelectedItem.ToString());
                        UPSUP2.Parameters.AddWithValue("@SubCatagory", SubCat.Text.ToString());
                        if (Sup2.Checked == true)
                        {
                            UPSUP2.Parameters.AddWithValue("@Supplier2", Sup2.Text.ToString());
                        }
                        else
                        {
                            UPSUP2.Parameters.AddWithValue("@Supplier2", " ");
                        }

                        SqlCommand UPSUP3 = new SqlCommand("UPDATE SubCatagory SET Supplier3=@Supplier3 WHERE Catagory=@Catagory AND SubCatagory=@SubCatagory ", Connection);
                        UPSUP3.Parameters.AddWithValue("@Catagory", Cat.SelectedItem.ToString());
                        UPSUP3.Parameters.AddWithValue("@SubCatagory", SubCat.Text.ToString());
                        if (Sup3.Checked == true)
                        {
                            UPSUP3.Parameters.AddWithValue("@Supplier3", Sup3.Text.ToString());
                        }
                        else
                        {
                            UPSUP3.Parameters.AddWithValue("@Supplier3", " ");
                        }

                        SqlCommand UPUNIT = new SqlCommand("UPDATE SubCatagory SET Units=@Units WHERE Catagory=@Catagory AND SubCatagory=@SubCatagory", Connection);
                        UPUNIT.Parameters.AddWithValue("@Units", unit.Text.ToString());
                        UPUNIT.Parameters.AddWithValue("@Catagory", Cat.SelectedItem.ToString());
                        UPUNIT.Parameters.AddWithValue("@SubCatagory", SubCat.Text.ToString());

                        int a, b, c, d, ei;
                        Connection.Open();
                        a  = UPDES.ExecuteNonQuery();
                        b  = UPSUP1.ExecuteNonQuery();
                        c  = UPSUP2.ExecuteNonQuery();
                        d  = UPSUP3.ExecuteNonQuery();
                        ei = UPUNIT.ExecuteNonQuery();


                        if ((a == 1) && (b == 1) && (c == 1) && (d == 1) && (ei == 1))
                        {
                            toolStripStatusLabel1.Text = "Successfully Updated";
                            SubCat.Text        = "";
                            Des.Text           = "";
                            Sup1.Checked       = true;
                            Sup2.Checked       = true;
                            Sup3.Checked       = true;
                            unit.SelectedIndex = 0;
                            SubCat.Focus();
                        }
                    }
                }
                catch (SqlException s)
                {
                    MessageBox.Show(s.ToString());
                }
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection Connection = new OleDbConnection(Con.ConnectionString());

            if (CatName.Text.ToString().Trim(' ') == "")
            {
                toolStripStatusLabel1.Text = "Please Enter Catagory Name";
                CatName.Text = "";
                CatName.Focus();
            }
            else if ((Sup1.SelectedIndex == -1) && (Sup2.SelectedIndex == -1) && (Sup3.SelectedIndex == -1))
            {
                toolStripStatusLabel1.Text = "Please Select atleast One Supplier for this Catagory";
                Sup1.Focus();
            }
            else
            {
                try
                {
                    if (button1.Text.ToString() == "Save")
                    {
                        OleDbCommand INSERT = new OleDbCommand("INSERT INTO Catagory(CatName,Descriptions,Supplier1,Supplier2,Supplier3) VALUES(@CatName,@Descriptions,@Supplier1,@Supplier2,@Supplier3)", Connection);
                        INSERT.Parameters.AddWithValue("@CatName", CatName.Text.ToString());
                        INSERT.Parameters.AddWithValue("@Descriptions", Des.Text.ToString());

                        if (Sup1.SelectedIndex != -1)
                        {
                            INSERT.Parameters.AddWithValue("@Supplier1", Sup1.SelectedItem.ToString());
                        }
                        else
                        {
                            INSERT.Parameters.AddWithValue("@Supplier1", "");
                        }

                        if (Sup2.SelectedIndex != -1)
                        {
                            INSERT.Parameters.AddWithValue("@Supplier2", Sup2.SelectedItem.ToString());
                        }
                        else
                        {
                            INSERT.Parameters.AddWithValue("@Supplier2", "");
                        }

                        if (Sup3.SelectedIndex != -1)
                        {
                            INSERT.Parameters.AddWithValue("@Supplier3", Sup3.SelectedItem.ToString());
                        }
                        else
                        {
                            INSERT.Parameters.AddWithValue("@Supplier3", "");
                        }

                        Connection.Open();
                        int a = INSERT.ExecuteNonQuery();
                        Connection.Close();

                        if (a == 1)
                        {
                            toolStripStatusLabel1.Text = "Successfully Saved";
                            CatName.Text = "";
                            Des.Text     = "";
                            Sup1.Text    = "";
                            Sup2.Text    = "";
                            Sup3.Text    = "";
                            CatName.Focus();
                        }
                        else
                        {
                            toolStripStatusLabel1.Text = "Error Catagory not Saved";
                        }
                    }
                    else
                    {
                        OleDbCommand UPDES = new OleDbCommand("UPDATE Catagory SET Descriptions=@Descriptions WHERE CatName=@CatName", Connection);
                        UPDES.Parameters.AddWithValue("@CatName", CatName.Text.ToString());
                        UPDES.Parameters.AddWithValue("@Descriptions", Des.Text.ToString());

                        OleDbCommand UPSUP1 = new OleDbCommand("UPDATE Catagory SET Supplier1=@Supplier1 WHERE CatName=@CatName", Connection);
                        if (Sup1.SelectedIndex != -1)
                        {
                            UPSUP1.Parameters.AddWithValue("@Supplier1", Sup1.SelectedItem.ToString());
                        }
                        else
                        {
                            UPSUP1.Parameters.AddWithValue("@Supplier1", "");
                        }
                        UPSUP1.Parameters.AddWithValue("@CatName", CatName.Text.ToString());

                        OleDbCommand UPSUP2 = new OleDbCommand("UPDATE Catagory SET Supplier2=@Supplier2 WHERE CatName=@CatName", Connection);
                        if (Sup2.SelectedIndex != -1)
                        {
                            UPSUP2.Parameters.AddWithValue("@Supplier2", Sup2.SelectedItem.ToString());
                        }
                        else
                        {
                            UPSUP2.Parameters.AddWithValue("@Supplier2", "");
                        }
                        UPSUP2.Parameters.AddWithValue("@CatName", CatName.Text.ToString());

                        OleDbCommand UPSUP3 = new OleDbCommand("UPDATE Catagory SET Supplier3=@Supplier3 WHERE CatName=@CatName", Connection);
                        if (Sup3.SelectedIndex != -1)
                        {
                            UPSUP3.Parameters.AddWithValue("@Supplier3", Sup3.SelectedItem.ToString());
                        }
                        else
                        {
                            UPSUP3.Parameters.AddWithValue("@Supplier3", "");
                        }
                        UPSUP3.Parameters.AddWithValue("@CatName", CatName.Text.ToString());

                        int a, b, c, d;

                        Connection.Open();
                        a = UPDES.ExecuteNonQuery();
                        b = UPSUP1.ExecuteNonQuery();
                        c = UPSUP2.ExecuteNonQuery();
                        d = UPSUP3.ExecuteNonQuery();
                        Connection.Close();

                        if ((a == 1) && (b == 1) && (c == 1) && (d == 1))
                        {
                            toolStripStatusLabel1.Text = "Successfully Updated";
                            CatName.Text = "";
                            Des.Text     = "";
                            Sup1.Text    = "";
                            Sup2.Text    = "";
                            Sup3.Text    = "";
                            CatName.Focus();
                        }
                        else
                        {
                            toolStripStatusLabel1.Text = "Error Catagory Not Updated";
                        }
                    }
                }
                catch
                {
                }
            }
        }