Пример #1
0
 private void Update_Click(object sender, RoutedEventArgs e)
 {
     if (!String.IsNullOrEmpty(CatagoryIdTxt.Text) && !String.IsNullOrEmpty(CatagoryNameTxt.Text))
     {
         SqlConnection sqlConFill = new SqlConnection(conn);
         SqlCommand cmdFill = new SqlCommand();
         cmdFill.CommandText = "UPDATE catagory_list SET Cat_Id=@CatagoryId,Cat_Name=@CatagoryName WHERE Cat_Id=@CatagoryId";
         cmdFill.Parameters.AddWithValue("@CatagoryId", CatagoryIdTxt.Text);
         cmdFill.Parameters.AddWithValue("@CatagoryName", CatagoryNameTxt.Text);
         cmdFill.Connection = sqlConFill;
         sqlConFill.Open();
         cmdFill.ExecuteNonQuery();
         sqlConFill.Close();
         Catagory win2 = new Catagory();
         win2.Show();
         this.Close();
     }
     else
     {
         MessageBox.Show("Catagory Id or Name Cann't be Empty");
     }
 }
Пример #2
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(CatagoryNameTxt.Text))
            {
                int sr = 0;
                SqlConnection sqlConFill = new SqlConnection(conn);
                SqlCommand cmdFill = new SqlCommand();
                cmdFill.CommandText = "SELECT MAX(Cat_Id) FROM catagory_list";
                cmdFill.Connection = sqlConFill;
                sqlConFill.Open();
                SqlDataReader rd1 = cmdFill.ExecuteReader();
                if (rd1.HasRows)
                {
                    rd1.Read();
                    var outputParam = rd1[0];
                    if (!(outputParam is DBNull))
                    {
                        sr = Convert.ToInt32(rd1[0]);
                    }
                    else
                    {
                        sr = 0;
                    }
                    rd1.Close();
                }
                sqlConFill.Close();
                sr = sr + 1;

                cmdFill.CommandText = "SELECT Cat_Id FROM catagory_list WHERE Cat_Name=@Name";
                cmdFill.Parameters.AddWithValue("@Name", CatagoryNameTxt.Text);
                cmdFill.Connection = sqlConFill;
                sqlConFill.Open();
                SqlDataReader rd = cmdFill.ExecuteReader();
                String cat = "";
                if (rd.HasRows)
                {
                    rd.Read();
                    cat = cat + rd[0].ToString();
                    rd.Close();
                    sqlConFill.Close();
                    MessageBox.Show("Food Catagory Already Exist at Id " + cat);
                }
                else
                {
                    sqlConFill.Close();
                    sqlConFill = new SqlConnection(conn);
                    cmdFill = new SqlCommand();
                    cmdFill.CommandText = "INSERT INTO catagory_list(Cat_Id,Cat_Name) VALUES (@CatagoryId,@CatagoryName)";
                    cmdFill.Parameters.AddWithValue("@CatagoryId", sr.ToString());
                    cmdFill.Parameters.AddWithValue("@CatagoryName", CatagoryNameTxt.Text);
                    cmdFill.Connection = sqlConFill;
                    sqlConFill.Open();
                    cmdFill.ExecuteNonQuery();
                    sqlConFill.Close();
                    Catagory win2 = new Catagory();
                    win2.Show();
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Catagory Name Cann't be Empty");
            }
        }
Пример #3
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(CatagoryIdTxt.Text) && !String.IsNullOrEmpty(CatagoryNameTxt.Text))
            {
                SqlConnection sqlConFill = new SqlConnection(conn);
                SqlCommand cmdFill = new SqlCommand();
                cmdFill.CommandText = "DELETE FROM catagory_list WHERE Cat_Id=@CatagoryId";
                cmdFill.Parameters.AddWithValue("@CatagoryId", CatagoryIdTxt.Text);
                cmdFill.Connection = sqlConFill;
                sqlConFill.Open();
                cmdFill.ExecuteNonQuery();
                sqlConFill.Close();

                SqlConnection sqlConFilld = new SqlConnection(conn);
                SqlCommand cmdFilld = new SqlCommand();
                cmdFilld.CommandText = "DELETE FROM Foods WHERE Catagory_Id=@dCatagoryIde";
                cmdFilld.Parameters.AddWithValue("@dCatagoryIde", CatagoryIdTxt.Text);
                cmdFilld.Connection = sqlConFilld;
                sqlConFilld.Open();
                cmdFilld.ExecuteNonQuery();
                sqlConFilld.Close();

                cmdFill.CommandText = "UPDATE catagory_list SET Cat_Id=Cat_Id-1 WHERE Cat_Id>@CatagoryId2";
                cmdFill.Parameters.AddWithValue("@CatagoryId2", CatagoryIdTxt.Text);
                cmdFill.Connection = sqlConFill;
                sqlConFill.Open();
                cmdFill.ExecuteNonQuery();
                sqlConFill.Close();

                SqlConnection sqlConFilluf = new SqlConnection(conn);
                SqlCommand cmdFilluf = new SqlCommand();
                cmdFilluf.CommandText = "UPDATE Foods SET Catagory_Id=Catagory_Id-1 WHERE Catagory_Id>@CatagoryIduf";
                cmdFilluf.Parameters.AddWithValue("@CatagoryIduf", CatagoryIdTxt.Text);
                cmdFilluf.Connection = sqlConFilluf;
                sqlConFilluf.Open();
                cmdFilluf.ExecuteNonQuery();
                sqlConFilluf.Close();
                Catagory win2 = new Catagory();
                win2.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("Catagory Id or Name Cann't be Empty");
            }
        }
Пример #4
0
 private void Catagory_Click(object sender, RoutedEventArgs e)
 {
     Catagory win2 = new Catagory();
     win2.Show();
     this.Close();
 }