Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            DataTable dt3 = controllerObj.GetSname(username);
            string    s3  = dt3.Rows[0].Field <string>(0);


            if (addsaleradio.Checked == true)
            {
                int Percentage = TextboxValid(PercentageTextbox.Text, 1);

                float percent = Percentage;
                percent = percent / 100;

                if (PercentageTextbox.Text == "")//validation part
                {
                    MessageBox.Show("Please, insert all values");
                }
                else if (Percentage == -1)
                {
                    MessageBox.Show("Please, Make sure you entered a correct value");
                }
                else
                {
                    int r3 = controllerObj.CheckSales(comboBox2.Text, s3);

                    if (r3 == 0)
                    {
                        int r = controllerObj.InsertSale(Percentage, comboBox2.Text, s3);

                        if (r > 0)
                        {
                            int r2 = controllerObj.Addsale(percent, comboBox2.Text, s3);
                            if (r2 > 0)
                            {
                                MessageBox.Show("Sale Added successfully and Prices updated");
                            }
                            else
                            {
                                MessageBox.Show("Error Occured while updating prices");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("There is already sale on this department");
                    }
                }
            }
            if (removesaleradio.Checked == true)
            {
                int r = controllerObj.CheckSales(comboBox2.Text, s3);

                if (r > 0)
                {
                    int   Percentage = controllerObj.GetPercent(comboBox2.Text, s3);
                    float percent    = Percentage;
                    percent = percent / 100;
                    int r3 = controllerObj.DeleteSale(comboBox2.Text, s3);
                    int r2 = controllerObj.Removesale(percent, comboBox2.Text, s3);
                    if (r2 > 0 && r3 > 0)
                    {
                        MessageBox.Show("Sale Removed successfully");
                    }
                    else
                    {
                        MessageBox.Show("Error Occured while updating prices");
                    }
                }
                else
                {
                    MessageBox.Show("There is not sale on this department");
                }
            }
            if (increasepriceradio.Checked == true)
            {
                int Percentage = TextboxValid(PercentageTextbox.Text, 1);


                if (PercentageTextbox.Text == "")//validation part
                {
                    MessageBox.Show("Please, insert all values");
                }
                else if (Percentage == -1)
                {
                    MessageBox.Show("Please, Make sure you entered a correct value");
                }
                else
                {
                    int r = controllerObj.CheckSales(comboBox2.Text, s3);

                    if (r == 0)
                    {
                        DialogResult res = MessageBox.Show("Do you want to increase the prices of Department " + comboBox2.Text + " with " + Percentage + " %",
                                                           "Edu Store Application",
                                                           MessageBoxButtons.YesNo,
                                                           MessageBoxIcon.Question,
                                                           MessageBoxDefaultButton.Button2);
                        if (res == DialogResult.Yes)
                        {
                            float percent = Percentage;
                            percent = percent / 100;
                            int r2 = controllerObj.Incprice(percent, comboBox2.Text, s3);
                            if (r2 > 0)
                            {
                                MessageBox.Show("You Have increased the prices with " + Percentage + " %");
                            }
                            else
                            {
                                MessageBox.Show("Error Occured while updating prices");
                            }
                        }
                    }

                    else
                    {
                        MessageBox.Show("There is a sale on this department please remove it first");
                    }
                }
            }

            if (removesaleradio.Checked == false && addsaleradio.Checked == false && increasepriceradio.Checked == false)
            {
                MessageBox.Show("Please Select a Radio Button according to function you want");
            }

            this.SalesStatisticsforownersTableAdapter.Fill(this.DataSet1.SalesStatisticsforowners, s3);
            this.reportViewer1.RefreshReport();
        }