Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtCode.Text != "" || chBoxSelectAll.Checked)
                {
                    dbconnection.Open();
                    double price       = double.Parse(txtPrice.Text);
                    double SellPercent = double.Parse(txtSell.Text);

                    if (radioQata3y.Checked == true)
                    {
                        #region set qata3yPrice for list item
                        if (txtCode.Text == "" && chBoxSelectAll.Checked)
                        {
                            double    NormalPercent   = double.Parse(txtNormal.Text);
                            double    UnNormalPercent = double.Parse(txtUnNormal.Text);
                            DataTable dataTable       = (DataTable)gridControl1.DataSource;
                            for (int i = 0; i < dataTable.Rows.Count; i++)
                            {
                                string       query   = "INSERT INTO sellprice (Sell_Discount,Price_Type, Sell_Price, ProfitRatio, Data_ID, Price,Last_Price, PercentageDelegate,Date) VALUES(?Sell_Discount,?Price_Type,?Sell_Price,?ProfitRatio,?Data_ID,?Price,?Last_Price,?PercentageDelegate,?Date)";
                                MySqlCommand command = new MySqlCommand(query, dbconnection);
                                command.Parameters.AddWithValue("?Price_Type", "قطعى");
                                command.Parameters.AddWithValue("?Sell_Price", calSellPrice());
                                command.Parameters.AddWithValue("?Data_ID", dataTable.Rows[i][0].ToString());
                                command.Parameters.AddWithValue("?ProfitRatio", double.Parse(txtSell.Text));
                                command.Parameters.AddWithValue("?Price", price);
                                command.Parameters.AddWithValue("?Last_Price", calSellPrice());
                                command.Parameters.AddWithValue("?Sell_Discount", 0.0);
                                command.Parameters.AddWithValue("?PercentageDelegate", double.Parse(txtPercentageDelegate.Text));
                                command.Parameters.Add("?Date", MySqlDbType.Date);
                                command.Parameters["?Date"].Value = DateTime.Now.Date;

                                command.ExecuteNonQuery();
                            }
                        }
                        #endregion
                        #region set qata3yPrice for one item
                        else
                        {
                            if (id != 0)
                            {
                                string       query   = "INSERT INTO sellprice (Sell_Discount,Price_Type,Last_Price, Sell_Price, ProfitRatio, Data_ID, Price, PercentageDelegate,Date) VALUES(?Sell_Discount,?Price_Type,?Last_Price,?Sell_Price,?ProfitRatio,?Data_ID,?Price,?PercentageDelegate,?Date)";
                                MySqlCommand command = new MySqlCommand(query, dbconnection);
                                command.Parameters.AddWithValue("?Price_Type", "قطعى");
                                command.Parameters.AddWithValue("?Sell_Price", calSellPrice());
                                command.Parameters.AddWithValue("?Data_ID", id);
                                command.Parameters.AddWithValue("?ProfitRatio", double.Parse(txtSell.Text));
                                command.Parameters.AddWithValue("?Price", price);
                                command.Parameters.AddWithValue("?Last_Price", calSellPrice());
                                command.Parameters.AddWithValue("?Sell_Discount", 0.0);
                                command.Parameters.AddWithValue("?PercentageDelegate", double.Parse(txtPercentageDelegate.Text));
                                command.Parameters.Add("?Date", MySqlDbType.Date);
                                command.Parameters["?Date"].Value = DateTime.Now.Date;


                                command.ExecuteNonQuery();
                            }
                            else
                            {
                                MessageBox.Show("error in Data_ID");
                                dbconnection.Close();
                                return;
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region set priceList for collection of items
                        if (txtCode.Text == "" && chBoxSelectAll.Checked)
                        {
                            double NormalPercent   = double.Parse(txtNormal.Text);
                            double unNormalPercent = double.Parse(txtUnNormal.Text);

                            double sellPrice = (price + NormalPercent) - ((price + NormalPercent) * SellPercent / 100.0);

                            sellPrice = sellPrice + unNormalPercent;
                            DataTable dataTable = (DataTable)gridControl1.DataSource;
                            for (int i = 0; i < dataTable.Rows.Count; i++)
                            {
                                string       query   = "INSERT INTO sellprice (Last_Price,Price_Type,Sell_Price,Data_ID,Sell_Discount,Price,Normal_Increase,Categorical_Increase,PercentageDelegate,Date) VALUES (?Last_Price,?Price_Type,?Sell_Price,?Data_ID,?Sell_Discount,?Price,?Normal_Increase,?Categorical_Increase,?PercentageDelegate,?Date)";
                                MySqlCommand command = new MySqlCommand(query, dbconnection);
                                command.Parameters.AddWithValue("@Price_Type", "لستة");
                                command.Parameters.AddWithValue("@Sell_Price", calSellPrice());
                                command.Parameters.AddWithValue("?Data_ID", dataTable.Rows[i][0].ToString());
                                command.Parameters.AddWithValue("@Sell_Discount", double.Parse(txtSell.Text));
                                command.Parameters.AddWithValue("@Price", price);
                                command.Parameters.AddWithValue("@Last_Price", lastPrice());
                                command.Parameters.AddWithValue("@Normal_Increase", double.Parse(txtNormal.Text));
                                command.Parameters.AddWithValue("@Categorical_Increase", double.Parse(txtUnNormal.Text));
                                command.Parameters.AddWithValue("@PercentageDelegate", double.Parse(txtPercentageDelegate.Text));
                                command.Parameters.Add("?Date", MySqlDbType.Date);
                                command.Parameters["?Date"].Value = DateTime.Now.Date;

                                command.ExecuteNonQuery();
                            }
                        }

                        #endregion
                        #region set priceList for one item
                        else
                        {
                            if (id != 0)
                            {
                                double NormalPercent   = double.Parse(txtNormal.Text);
                                double unNormalPercent = double.Parse(txtUnNormal.Text);

                                double sellPrice = (price + NormalPercent) - ((price + NormalPercent) * SellPercent / 100.0);

                                sellPrice = sellPrice + unNormalPercent;

                                string       query   = "INSERT INTO sellprice (Last_Price,Price_Type,Sell_Price,Data_ID,Sell_Discount,Price,Normal_Increase,Categorical_Increase,PercentageDelegate,Date) VALUES (?Last_Price,?Price_Type,?Sell_Price,?Data_ID,?Sell_Discount,?Price,?Normal_Increase,?Categorical_Increase,?PercentageDelegate,?Date)";
                                MySqlCommand command = new MySqlCommand(query, dbconnection);
                                command.Parameters.AddWithValue("@Price_Type", "لستة");
                                command.Parameters.AddWithValue("@Sell_Price", calSellPrice());
                                command.Parameters.AddWithValue("?Data_ID", id);
                                command.Parameters.AddWithValue("@Sell_Discount", double.Parse(txtSell.Text));
                                command.Parameters.AddWithValue("@Price", price);
                                command.Parameters.AddWithValue("@Last_Price", lastPrice());
                                command.Parameters.AddWithValue("@Normal_Increase", double.Parse(txtNormal.Text));
                                command.Parameters.AddWithValue("@Categorical_Increase", double.Parse(txtUnNormal.Text));
                                command.Parameters.AddWithValue("@PercentageDelegate", double.Parse(txtPercentageDelegate.Text));
                                command.Parameters.Add("?Date", MySqlDbType.Date);
                                command.Parameters["?Date"].Value = DateTime.Now.Date;

                                command.ExecuteNonQuery();
                            }
                            else
                            {
                                MessageBox.Show("error in Data_ID");
                                dbconnection.Close();
                                return;
                            }
                        }
                        #endregion
                    }

                    int          sellPrice_ID = 0;
                    string       queryx       = "select SellPrice_ID from sellprice order by SellPrice_ID desc limit 1";
                    MySqlCommand com          = new MySqlCommand(queryx, dbconnection);
                    if (com.ExecuteScalar() != null)
                    {
                        sellPrice_ID = Convert.ToInt16(com.ExecuteScalar());
                    }
                    foreach (DataGridViewRow item in dataGridView1.Rows)
                    {
                        double addational = Convert.ToDouble(item.Cells[0].Value);
                        queryx = "insert into additional_increase_sellprice (SellPrice_ID,AdditionalValue,Type,Description) values (@SellPrice_ID,@AdditionalValue,@Type,@Description)";
                        com    = new MySqlCommand(queryx, dbconnection);
                        com.Parameters.AddWithValue("@SellPrice_ID", sellPrice_ID);
                        com.Parameters.AddWithValue("@Type", item.Cells[1].Value);
                        com.Parameters.AddWithValue("@AdditionalValue", item.Cells[0].Value);
                        com.Parameters.AddWithValue("@Description", item.Cells[2].Value);
                        com.ExecuteNonQuery();
                    }
                    UserControl.ItemRecord("sellprice", "اضافة", sellPrice_ID, DateTime.Now, "", dbconnection);

                    MessageBox.Show("Done");
                    Clear();
                    productsSellPriceForm.displayProducts();
                }
                else
                {
                    MessageBox.Show("select item");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
Ejemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                dbconnection.Open();
                if (!chBoxSpecialIncrease.Checked)
                {
                    double price       = double.Parse(txtPrice.Text);
                    double SellPercent = double.Parse(txtSell.Text);

                    if (radioQata3y.Checked == true)
                    {
                        #region set qata3yPrice for list item

                        double NormalPercent   = double.Parse(txtNormal.Text);
                        double UnNormalPercent = double.Parse(txtUnNormal.Text);

                        DataTable dataTable = (DataTable)gridControl1.DataSource;
                        for (int i = 0; i < dataTable.Rows.Count; i++)
                        {
                            String query = "update sellprice set Sell_Discount=@Sell_Discount,Normal_Increase=@Normal_Increase,Categorical_Increase=@Categorical_Increase,Price_Type=@Price_Type,Sell_Price=@Sell_Price,ProfitRatio=@ProfitRatio,Price=@Price,PercentageDelegate=@PercentageDelegate where SellPrice_ID=" + dataTable.Rows[i][0].ToString();

                            MySqlCommand command = new MySqlCommand(query, dbconnection);
                            command.Parameters.AddWithValue("@Price_Type", "قطعى");
                            command.Parameters.AddWithValue("@Sell_Price", price + (price * SellPercent / 100.0));
                            command.Parameters.AddWithValue("@ProfitRatio", SellPercent);
                            command.Parameters.AddWithValue("@Sell_Discount", 0.00);
                            command.Parameters.AddWithValue("@Price", price);
                            command.Parameters.AddWithValue("@Normal_Increase", 0.00);
                            command.Parameters.AddWithValue("@Categorical_Increase", 0.00);
                            command.Parameters.AddWithValue("@PercentageDelegate", double.Parse(txtPercentageDelegate.Text));

                            command.ExecuteNonQuery();
                        }

                        #endregion
                    }
                    else
                    {
                        #region set priceList for collection of items

                        double NormalPercent   = double.Parse(txtNormal.Text);
                        double unNormalPercent = double.Parse(txtUnNormal.Text);

                        double sellPrice = (price + NormalPercent) - ((price + NormalPercent) * SellPercent / 100.0);

                        sellPrice = sellPrice + unNormalPercent;

                        DataTable dataTable = (DataTable)gridControl1.DataSource;
                        for (int i = 0; i < dataTable.Rows.Count; i++)
                        {
                            string query = "update sellprice set ProfitRatio=@ProfitRatio, Price_Type=@Price_Type,Sell_Price=@Sell_Price,Sell_Discount=@Sell_Discount,Price=@Price,Normal_Increase=@Normal_Increase,Categorical_Increase=@Categorical_Increase,PercentageDelegate=@PercentageDelegate where SellPrice_ID =" + dataTable.Rows[i][0].ToString();

                            MySqlCommand command = new MySqlCommand(query, dbconnection);
                            command.Parameters.AddWithValue("@Price_Type", "لستة");
                            command.Parameters.AddWithValue("@Sell_Price", sellPrice);
                            command.Parameters.AddWithValue("@ProfitRatio", 0.00);
                            command.Parameters.AddWithValue("@Sell_Discount", double.Parse(txtSell.Text));
                            command.Parameters.AddWithValue("@Price", price);
                            command.Parameters.AddWithValue("@Normal_Increase", double.Parse(txtNormal.Text));
                            command.Parameters.AddWithValue("@Categorical_Increase", double.Parse(txtUnNormal.Text));
                            command.Parameters.AddWithValue("@PercentageDelegate", double.Parse(txtPercentageDelegate.Text));

                            command.ExecuteNonQuery();
                        }

                        #endregion
                    }
                    int          sellPrice_ID = 0;
                    string       queryx       = "select SellPrice_ID from sellprice order by SellPrice_ID desc limit 1";
                    MySqlCommand com          = new MySqlCommand(queryx, dbconnection);
                    if (com.ExecuteScalar() != null)
                    {
                        sellPrice_ID = Convert.ToInt16(com.ExecuteScalar());
                    }

                    queryx = "delete from additional_increase_sellprice where SellPrice_ID=" + sellPrice_ID;
                    com    = new MySqlCommand(queryx, dbconnection);
                    com.ExecuteNonQuery();

                    foreach (DataGridViewRow item in dataGridView1.Rows)
                    {
                        double addational = Convert.ToDouble(item.Cells[0].Value);
                        queryx = "insert into additional_increase_sellprice (SellPrice_ID,AdditionalValue,Type,Description) values (@SellPrice_ID,@AdditionalValue,@Type,@Description)";
                        com    = new MySqlCommand(queryx, dbconnection);
                        com.Parameters.AddWithValue("@SellPrice_ID", sellPrice_ID);
                        com.Parameters.AddWithValue("@Type", item.Cells[1].Value);
                        com.Parameters.AddWithValue("@AdditionalValue", item.Cells[0].Value);
                        com.Parameters.AddWithValue("@Description", item.Cells[2].Value);
                        com.ExecuteNonQuery();
                    }
                    UserControl.ItemRecord("sellprice", "تعديل", sellPrice_ID, DateTime.Now, "", dbconnection);
                }
                else
                {
                    double       addationalValue = 0.0;
                    DataGridView DataGridView    = (DataGridView)panContent.Controls["panContent"].Controls["dataGridView1"];
                    foreach (DataGridViewRow item1 in DataGridView.Rows)
                    {
                        addationalValue += Convert.ToDouble(item1.Cells[0].Value);
                    }
                    int[] rows = (((GridView)gridControl1.MainView).GetSelectedRows());
                    List <DataRowView> recordList = new List <DataRowView>();
                    for (int i = 0; i < rows.Length; i++)
                    {
                        DataRowView a = (DataRowView)(((GridView)gridControl1.MainView).GetRow(rows[i]));
                        recordList.Add(a);
                    }
                    foreach (DataRowView item in recordList)
                    {
                        String query = "update sellprice set Sell_Price=@Sell_Price where SellPrice_ID=" + item[0].ToString();

                        MySqlCommand command = new MySqlCommand(query, dbconnection);
                        command.Parameters.AddWithValue("@Sell_Price", Convert.ToDouble(item["سعر البيع"]) + addationalValue);
                        command.ExecuteNonQuery();

                        foreach (DataGridViewRow item1 in DataGridView.Rows)
                        {
                            double       addational = Convert.ToDouble(item1.Cells[0].Value);
                            string       queryx     = "insert into special_increase (SellPrice_ID,Value,Description,Date) values (@SellPrice_ID,@Value,@Description,@Date)";
                            MySqlCommand com        = new MySqlCommand(queryx, dbconnection);
                            com.Parameters.AddWithValue("@SellPrice_ID", item[0]);
                            com.Parameters.AddWithValue("@Value", item1.Cells[0].Value);
                            com.Parameters.AddWithValue("@Description", item1.Cells[1].Value);
                            com.Parameters.Add("@Date", MySqlDbType.Date);
                            com.Parameters["@Date"].Value = DateTime.Now.Date;
                            com.ExecuteNonQuery();
                        }
                    }
                }
                displayData();
                productsSellPriceForm.displayProducts();

                XtraTabPage xtraTabPage = getTabPage("تعديل اسعار البنود");
                xtraTabPage.ImageOptions.Image = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
Ejemplo n.º 3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                dbconnection.Open();
                double price       = double.Parse(txtPrice.Text);
                double SellPercent = double.Parse(txtSell.Text);

                if (radioQata3y.Checked == true)
                {
                    #region set qata3yPrice for list item

                    double NormalPercent   = double.Parse(txtNormal.Text);
                    double UnNormalPercent = double.Parse(txtUnNormal.Text);

                    DataTable dataTable = (DataTable)gridControl1.DataSource;
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        String query = "update sellprice set Sell_Discount=@Sell_Discount,Normal_Increase=@Normal_Increase,Categorical_Increase=@Categorical_Increase,Price_Type=@Price_Type,Sell_Price=@Sell_Price,ProfitRatio=@ProfitRatio,Price=@Price,PercentageDelegate=@PercentageDelegate where SellPrice_ID=" + dataTable.Rows[i][0].ToString();

                        MySqlCommand command = new MySqlCommand(query, dbconnection);
                        command.Parameters.AddWithValue("@Price_Type", "قطعى");
                        command.Parameters.AddWithValue("@Sell_Price", price + (price * SellPercent / 100.0));
                        command.Parameters.AddWithValue("@ProfitRatio", SellPercent);
                        command.Parameters.AddWithValue("@Sell_Discount", 0.00);
                        command.Parameters.AddWithValue("@Price", price);
                        command.Parameters.AddWithValue("@Normal_Increase", 0.00);
                        command.Parameters.AddWithValue("@Categorical_Increase", 0.00);
                        command.Parameters.AddWithValue("@PercentageDelegate", double.Parse(txtPercentageDelegate.Text));

                        command.ExecuteNonQuery();

                        UserControl.ItemRecord("sellprice", "تعديل", Convert.ToInt16(dataTable.Rows[i][0].ToString()), DateTime.Now, "", dbconnection);
                        dbconnection.Open();
                    }

                    #endregion
                }
                else
                {
                    #region set priceList for collection of items

                    double NormalPercent   = double.Parse(txtNormal.Text);
                    double unNormalPercent = double.Parse(txtUnNormal.Text);

                    double sellPrice = (price + NormalPercent) - ((price + NormalPercent) * SellPercent / 100.0);

                    sellPrice = sellPrice + unNormalPercent;

                    DataTable dataTable = (DataTable)gridControl1.DataSource;
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        string query = "update sellprice set ProfitRatio=@ProfitRatio, Price_Type=@Price_Type,Sell_Price=@Sell_Price,Sell_Discount=@Sell_Discount,Price=@Price,Normal_Increase=@Normal_Increase,Categorical_Increase=@Categorical_Increase,PercentageDelegate=@PercentageDelegate where SellPrice_ID =" + dataTable.Rows[i][0].ToString();

                        MySqlCommand command = new MySqlCommand(query, dbconnection);
                        command.Parameters.AddWithValue("@Price_Type", "لستة");
                        command.Parameters.AddWithValue("@Sell_Price", sellPrice);
                        command.Parameters.AddWithValue("@ProfitRatio", 0.00);
                        command.Parameters.AddWithValue("@Sell_Discount", double.Parse(txtSell.Text));
                        command.Parameters.AddWithValue("@Price", price);
                        command.Parameters.AddWithValue("@Normal_Increase", double.Parse(txtNormal.Text));
                        command.Parameters.AddWithValue("@Categorical_Increase", double.Parse(txtUnNormal.Text));
                        command.Parameters.AddWithValue("@PercentageDelegate", double.Parse(txtPercentageDelegate.Text));

                        command.ExecuteNonQuery();

                        UserControl.ItemRecord("sellprice", "تعديل", Convert.ToInt16(dataTable.Rows[i][0].ToString()), DateTime.Now, "", dbconnection);
                        dbconnection.Open();
                    }

                    #endregion
                }
                displayData();

                productsSellPriceForm.displayProducts();

                XtraTabPage xtraTabPage = getTabPage("تعديل اسعار البنود");

                xtraTabPage.ImageOptions.Image = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }