private void button1_Click(object sender, EventArgs e)
        {
            Director f = (Director)this.parent;

            if (row == null)
            {
                try
                {
                    string connectionString = ConfigurationManager.ConnectionStrings["DairyDepartureConnectionString"].ConnectionString;

                    using (OleDbConnection conn = new OleDbConnection(connectionString))
                    {
                        conn.Open();
                        int    ID;
                        string sql = @"Insert into Employee ([Full_name], [Username], [Password])
                                    values (@Full_name, @Username, @Password)
                    ";

                        string sql2 = @"Select @@Identity";

                        string sql3 = @"Insert into Employee_Position([ID_employee], [ID_position], [Date_from]) 
                                    values(@ID_e, @ID_position, @Date_p)";
                        using (OleDbCommand comm = new OleDbCommand(sql, conn))
                        {
                            comm.Parameters.AddWithValue("@Full_name", maskedTextBox1.Text);
                            comm.Parameters.AddWithValue("@Username", maskedTextBox2.Text);
                            comm.Parameters.AddWithValue("@Password", maskedTextBox3.Text);
                            comm.ExecuteNonQuery();

                            comm.Parameters.RemoveAt("@Full_name");
                            comm.Parameters.RemoveAt("@Username");
                            comm.Parameters.RemoveAt("@Password");


                            comm.CommandText = sql2;
                            ID = (int)comm.ExecuteScalar();

                            comm.CommandText = sql3;
                            comm.Parameters.AddWithValue("@ID_e", ID);
                            comm.Parameters.AddWithValue("@ID_position", ((DairyDeparture1DataSet.PositionInfoRow)((DataRowView)((ComboBox)comboBox1).SelectedItem).Row).ID_position);
                            comm.Parameters.AddWithValue("@Date_p", DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year);
                            comm.ExecuteNonQuery();
                        }
                    }
                    MessageBox.Show("Employee successfully added");
                    //((DataGridView)parent.Controls["dataGridView1"]).Rows.Clear();
                    //((DataGridView)parent.Controls["dataGridView1"]).Refresh();
                    f.employeeToolStripMenuItem_Click(f.GetToolStripMenuItem("employeeToolStripMenuItem"), e);
                    this.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Invalid input");
                }
            }
            else
            {
                try
                {
                    string connectionString = ConfigurationManager.ConnectionStrings["DairyDepartureConnectionString"].ConnectionString;

                    using (OleDbConnection conn = new OleDbConnection(connectionString))
                    {
                        conn.Open();
                        int    empID = Int32.Parse(row.Cells["EmpID"].Value.ToString());
                        int    posID = Int32.Parse(row.Cells["PosID"].Value.ToString());
                        string sql   = @"Update Employee 
                                        set [Full_name] = @Full_name, [Username] = @Username, [Password] = @Password
                                        where ID_employee = @id_e;";

                        string sql3 = @"Update Employee_Position
                                        set [Date_for] = @DateNow
                                        where ID_employee = @id_e and Date_for is null;";

                        string sql4 = @"Insert into Employee_Position([ID_employee], [ID_position], [Date_from]) 
                                         values(@ID_e, @ID_position, @Date_p)";

                        using (OleDbCommand comm = new OleDbCommand(sql, conn))
                        {
                            comm.Parameters.AddWithValue("@Full_name", maskedTextBox1.Text);
                            comm.Parameters.AddWithValue("@Username", maskedTextBox2.Text);
                            comm.Parameters.AddWithValue("@Password", maskedTextBox3.Text);
                            comm.Parameters.AddWithValue("@id_e", empID);
                            comm.ExecuteNonQuery();

                            comm.Parameters.RemoveAt("@id_e");
                            comm.Parameters.RemoveAt("@Full_name");
                            comm.Parameters.RemoveAt("@Username");
                            comm.Parameters.RemoveAt("@Password");

                            if (((DairyDeparture1DataSet.PositionInfoRow)((DataRowView)((ComboBox)comboBox1).SelectedItem).Row).ID_position != posID)
                            {
                                comm.CommandText = sql3;
                                comm.Parameters.AddWithValue("@DateNow", DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year);
                                comm.Parameters.AddWithValue("@id_e", empID);
                                comm.ExecuteNonQuery();

                                comm.Parameters.RemoveAt("@id_e");
                                comm.Parameters.RemoveAt("@DateNow");

                                comm.CommandText = sql4;
                                comm.Parameters.AddWithValue("@ID_e", empID);
                                comm.Parameters.AddWithValue("@ID_position", ((DairyDeparture1DataSet.PositionInfoRow)((DataRowView)((ComboBox)comboBox1).SelectedItem).Row).ID_position);
                                comm.Parameters.AddWithValue("@Date_p", DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year);
                                comm.ExecuteNonQuery();
                            }
                        }
                    }
                    MessageBox.Show("Employee successfully updated");
                    f.employeeToolStripMenuItem_Click(f.GetToolStripMenuItem("employeeToolStripMenuItem"), e);
                    this.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Invalid input");
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Director f = (Director)this.parent;

            if (row == null)
            {
                try
                {
                    int    count            = 0;
                    string connectionString = ConfigurationManager.ConnectionStrings["DairyDepartureConnectionString"].ConnectionString;
                    using (OleDbConnection conn = new OleDbConnection(connectionString))
                    {
                        conn.Open();
                        string sql = @"select Count(ID_plan) from Selles_plan where Date_from = @Date_from and Date_to = @Date_to";
                        using (OleDbCommand comm = new OleDbCommand(sql, conn))
                        {
                            comm.Parameters.AddWithValue("@Date_from", dateTimePicker1.Value.Day + "." + dateTimePicker1.Value.Month + "." + dateTimePicker1.Value.Year);
                            comm.Parameters.AddWithValue("@Date_to", dateTimePicker2.Value.Day + "." + dateTimePicker2.Value.Month + "." + dateTimePicker2.Value.Year);
                            using (OleDbDataReader reader = comm.ExecuteReader())
                            {
                                if (reader.Read())
                                {
                                    count = reader.GetInt32(0);
                                }
                            }
                        }
                    }

                    if (count == 0)
                    {
                        using (OleDbConnection conn = new OleDbConnection(connectionString))
                        {
                            conn.Open();
                            int    ID;
                            string sql = @"Insert into Selles_plan ([Date_from], [Date_to])
                                            values (@Date_from, @Date_to)
                            ";

                            string sql2 = @"Select @@Identity";

                            string sql3 = @"Insert into SellesPlan_product([ID_plan], [ID_product], [Amount]) 
                                            values(@ID_plan, @ID_product, @Amount)";
                            using (OleDbCommand comm = new OleDbCommand(sql, conn))
                            {
                                comm.Parameters.AddWithValue("@Date_from", dateTimePicker1.Value.Day + "." + dateTimePicker1.Value.Month + "." + dateTimePicker1.Value.Year);
                                comm.Parameters.AddWithValue("@Date_to", dateTimePicker2.Value.Day + "." + dateTimePicker2.Value.Month + "." + dateTimePicker2.Value.Year);
                                comm.ExecuteNonQuery();

                                comm.Parameters.RemoveAt("@Date_from");
                                comm.Parameters.RemoveAt("@Date_to");


                                comm.CommandText = sql2;
                                ID = (int)comm.ExecuteScalar();

                                comm.CommandText = sql3;
                                comm.Parameters.AddWithValue("@ID_plan", ID);
                                comm.Parameters.AddWithValue("@ID_product", ((DairyDeparture1DataSet.Product_ЗапросRow)((DataRowView)((ComboBox)comboBox2).SelectedItem).Row).ID_product);
                                comm.Parameters.AddWithValue("@Amount", maskedTextBox2.Text);
                                comm.ExecuteNonQuery();
                            }
                        }
                    }
                    else
                    {
                        using (OleDbConnection conn = new OleDbConnection(connectionString))
                        {
                            conn.Open();
                            int    ID  = -1;
                            string sql = @"select ID_plan from Selles_plan where Date_from = @Date_from and Date_to = @Date_to";

                            string sql2 = @"Insert into SellesPlan_product([ID_plan], [ID_product], [Amount]) 
                                            values(@ID_plan, @ID_product, @Amount)";
                            using (OleDbCommand comm = new OleDbCommand(sql, conn))
                            {
                                comm.Parameters.AddWithValue("@Date_from", dateTimePicker1.Value.Day + "." + dateTimePicker1.Value.Month + "." + dateTimePicker1.Value.Year);
                                comm.Parameters.AddWithValue("@Date_to", dateTimePicker2.Value.Day + "." + dateTimePicker2.Value.Month + "." + dateTimePicker2.Value.Year);
                                comm.ExecuteNonQuery();

                                using (OleDbDataReader reader = comm.ExecuteReader())
                                {
                                    if (reader.Read())
                                    {
                                        ID = reader.GetInt32(0);
                                    }
                                }

                                comm.Parameters.RemoveAt("@Date_from");
                                comm.Parameters.RemoveAt("@Date_to");

                                comm.CommandText = sql2;
                                comm.Parameters.AddWithValue("@ID_plan", ID);
                                comm.Parameters.AddWithValue("@ID_product", ((DairyDeparture1DataSet.Product_ЗапросRow)((DataRowView)((ComboBox)comboBox2).SelectedItem).Row).ID_product);
                                comm.Parameters.AddWithValue("@Amount", maskedTextBox2.Text);
                                comm.ExecuteNonQuery();
                            }
                        }
                    }
                    MessageBox.Show("Plan successfully added");
                    f.sellingPlansToolStripMenuItem_Click(f.GetToolStripMenuItem("sellingPlansToolStripMenuItem"), e);
                    this.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Invalid input");
                }
            }
            else
            {
                try
                {
                    DateTime dayFrom   = DateTime.Parse(row.Cells["DateFr"].Value.ToString());
                    DateTime dayTo     = DateTime.Parse(row.Cells["DateTo"].Value.ToString());
                    int      planID    = Int32.Parse(row.Cells["ID_plan"].Value.ToString());
                    int      productID = Int32.Parse(row.Cells["ID_product"].Value.ToString());

                    string connectionString = ConfigurationManager.ConnectionStrings["DairyDepartureConnectionString"].ConnectionString;

                    using (OleDbConnection conn = new OleDbConnection(connectionString))
                    {
                        conn.Open();
                        string sql = @"Update Selles_plan
                                        set [Date_from] = @dayFrom, [Date_to] = @dayTo
                                        where ID_plan = @planID";

                        string sql2 = @"Update SellesPlan_product
                                        set [ID_product] = @ID_product, [Amount] = @Amount
                                        where ID_plan = @planID and ID_product = @productID";
                        using (OleDbCommand comm = new OleDbCommand(sql, conn))
                        {
                            comm.Parameters.AddWithValue("@dayFrom", dateTimePicker1.Value.Day + "." + dateTimePicker1.Value.Month + "." + dateTimePicker1.Value.Year);
                            comm.Parameters.AddWithValue("@dayTo", dateTimePicker2.Value.Day + "." + dateTimePicker2.Value.Month + "." + dateTimePicker2.Value.Year);
                            comm.Parameters.AddWithValue("@planID", planID);
                            comm.ExecuteNonQuery();

                            comm.Parameters.RemoveAt("@dayFrom");
                            comm.Parameters.RemoveAt("@dayTo");
                            comm.Parameters.RemoveAt("@planID");

                            comm.CommandText = sql2;
                            comm.Parameters.AddWithValue("@ID_product", ((DairyDeparture1DataSet.Product_ЗапросRow)((DataRowView)((ComboBox)comboBox2).SelectedItem).Row).ID_product);
                            comm.Parameters.AddWithValue("@Amount", Int32.Parse(maskedTextBox2.Text));
                            comm.Parameters.AddWithValue("@planID", planID);
                            comm.Parameters.AddWithValue("@productID", productID);
                            comm.ExecuteNonQuery();
                        }
                    }
                    MessageBox.Show("Plan successfully updated");
                    f.sellingPlansToolStripMenuItem_Click(f.GetToolStripMenuItem("sellingPlansToolStripMenuItem"), e);
                    this.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Invalid input");
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Director f = (Director)this.parent;

            if (row == null)
            {
                try
                {
                    string connectionString = ConfigurationManager.ConnectionStrings["DairyDepartureConnectionString"].ConnectionString;

                    using (OleDbConnection conn = new OleDbConnection(connectionString))
                    {
                        conn.Open();
                        string sql = @"Insert into [Position] ([Position_name], [Payment_per_hour])
                                        values (@Position_name, @Payment_per_hour)";

                        using (OleDbCommand comm = new OleDbCommand(sql, conn))
                        {
                            comm.Parameters.AddWithValue("@Position_name", maskedTextBox1.Text);
                            comm.Parameters.AddWithValue("@Payment_per_hour", Decimal.Parse(maskedTextBox2.Text));
                            comm.ExecuteNonQuery();
                        }
                    }
                    MessageBox.Show("Position successfully added");
                    f.positionsToolStripMenuItem_Click(f.GetToolStripMenuItem("positionsToolStripMenuItem"), e);
                    this.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Invalid input");
                }
            }
            else
            {
                try
                {
                    int    posID            = Int32.Parse(row.Cells["ID_position"].Value.ToString());
                    string connectionString = ConfigurationManager.ConnectionStrings["DairyDepartureConnectionString"].ConnectionString;

                    using (OleDbConnection conn = new OleDbConnection(connectionString))
                    {
                        conn.Open();
                        string sql = @"Update [Position] 
                                        set [Position_name] = @Position_name, [Payment_per_hour] = @Payment_per_hour
                                        where ID_position = @id";

                        using (OleDbCommand comm = new OleDbCommand(sql, conn))
                        {
                            comm.Parameters.AddWithValue("@Position_name", maskedTextBox1.Text);
                            comm.Parameters.AddWithValue("@Payment_per_hour", Decimal.Parse(maskedTextBox2.Text));
                            comm.Parameters.AddWithValue("@Position_name", posID);
                            comm.ExecuteNonQuery();
                        }
                    }
                    MessageBox.Show("Position successfully updated");
                    this.Close();
                    f.positionsToolStripMenuItem_Click(f.GetToolStripMenuItem("positionsToolStripMenuItem"), e);
                }
                catch (Exception)
                {
                    MessageBox.Show("Invalid input");
                }
            }
        }
Beispiel #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            Director f = (Director)this.parent;

            if (row == null)
            {
                try
                {
                    string connectionString = ConfigurationManager.ConnectionStrings["DairyDepartureConnectionString"].ConnectionString;
                    using (OleDbConnection conn = new OleDbConnection(connectionString))
                    {
                        conn.Open();
                        string sql = @"Insert into Product ([Name_product], [ID_manufacturer], [Mass/volume], [%-fat], [ShelfLife])
                                    values (@Name_product, @ID_manufacturer, @Mass, @proc, @ShelfLife)
                    ";
                        using (OleDbCommand comm = new OleDbCommand(sql, conn))
                        {
                            comm.Parameters.AddWithValue("@Name_product", maskedTextBox1.Text);
                            comm.Parameters.AddWithValue("@ID_manufacturer", ((DairyDeparture1DataSet.Manufacturer_ЗапросRow)((DataRowView)((ComboBox)comboBox1).SelectedItem).Row).ID_manufacturer);
                            comm.Parameters.AddWithValue("@Mass", maskedTextBox2.Text);
                            comm.Parameters.AddWithValue("@proc", maskedTextBox3.Text);
                            comm.Parameters.AddWithValue("@ShelfLife", maskedTextBox4.Text);
                            comm.ExecuteNonQuery();
                        }
                    }
                    MessageBox.Show("Product successfully added");
                    f.productsToolStripMenuItem_Click(f.GetToolStripMenuItem("productsToolStripMenuItem"), e);
                    this.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Invalid input");
                }
            }
            else
            {
                try
                {
                    int prodID = Int32.Parse(row.Cells["ID_product"].Value.ToString());

                    string connectionString = ConfigurationManager.ConnectionStrings["DairyDepartureConnectionString"].ConnectionString;
                    using (OleDbConnection conn = new OleDbConnection(connectionString))
                    {
                        conn.Open();
                        string sql = @"Update Product 
                                        set [Name_product] = @Name_product, [ID_manufacturer] = @ID_manufacturer,
                                            [Mass/volume] = @Mass, [%-fat] = @proc, [ShelfLife] = @ShelfLife
                                            where ID_product = @prodID
                    ";
                        using (OleDbCommand comm = new OleDbCommand(sql, conn))
                        {
                            comm.Parameters.AddWithValue("@Name_product", maskedTextBox1.Text);
                            comm.Parameters.AddWithValue("@ID_manufacturer", ((DairyDeparture1DataSet.Manufacturer_ЗапросRow)((DataRowView)((ComboBox)comboBox1).SelectedItem).Row).ID_manufacturer);
                            comm.Parameters.AddWithValue("@Mass", maskedTextBox2.Text);
                            comm.Parameters.AddWithValue("@proc", maskedTextBox3.Text);
                            comm.Parameters.AddWithValue("@ShelfLife", maskedTextBox4.Text);
                            comm.Parameters.AddWithValue("@ID_product", prodID);
                            comm.ExecuteNonQuery();
                        }
                    }
                    MessageBox.Show("Product successfully added");
                    f.productsToolStripMenuItem_Click(f.GetToolStripMenuItem("productsToolStripMenuItem"), e);
                    this.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Invalid input");
                }
            }
        }