private void Button3_Click(object sender, EventArgs e)
        {
            Supply f = new Supply();

            f.ShowDialog();
        }
        private void ПоставкаToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Supply f = new Supply();

            f.ShowDialog();
        }
Exemplo n.º 3
0
        public void ToDistribute()
        {
            Supply  f          = (Supply)this.Owner;
            int     department = id_department[comboBox1.SelectedIndex];
            int     autopart   = f.id_autopart;
            decimal price      = Convert.ToDecimal(f.price_holiday.ToString().Replace(".", ","));
            int     amount     = f.amount;

            using (SqlConnection connect = new SqlConnection(con))
            {
                SqlDataAdapter sda = new SqlDataAdapter("dbo.CheckAutoparts " + department + "," + autopart, connect);
                DataTable      dt  = new DataTable();
                sda.Fill(dt);
                if (dt.Rows[0][0].ToString() != "1")
                {
                    connect.Open();
                    SqlCommand com = new SqlCommand("EXECUTE dbo.InsertAvailability_auto_parts " + insertIdAvailability +
                                                    "," + department + "," + autopart + "," + Convert.ToString(price).Replace(",", ".") + "," + amount, connect);
                    com.ExecuteNonQuery();
                }
                else
                {
                    connect.Open();
                    SqlCommand com = new SqlCommand("SELECT * FROM Availability_auto_parts WHERE ID_department=" + department +
                                                    " AND ID_autoparts=" + autopart + "", connect);
                    using (SqlDataReader r = com.ExecuteReader())
                    {
                        while (r.Read())
                        {
                            ID_availability = r[0].ToString();
                            ID_department   = r[1].ToString();
                            ID_autoparts    = r[2].ToString();
                            Price_holiday   = r[3].ToString();
                            Amount          = r[4].ToString();
                        }
                    }

                    decimal p = Convert.ToDecimal(Price_holiday.ToString().Replace(".", ","));
                    int     a = Convert.ToInt32(Amount);
                    decimal max;

                    if (price > p)
                    {
                        max = price;
                    }
                    else
                    {
                        max = p;
                    }
                    string MaxStr    = Convert.ToString(max).Replace(",", ".");
                    int    newAmount = a + Convert.ToInt32(amount);

                    connect.Close();
                    connect.Open();
                    SqlCommand EditAvailability = new SqlCommand("EXECUTE dbo.EditAvailability_auto_parts " + Convert.ToInt32(ID_availability) +
                                                                 "," + Convert.ToInt32(ID_department) + "," + Convert.ToInt32(ID_autoparts) + "," + MaxStr + "," + newAmount, connect);
                    EditAvailability.ExecuteNonQuery();
                }
            }

            using (SqlConnection connect = new SqlConnection(con))
            {
                connect.Open();
                SqlCommand com = new SqlCommand("EXECUTE dbo.StatusChange " + f.id_supply +
                                                ",'Распределена'", connect);
                com.ExecuteNonQuery();
            }
        }