void delete(GridView view)
        {
            int[] selRows = ((GridView)gridControl1.MainView).GetSelectedRows();
            if (selRows.Length > 0)
            {
                if (MessageBox.Show("هل انت متاكد انك تريد الحذف؟", "تحذير", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                {
                    return;
                }

                conn.Open();
                for (int i = 0; i < selRows.Length; i++)
                {
                    DataRowView selRow = (DataRowView)(((GridView)gridControl1.MainView).GetRow(selRows[i]));

                    string       query  = "delete from supplier where Supplier_ID=" + selRow[0].ToString();
                    MySqlCommand comand = new MySqlCommand(query, conn);
                    comand.ExecuteNonQuery();

                    UserControl.ItemRecord("supplier", "حذف", Convert.ToInt32(selRow[0].ToString()), DateTime.Now, "", conn);
                }
                conn.Close();
                search();
            }
            else
            {
                MessageBox.Show("يجب ان تختار عنصر للحذف");
            }
        }
Beispiel #2
0
        private void radNewBill_Click(object sender, EventArgs e)
        {
            try
            {
                dbconnection.Open();
                int          id    = 0;
                string       query = "select Bill_Number from dash where Branch_ID=" + EmpBranchId + " order by Dash_ID desc limit 1";
                MySqlCommand cmd   = new MySqlCommand(query, dbconnection);
                if (cmd.ExecuteScalar() != null)
                {
                    id = Convert.ToInt32(cmd.ExecuteScalar());
                }
                id = id + 1;
                txtBill.Enabled = false;
                txtBill.Text    = id.ToString();

                query = "insert into dash (Bill_Number,Branch_ID,Bill_Date) values (@Bill_Number,@Branch_ID,@Bill_Date)";
                MySqlCommand com = new MySqlCommand(query, dbconnection);
                com.Parameters.Add("@Bill_Number", MySqlDbType.Int16).Value  = id;
                com.Parameters.Add("@Branch_ID", MySqlDbType.Int16).Value    = EmpBranchId;
                com.Parameters.Add("@Bill_Date", MySqlDbType.DateTime).Value = DateTime.Now;
                com.ExecuteNonQuery();

                string       q       = "select Dash_ID from dash where Branch_ID=" + EmpBranchId + " and Bill_Number=" + id + " order by Dash_ID desc limit 1";
                MySqlCommand command = new MySqlCommand(q, dbconnection);
                int          dashId  = Convert.ToInt32(command.ExecuteScalar().ToString());

                UserControl.ItemRecord("dash", "اضافة", dashId, DateTime.Now, null, dbconnection);
                dbconnection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                dbconnection.Open();

                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete the item?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    DataTable dataTable = (DataTable)gridControl1.DataSource;
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        if (gridView1.IsRowSelected(i))
                        {
                            string       query  = "delete from sellprice where SellPrice_ID='" + dataTable.Rows[i][0].ToString() + "'";
                            MySqlCommand comand = new MySqlCommand(query, dbconnection);

                            comand.ExecuteNonQuery();

                            UserControl.ItemRecord("sellprice", "حذف", Convert.ToInt32(dataTable.Rows[i][0].ToString()), DateTime.Now, "", dbconnection);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
Beispiel #4
0
        void delete()
        {
            string       query = "delete from area where Area_ID=" + areaId;
            MySqlCommand com   = new MySqlCommand(query, dbConnection);

            com.ExecuteNonQuery();
            UserControl.ItemRecord("area", "حذف", areaId, DateTime.Now, null, dbConnection);
        }
Beispiel #5
0
        void delete()
        {
            string       query = "delete from property_details where DetailsProperty_ID=" + row1[0].ToString();
            MySqlCommand com   = new MySqlCommand(query, dbConnection);

            com.ExecuteNonQuery();

            UserControl.ItemRecord("property_details", "حذف", Convert.ToInt32(row1[0].ToString()), DateTime.Now, null, dbConnection);
        }
Beispiel #6
0
        void delete()
        {
            string       query = "delete from expense_sub where SubExpense_ID=" + row1[0].ToString();
            MySqlCommand com   = new MySqlCommand(query, dbConnection);

            com.ExecuteNonQuery();

            UserControl.ItemRecord("expense_sub", "حذف", Convert.ToInt32(row1[0].ToString()), DateTime.Now, null, dbConnection);
        }
Beispiel #7
0
        void delete()
        {
            string       query = "delete from zone where Zone_ID=" + zoneId;
            MySqlCommand com   = new MySqlCommand(query, dbConnection);

            com.ExecuteNonQuery();

            query = "update area set Zone_ID=null where Zone_ID=" + zoneId;
            com   = new MySqlCommand(query, dbConnection);
            com.ExecuteNonQuery();

            UserControl.ItemRecord("zone", "حذف", zoneId, DateTime.Now, null, dbConnection);
        }
        void delete()
        {
            string       query = "delete from expense_main where MainExpense_ID=" + row1[0].ToString();
            MySqlCommand com   = new MySqlCommand(query, dbConnection);

            com.ExecuteNonQuery();

            /*query = "update expense_sub set MainExpense_ID=null where MainExpense_ID=" + MainExpenseId;
             * com = new MySqlCommand(query, dbConnection);
             * com.ExecuteNonQuery();*/

            UserControl.ItemRecord("expense_main", "حذف", Convert.ToInt32(row1[0].ToString()), DateTime.Now, null, dbConnection);
        }
Beispiel #9
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                dbconnection.Open();
                DataRowView setRow = (DataRowView)(((GridView)gridControl1.MainView).GetRow(((GridView)gridControl1.MainView).GetSelectedRows()[0]));

                if (setRow != null)
                {
                    DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete the item?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Yes)
                    {
                        if (setRow[0].ToString() == "موظف")
                        {
                            string       Query     = "delete from employee where Employee_ID=" + setRow[1].ToString();
                            MySqlCommand MyCommand = new MySqlCommand(Query, dbconnection);
                            MyCommand.ExecuteNonQuery();

                            string       query = "ALTER TABLE employee AUTO_INCREMENT = 1;";
                            MySqlCommand com   = new MySqlCommand(query, dbconnection);
                            com.ExecuteNonQuery();
                            UserControl.ItemRecord("employee", "حذف", Convert.ToInt32(setRow[1].ToString()), DateTime.Now, "", dbconnection);
                        }
                        else
                        {
                            string       Query     = "delete from delegate where Delegate_ID=" + setRow[1].ToString();
                            MySqlCommand MyCommand = new MySqlCommand(Query, dbconnection);
                            MyCommand.ExecuteNonQuery();

                            string       query = "ALTER TABLE delegate AUTO_INCREMENT = 1;";
                            MySqlCommand com   = new MySqlCommand(query, dbconnection);
                            com.ExecuteNonQuery();
                            UserControl.ItemRecord("employee", "حذف", Convert.ToInt32(setRow[1].ToString()), DateTime.Now, "", dbconnection);
                        }
                        displayEmployee();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                    }
                }
                else
                {
                    MessageBox.Show("select row");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
Beispiel #10
0
        private void btnAddMain_Click(object sender, EventArgs e)//add New Main Property button
        {
            if (txtDetailsNameAdd.Text != "" && comSubAdd.SelectedValue != null)
            {
                try
                {
                    dbConnection.Open();
                    string       q = "select DetailsProperty_Name from property_details where DetailsProperty_Name='" + txtDetailsNameAdd.Text + "' and SubProperty_ID=" + comSubAdd.SelectedValue.ToString();
                    MySqlCommand c = new MySqlCommand(q, dbConnection);
                    if (c.ExecuteScalar() == null)
                    {
                        string       query = "insert into property_details (DetailsProperty_Name,SubProperty_ID) values (@DetailsProperty_Name,@SubProperty_ID)";
                        MySqlCommand com   = new MySqlCommand(query, dbConnection);
                        com.Parameters.Add("@DetailsProperty_Name", MySqlDbType.VarChar).Value = txtDetailsNameAdd.Text;
                        com.Parameters.Add("@SubProperty_ID", MySqlDbType.VarChar).Value       = comSubAdd.SelectedValue.ToString();
                        com.ExecuteNonQuery();
                        txtDetailsNameAdd.Text  = "";
                        comSubAdd.SelectedIndex = -1;

                        q = "select DetailsProperty_ID from property_details order by DetailsProperty_ID desc limit 1";
                        c = new MySqlCommand(q, dbConnection);
                        int SubId = Convert.ToInt32(c.ExecuteScalar().ToString());

                        UserControl.ItemRecord("property_details", "اضافة", SubId, DateTime.Now, null, dbConnection);

                        updateLists();//update combox1
                        displayAllMain();
                        panelUpdateSub.Visible = false;
                        panelAddSub.Visible    = false;
                    }
                    else
                    {
                        MessageBox.Show("هذا العقار تم اضافته من قبل");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                dbConnection.Close();
            }
            else
            {
                MessageBox.Show("يجب التاكد من البيانات");
            }
        }
        private void btnAddNewSub_Click(object sender, EventArgs e)
        {
            if (txtMainAdd.Text != "")
            {
                try
                {
                    dbConnection.Open();
                    string       q = "select MainExpense_Name from expense_main where MainExpense_Name='" + txtMainAdd.Text + "'";
                    MySqlCommand c = new MySqlCommand(q, dbConnection);
                    if (c.ExecuteScalar() == null)
                    {
                        string       query = "insert into expense_main (MainExpense_Name) values (@MainExpense_Name)";
                        MySqlCommand com   = new MySqlCommand(query, dbConnection);
                        com.Parameters.Add("@MainExpense_Name", MySqlDbType.VarChar).Value = txtMainAdd.Text;
                        com.ExecuteNonQuery();
                        txtMainAdd.Text = "";

                        q = "select MainExpense_ID from expense_main order by MainExpense_ID desc limit 1";
                        c = new MySqlCommand(q, dbConnection);
                        int MainExpenseId = Convert.ToInt32(c.ExecuteScalar().ToString());

                        UserControl.ItemRecord("expense_main", "اضافة", MainExpenseId, DateTime.Now, null, dbConnection);
                        updateLists();
                        displayAllMain();
                        panelAddMain.Visible    = false;
                        panelUpdateMain.Visible = false;
                    }
                    else
                    {
                        MessageBox.Show("هذا المصروف تم اضافته من قبل");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                dbConnection.Close();
            }
            else
            {
                MessageBox.Show("يجب التاكد من البيانات");
            }
        }
Beispiel #12
0
        private void btnAddNewArea_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtArea.Text != "")
                {
                    dbConnection.Open();
                    string       q = "select Area_Name from area where Area_Name='" + txtArea.Text + "'";
                    MySqlCommand c = new MySqlCommand(q, dbConnection);
                    if (c.ExecuteScalar() == null)
                    {
                        string       query = "insert into area (Area_Name) values (@Area_Name)";
                        MySqlCommand com   = new MySqlCommand(query, dbConnection);
                        com.Parameters.Add("@Area_Name", MySqlDbType.VarChar).Value = txtArea.Text;
                        com.ExecuteNonQuery();
                        txtArea.Text = "";

                        q = "select Area_ID from area order by Area_ID desc limit 1";
                        c = new MySqlCommand(q, dbConnection);
                        int areId = Convert.ToInt32(c.ExecuteScalar().ToString());

                        UserControl.ItemRecord("area", "اضافة", areId, DateTime.Now, null, dbConnection);
                        updateLists();
                        displayAllAreas();
                        MessageBox.Show("تم الاضافة");
                    }
                    else
                    {
                        MessageBox.Show("هذه المنطقة تم اضافتها من قبل");
                    }
                }
                else
                {
                    MessageBox.Show("يجب ادخال البيانات كاملة");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            dbConnection.Close();
        }
Beispiel #13
0
        private void btnUpdateMain_Click(object sender, EventArgs e)//update
        {
            if (txtDetailsNameUpdate.Text != "" && comSubUpdate.SelectedValue != null)
            {
                try
                {
                    dbConnection.Open();
                    string       q = "select DetailsProperty_Name from property_details where DetailsProperty_Name='" + txtDetailsNameUpdate.Text + "' and SubProperty_ID=" + comSubUpdate.SelectedValue.ToString() + " and DetailsProperty_ID<>" + row1[0].ToString();
                    MySqlCommand c = new MySqlCommand(q, dbConnection);
                    if (c.ExecuteScalar() == null)
                    {
                        string       query = "update property_details set DetailsProperty_Name=@DetailsProperty_Name,SubProperty_ID=@SubProperty_ID where DetailsProperty_ID=" + row1[0].ToString();
                        MySqlCommand com   = new MySqlCommand(query, dbConnection);
                        com.Parameters.Add("@DetailsProperty_Name", MySqlDbType.VarChar).Value = txtDetailsNameUpdate.Text;
                        com.Parameters.Add("@SubProperty_ID", MySqlDbType.VarChar).Value       = comSubUpdate.SelectedValue.ToString();
                        com.ExecuteNonQuery();
                        txtDetailsNameUpdate.Text  = "";
                        comSubUpdate.SelectedIndex = -1;

                        UserControl.ItemRecord("property_details", "تعديل", Convert.ToInt32(row1[0].ToString()), DateTime.Now, null, dbConnection);

                        updateLists();//update combox1
                        displayAllMain();
                        panelUpdateSub.Visible = false;
                        panelAddSub.Visible    = false;
                    }
                    else
                    {
                        MessageBox.Show("هذا العقار تم اضافته من قبل");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                dbConnection.Close();
            }
            else
            {
                MessageBox.Show("يجب التاكد من البيانات");
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                dbconnection.Open();
                DataRowView  row1         = (DataRowView)(((GridView)gridControl1.MainView).GetRow(((GridView)gridControl1.MainView).GetSelectedRows()[0]));
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete the item?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    string       query = "select Money from supplier_rest_money where Supplier_ID=" + row1["Supplier_ID"].ToString();
                    MySqlCommand com   = new MySqlCommand(query, dbconnection);
                    if (com.ExecuteScalar() != null)
                    {
                        double restMoney = Convert.ToDouble(com.ExecuteScalar());

                        if (row1["نوع التسوية"].ToString() == "اضافة")
                        {
                            query = "update supplier_rest_money set Money=" + (restMoney - Convert.ToDouble(row1["قيمة التسوية"].ToString())) + " where Supplier_ID=" + row1["Supplier_ID"].ToString();
                        }
                        else
                        {
                            query = "update supplier_rest_money set Money=" + (restMoney + Convert.ToDouble(row1["قيمة التسوية"].ToString())) + " where Supplier_ID=" + row1["Supplier_ID"].ToString();
                        }
                        com = new MySqlCommand(query, dbconnection);
                        com.ExecuteNonQuery();
                    }

                    query = "delete from supplier_taswaya where SupplierTaswaya_ID=" + row1[0].ToString() + "";
                    com   = new MySqlCommand(query, dbconnection);
                    com.ExecuteNonQuery();
                    UserControl.ItemRecord("supplier_taswaya", "حذف", Convert.ToInt32(row1[0].ToString()), DateTime.Now, "", dbconnection);

                    gridView1.DeleteSelectedRows();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
Beispiel #15
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                dbconnection.Open();
                DataRowView setRow = (DataRowView)(((GridView)dataGridView1.MainView).GetRow(((GridView)dataGridView1.MainView).GetSelectedRows()[0]));


                if (setRow != null)
                {
                    DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete the item?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (dialogResult == DialogResult.Yes)
                        {

                        deleteSet(Convert.ToInt32(setRow[0].ToString()));
                        
                        string query = "ALTER TABLE sets AUTO_INCREMENT = 1;";
                        MySqlCommand com = new MySqlCommand(query, dbconnection);
                        com.ExecuteNonQuery();

                        UserControl.ItemRecord("sets", "delete",Convert.ToInt32(setRow[0].ToString()), DateTime.Now,"", dbconnection);
                        dbconnection.Close();
                
                        }
                        else if (dialogResult == DialogResult.No)
                        { }
              
                }
                else
                {
                    MessageBox.Show("select row");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            dbconnection.Close();
        }
Beispiel #16
0
        public void saveStore()
        {
            conn.Open();
            string       query = "select Store_Name from store where Store_Name='" + txtName.Text + "'";
            MySqlCommand com   = new MySqlCommand(query, conn);

            if (com.ExecuteScalar() == null)
            {
                if (txtName.Text != "")
                {
                    string qeury = "insert into store (Store_Name,Store_Address,Store_Phone)values(@Name,@Address,@Phone)";
                    com = new MySqlCommand(qeury, conn);
                    com.Parameters.Add("@Name", MySqlDbType.VarChar, 255);
                    com.Parameters["@Name"].Value = txtName.Text;
                    com.Parameters.Add("@Address", MySqlDbType.VarChar, 255);
                    com.Parameters["@Address"].Value = txtAddress.Text;
                    com.Parameters.Add("@Phone", MySqlDbType.VarChar, 255);
                    com.Parameters["@Phone"].Value = txtPhone.Text;

                    com.ExecuteNonQuery();
                    query = "select Type_ID from type order by Type_ID desc limit 1";
                    com   = new MySqlCommand(query, conn);

                    UserControl.ItemRecord("store", "اضافة", (int)com.ExecuteScalar(), DateTime.Now, "", conn);

                    MessageBox.Show("add success");
                    clear();
                    txtName.Focus();
                    stores.DisplayStores();
                }
                else
                {
                    MessageBox.Show("ادخل الاسم");
                }
            }
            else
            {
                MessageBox.Show("هذا الاسم مضاف من قبل.");
            }
        }
        private void btnMainUpdate_Click(object sender, EventArgs e)
        {
            if (txtMainUpdate.Text != "")
            {
                try
                {
                    dbConnection.Open();
                    string       q = "select MainExpense_Name from expense_main where MainExpense_Name='" + txtMainUpdate.Text + "' and MainExpense_ID<>" + row1[0].ToString();
                    MySqlCommand c = new MySqlCommand(q, dbConnection);
                    if (c.ExecuteScalar() == null)
                    {
                        string       query = "update expense_main set MainExpense_Name=@MainExpense_Name where MainExpense_ID=" + row1[0].ToString();
                        MySqlCommand com   = new MySqlCommand(query, dbConnection);
                        com.Parameters.Add("@MainExpense_Name", MySqlDbType.VarChar).Value = txtMainUpdate.Text;
                        com.ExecuteNonQuery();
                        txtMainUpdate.Text = "";

                        UserControl.ItemRecord("expense_main", "تعديل", Convert.ToInt32(row1[0].ToString()), DateTime.Now, null, dbConnection);
                        updateLists();
                        displayAllMain();
                        panelAddMain.Visible    = false;
                        panelUpdateMain.Visible = false;
                    }
                    else
                    {
                        MessageBox.Show("هذا المصروف تم اضافته من قبل");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                dbConnection.Close();
            }
            else
            {
                MessageBox.Show("يجب التاكد من البيانات");
            }
        }
Beispiel #18
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtQuantity.Text != "")
            {
                double quantity  = 0;
                int    CartonNum = 0;
                if (double.TryParse(txtQuantity.Text, out quantity))
                {
                    try
                    {
                        dbconnection.Open();

                        string       query = "select Total_Meters from storage where Store_ID=" + storeID + " and Data_ID=" + selRow["Data_ID"].ToString();
                        MySqlCommand com   = new MySqlCommand(query, dbconnection);
                        if (com.ExecuteScalar() != null)
                        {
                            double totalf = Convert.ToDouble(com.ExecuteScalar());

                            totalf = (totalf - Convert.ToDouble(selRow["متر/قطعة"].ToString()));

                            if ((totalf + quantity) >= 0)
                            {
                                string q = "select Carton from data where Data_ID=" + selRow["Data_ID"].ToString();
                                com = new MySqlCommand(q, dbconnection);

                                double carton = double.Parse(com.ExecuteScalar().ToString());
                                if (carton > 0)
                                {
                                    double total = quantity / carton;
                                    CartonNum = Convert.ToInt32(total);
                                }

                                query = "update supplier_permission_details set Total_Meters=" + quantity + " , Carton_Balata=" + CartonNum + " where Supplier_Permission_Details_ID=" + selRow["Supplier_Permission_Details_ID"].ToString();
                                com   = new MySqlCommand(query, dbconnection);
                                com.ExecuteNonQuery();

                                query = "update storage set Total_Meters=" + (totalf + quantity) + " where Store_ID=" + storeID + " and Data_ID=" + selRow["Data_ID"].ToString();
                                com   = new MySqlCommand(query, dbconnection);
                                com.ExecuteNonQuery();

                                UserControl.ItemRecord("storage", "تعديل", Convert.ToInt16(selRow["Data_ID"].ToString()), DateTime.Now, "اذن مخزن", dbconnection);


                                #region MyRegion
                                if (selRow["Factory_ID"].ToString() != "" && selRow["رقم الطلب"].ToString() != "")
                                {
                                    dbconnection2.Open();
                                    query = "select order_details.OrderDetails_ID,order_details.Quantity from orders INNER JOIN order_details ON order_details.Order_ID = orders.Order_ID where order_details.Data_ID=" + selRow["Data_ID"].ToString() + " and orders.Factory_ID=" + selRow["Factory_ID"].ToString() + " and orders.Order_Number=" + selRow["رقم الطلب"].ToString();
                                    com   = new MySqlCommand(query, dbconnection);
                                    MySqlDataReader dr = com.ExecuteReader();
                                    if (dr.HasRows)
                                    {
                                        while (dr.Read())
                                        {
                                            double orderQuantity = Convert.ToDouble(dr["Quantity"].ToString());
                                            if (orderQuantity == quantity)
                                            {
                                                query = "update order_details set Received=1 where OrderDetails_ID=" + dr["OrderDetails_ID"].ToString();
                                            }
                                            else
                                            {
                                                query = "select sum(supplier_permission_details.Total_Meters) as 'Total_Meters' from supplier_permission_details INNER JOIN data ON supplier_permission_details.Data_ID = data.Data_ID INNER JOIN import_supplier_permission ON supplier_permission_details.ImportSupplierPermission_ID = import_supplier_permission.ImportSupplierPermission_ID INNER JOIN storage_import_permission ON storage_import_permission.StorageImportPermission_ID = import_supplier_permission.StorageImportPermission_ID  INNER JOIN supplier ON import_supplier_permission.Supplier_ID = supplier.Supplier_ID inner JOIN order_details ON supplier_permission_details.Data_ID = order_details.Data_ID inner JOIN orders ON order_details.Order_ID = orders.Order_ID INNER JOIN type ON type.Type_ID = data.Type_ID INNER JOIN product ON product.Product_ID = data.Product_ID INNER JOIN factory ON data.Factory_ID = factory.Factory_ID INNER JOIN groupo ON data.Group_ID = groupo.Group_ID LEFT JOIN color ON color.Color_ID = data.Color_ID LEFT JOIN size ON size.Size_ID = data.Size_ID LEFT JOIN sort ON sort.Sort_ID = data.Sort_ID where data.Data_ID=" + selRow["Data_ID"].ToString() + " and orders.Order_Number=" + selRow["رقم الطلب"].ToString() + " and orders.Factory_ID=" + selRow["Factory_ID"].ToString() + " ";
                                                com   = new MySqlCommand(query, dbconnection2);
                                                MySqlDataReader dr2 = com.ExecuteReader();
                                                if (dr2.HasRows)
                                                {
                                                    while (dr2.Read())
                                                    {
                                                        if (dr2["Total_Meters"].ToString() != "")
                                                        {
                                                            if (Convert.ToDouble(dr2["Total_Meters"].ToString()) > 0)
                                                            {
                                                                query = "update order_details set Received=2 where OrderDetails_ID=" + dr["OrderDetails_ID"].ToString();
                                                            }
                                                            else
                                                            {
                                                                query = "update order_details set Received=0 where OrderDetails_ID=" + dr["OrderDetails_ID"].ToString();
                                                            }
                                                        }
                                                        else
                                                        {
                                                            query = "update order_details set Received=0 where OrderDetails_ID=" + dr["OrderDetails_ID"].ToString();
                                                        }
                                                    }
                                                }
                                                dr2.Close();
                                            }

                                            com = new MySqlCommand(query, dbconnection2);
                                            com.ExecuteNonQuery();
                                        }
                                    }
                                    dr.Close();
                                }
                                #endregion
                                dbconnection.Close();
                                dbconnection2.Close();
                                if (supplierReceiptUpdate == null)
                                {
                                    permissionsReport.refreshView(rowHandel, quantity, CartonNum);
                                }
                                else /*if (FormName == "SupplierReceiptUpdate")*/
                                {
                                    supplierReceiptUpdate.refreshView(rowHandel, quantity, CartonNum);

                                    permissionsReport.refreshView(rowHandel, quantity, CartonNum);
                                }
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("لا يوجد كمية كافية");
                            }
                        }
                        else
                        {
                            MessageBox.Show("لا يوجد كمية كافية");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    dbconnection.Close();
                    dbconnection2.Close();
                }
                else
                {
                    MessageBox.Show("الكمية يجب ان تكون عدد");
                }
            }
            else
            {
                MessageBox.Show("يجب ادخال الكمية");
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                int[] selRows = ((GridView)gridControl1.MainView).GetSelectedRows();
                if (selRows.Length > 0)
                {
                    if (MessageBox.Show("هل انت متاكد انك تريد الحذف؟", "تحذير", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                    {
                        return;
                    }

                    Form prompt = new Form()
                    {
                        Width           = 500,
                        Height          = 220,
                        FormBorderStyle = FormBorderStyle.FixedDialog,
                        Text            = "",
                        StartPosition   = FormStartPosition.CenterScreen,
                        MaximizeBox     = false,
                        MinimizeBox     = false
                    };
                    Label textLabel = new Label()
                    {
                        Left = 340, Top = 20, Text = "ما هو سبب الحذف؟"
                    };
                    TextBox textBox = new TextBox()
                    {
                        Left = 50, Top = 50, Width = 385, Multiline = true, Height = 80, RightToLeft = RightToLeft
                    };
                    Button confirmation = new Button()
                    {
                        Text = "تأكيد", Left = 200, Width = 100, Top = 140, DialogResult = DialogResult.OK
                    };
                    prompt.Controls.Add(textBox);
                    prompt.Controls.Add(confirmation);
                    prompt.Controls.Add(textLabel);
                    prompt.AcceptButton = confirmation;
                    if (prompt.ShowDialog() == DialogResult.OK)
                    {
                        if (textBox.Text != "")
                        {
                            conn.Open();
                            for (int i = 0; i < gridView1.SelectedRowsCount; i++)
                            {
                                DataRowView  selRow    = (DataRowView)(((GridView)gridControl1.MainView).GetRow(selRows[i]));
                                string       Query     = "update attendance set Error=1 where Attendance_ID=" + Convert.ToInt32(selRow[0].ToString());
                                MySqlCommand MyCommand = new MySqlCommand(Query, conn);
                                MyCommand.ExecuteNonQuery();

                                UserControl.ItemRecord("attendance", "حذف", Convert.ToInt32(selRow[0].ToString()), DateTime.Now, textBox.Text, conn);
                            }
                            search();
                        }
                        else
                        {
                            MessageBox.Show("يجب كتابة السبب");
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                    MessageBox.Show("يجب ان تختار عنصر للحذف");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            conn.Close();
        }
Beispiel #20
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtName.Text != "" && checkedListBoxControlPhone.ItemCount > 0)
                {
                    dbconnection.Open();
                    if (checkPhonesExist())
                    {
                        double outputDebit;
                        double outputCredit;
                        if (double.TryParse(txtDebit.Text, out outputDebit))
                        {
                        }
                        else
                        {
                            MessageBox.Show("يجب التاكد من ادخال عدد فى مبلغ المدين");
                            dbconnection.Close();
                            return;
                        }
                        if (double.TryParse(txtCredit.Text, out outputCredit))
                        {
                        }
                        else
                        {
                            MessageBox.Show("يجب التاكد من ادخال عدد فى مبلغ الدائن");
                            dbconnection.Close();
                            return;
                        }

                        string       query = "insert into supplier (Supplier_Name,Supplier_Address,Supplier_Fax,Supplier_Mail,Supplier_Start,Supplier_Info,Supplier_Credit,Supplier_Debit) values (@Name,@Address,@Fax,@E_mail,@Start_Date,@Info,@Supplier_Credit,@Supplier_Debit)";
                        MySqlCommand com   = new MySqlCommand(query, dbconnection);
                        com.Parameters.Add("@Name", MySqlDbType.VarChar, 255);
                        com.Parameters["@Name"].Value = txtName.Text;
                        com.Parameters.Add("@Address", MySqlDbType.VarChar, 255);
                        com.Parameters["@Address"].Value = txtAddress.Text;
                        com.Parameters.Add("@Fax", MySqlDbType.VarChar, 255);
                        com.Parameters["@Fax"].Value = txtFax.Text;
                        com.Parameters.Add("@E_mail", MySqlDbType.VarChar, 255);
                        com.Parameters["@E_mail"].Value = txtMail.Text;
                        com.Parameters.Add("@Start_Date", MySqlDbType.Date, 0);
                        com.Parameters["@Start_Date"].Value = dateTimePicker1.Value.Date;
                        com.Parameters.Add("@Supplier_Credit", MySqlDbType.Decimal, 10);
                        com.Parameters["@Supplier_Credit"].Value = outputCredit;
                        com.Parameters.Add("@Supplier_Debit", MySqlDbType.Decimal, 10);
                        com.Parameters["@Supplier_Debit"].Value = outputDebit;
                        com.Parameters.Add("@Info", MySqlDbType.VarChar, 255);
                        com.Parameters["@Info"].Value = txtInfo.Text;
                        com.ExecuteNonQuery();

                        query = "SELECT Supplier_ID FROM supplier ORDER BY Supplier_ID DESC LIMIT 1";
                        com   = new MySqlCommand(query, dbconnection);
                        int id = 0;
                        if (com.ExecuteScalar() != null)
                        {
                            id = (int)com.ExecuteScalar();
                        }

                        AddPhoneNumbers(id);
                        AddFactory(id);

                        UserControl.ItemRecord("supplier", "اضافة", id, DateTime.Now, "", dbconnection);

                        clear();
                        xtraTabPage.ImageOptions.Image = null;
                    }
                    else
                    {
                        MessageBox.Show("يوجد رقم تليفون موجود من قبل");
                        dbconnection.Close();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("برجاء ادخال البيانات كاملة");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            dbconnection.Close();
        }
Beispiel #21
0
        private void addNewZone()
        {
            if (txtZoneNameAdd.Text != "")
            {
                bool         flag = false;
                string       q    = "select Zone_Name from zone where Zone_Name='" + txtZoneNameAdd.Text + "'";
                MySqlCommand c    = new MySqlCommand(q, dbConnection);
                if (c.ExecuteScalar() == null)
                {
                    int zonId = 0;
                    foreach (DataRowView item in checkedListBoxAreas.CheckedItems)
                    {
                        string areaName = item["Area_Name"].ToString();
                        if (!flag)
                        {
                            flag = true;

                            string       query = "insert into zone (Zone_Name) values (@Zone_Name)";
                            MySqlCommand com   = new MySqlCommand(query, dbConnection);
                            com.Parameters.Add("@Zone_Name", MySqlDbType.VarChar).Value = txtZoneNameAdd.Text;
                            com.ExecuteNonQuery();

                            q     = "select Zone_ID from zone order by Zone_ID desc limit 1";
                            c     = new MySqlCommand(q, dbConnection);
                            zonId = Convert.ToInt32(c.ExecuteScalar().ToString());

                            /*q = "select Zone_ID from area where Area_ID="+ item["Area_ID"].ToString();
                             * c = new MySqlCommand(q, dbConnection);
                             * if (c.ExecuteScalar() == null)
                             * {*/
                            query = "update area set Zone_ID=@Zone_ID where area_ID=" + item["Area_ID"].ToString();
                            com   = new MySqlCommand(query, dbConnection);
                            com.Parameters.Add("@Zone_ID", MySqlDbType.VarChar).Value = zonId;
                            com.ExecuteNonQuery();

                            /*}
                             * else
                             * {}*/
                        }
                        else
                        {
                            string       query2 = "update area set Zone_ID=@Zone_ID where area_ID=" + item["Area_ID"].ToString();
                            MySqlCommand com    = new MySqlCommand(query2, dbConnection);
                            com.Parameters.Add("@Zone_ID", MySqlDbType.VarChar).Value = zonId;
                            com.ExecuteNonQuery();
                        }
                    }
                    if (!flag)
                    {
                        string       query = "insert into zone (Zone_Name) values (@Zone_Name)";
                        MySqlCommand com   = new MySqlCommand(query, dbConnection);
                        com.Parameters.Add("@Zone_Name", MySqlDbType.VarChar).Value = txtZoneNameAdd.Text;
                        com.ExecuteNonQuery();
                    }

                    UserControl.ItemRecord("zone", "اضافة", zoneId, DateTime.Now, null, dbConnection);

                    updateLists();//update combox1
                    displayAllZones();
                    panelUpdateZone.Visible = false;
                    panelAddZone.Visible    = false;
                    MessageBox.Show("تم الاضافة");
                }
                else
                {
                    MessageBox.Show("هذه الزون تم اضافتها من قبل");
                    dbConnection.Close();
                    return;
                }
            }
            else
            {
                MessageBox.Show("يجب ادخال الاسم");
                dbConnection.Close();
                return;
            }
        }
        private void btnUpdateProduct_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtFactory.Text != "" && txtGroup.Text != "" && txtProduct.Text != "" && txtType.Text != "")
                {
                    double carton = 0;
                    string classification, description = "";
                    if (comColour.Text != "")
                    {
                        try
                        {
                            color_id = Convert.ToInt32(comColour.SelectedValue.ToString());
                        }
                        catch
                        {
                        }
                    }
                    if (comSize.Text != "")
                    {
                        try
                        {
                            size_id = Convert.ToInt32(comSize.SelectedValue.ToString());
                        }
                        catch
                        {
                        }
                    }
                    if (comSort.Text != "")
                    {
                        try
                        {
                            sort_id = Convert.ToInt32(comSort.SelectedValue.ToString());
                        }
                        catch
                        {
                        }
                    }
                    if (txtCarton.Text != "")
                    {
                        if (double.TryParse(txtCarton.Text, out carton))
                        {
                        }
                        else
                        {
                            MessageBox.Show("carton must be numeric");
                            dbconnection.Close();
                            return;
                        }
                    }
                    classification = txtClassification.Text;
                    description    = txtDescription.Text;


                    dbconnection.Close();

                    MySqlCommand command = dbconnection.CreateCommand();

                    string code = txtType.Text;

                    int typecount = txtType.Text.Length;

                    int factorycount = txtFactory.Text.Length;

                    int groupcount = txtGroup.Text.Length;

                    int productcount = txtProduct.Text.Length;

                    while (typecount < 4)
                    {
                        code = "0" + code;
                        typecount++;
                    }

                    string code2 = txtFactory.Text;

                    while (factorycount < 4)
                    {
                        code2 = "0" + code2;
                        factorycount++;
                    }

                    code = code + code2;

                    string code3 = txtGroup.Text;

                    while (groupcount < 4)
                    {
                        code3 = "0" + code3;
                        groupcount++;
                    }

                    code = code + code3;

                    string code4 = txtProduct.Text;

                    while (productcount < 4)
                    {
                        code4 = "0" + code4;
                        productcount++;
                    }

                    code = code + code4;
                    string code5 = "";

                    if (!IsMainChang())
                    {
                        string query2 = "SELECT max(Code) FROM data where Type_ID=" + txtType.Text + " and Factory_ID=" + txtFactory.Text + " and Group_ID=" + txtGroup.Text + " and Product_ID=" + txtProduct.Text;
                        dbconnection.Open();
                        MySqlCommand adpt    = new MySqlCommand(query2, dbconnection);
                        string       maxCode = adpt.ExecuteScalar().ToString();
                        if (maxCode != "")
                        {
                            char[] arrCode = maxCode.ToCharArray();
                            string part5   = arrCode[16].ToString() + arrCode[17].ToString() + arrCode[18].ToString() + arrCode[19].ToString() + "";

                            int result = Convert.ToInt32(part5);
                            result = result + 1;
                            dbconnection.Close();

                            int resultcount = result.ToString().Length;

                            code5 = result.ToString();

                            while (resultcount < 4)
                            {
                                code5 = "0" + code5;
                                resultcount++;
                            }
                        }
                        else
                        {
                            code5 = "0001";
                        }
                    }
                    else
                    {
                        code5 = lastPartCode;
                    }
                    code = code + code5;

                    string query = "update  data set Color_ID=?Color_ID,Size_ID=?Size_ID,Sort_ID=?Sort_ID,Description=?Description,Carton=?Carton,Code=?Code,Type_ID=?Type_ID,Factory_ID=?Factory_ID,Group_ID=?Group_ID,Product_ID=?Product_ID,Classification=?Classification where Data_ID=" + Data_ID;
                    command = new MySqlCommand(query, dbconnection);
                    command.Parameters.AddWithValue("?Color_ID", color_id);
                    command.Parameters.AddWithValue("?Size_ID", size_id);
                    command.Parameters.AddWithValue("?Sort_ID", sort_id);
                    command.Parameters.AddWithValue("?Description", description);
                    command.Parameters.AddWithValue("?Carton", carton);
                    command.Parameters.AddWithValue("?Code", code);
                    command.Parameters.AddWithValue("?Type_ID", int.Parse(txtType.Text));
                    command.Parameters.AddWithValue("?Factory_ID", int.Parse(txtFactory.Text));
                    command.Parameters.AddWithValue("?Group_ID", int.Parse(txtGroup.Text));
                    command.Parameters.AddWithValue("?Product_ID", int.Parse(txtProduct.Text));
                    command.Parameters.AddWithValue("?Classification", classification);
                    dbconnection.Close();
                    dbconnection.Open();
                    command.ExecuteNonQuery();


                    //save image as bytes
                    query   = "select DataPhoto_ID from data_photo where  Data_ID=" + Data_ID;
                    command = new MySqlCommand(query, dbconnection);
                    try
                    {
                        string DataPhoto_ID = command.ExecuteScalar().ToString();
                        string q            = "update data_photo set Photo =?Photo where DataPhoto_ID=" + DataPhoto_ID;
                        command = new MySqlCommand(q, dbconnection);
                        command.Parameters.AddWithValue("?Photo", selectedImage);
                        command.ExecuteNonQuery();
                    }
                    catch
                    {
                        string q = "insert into  data_photo (Photo,Data_ID) values (@Photo,@Data_ID)";
                        command = new MySqlCommand(q, dbconnection);
                        command.Parameters.AddWithValue("?Photo", selectedImage);
                        command.Parameters.AddWithValue("?Data_ID", Data_ID);
                        dbconnection.Close();
                        dbconnection.Open();
                        command.ExecuteNonQuery();
                    }
                    UserControl.ItemRecord("data", "تعديل", Data_ID, DateTime.Now, "", dbconnection);
                    dbconnection.Close();
                    MessageBox.Show("updated");
                    products.displayProducts();

                    XtraTabPage xtraTabPage = getTabPage("تعديل بند");
                    xtraTabPage.ImageOptions.Image = null;
                    comType.Focus();
                }
                else
                {
                    MessageBox.Show("you should fill all fields");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
Beispiel #23
0
        public void saveData()
        {
            if (txtFactory.Text != "" && txtGroup.Text != "" && txtProduct.Text != "" && txtType.Text != "")
            {
                int    color_id = 0;
                int    size_id = 0;
                int    sort_id = 0;
                double carton = 0;
                string classification, description = "";
                if (comColour.Text != "")
                {
                    color_id = Convert.ToInt32(txtColor.Text);
                }
                if (comSize.Text != "")
                {
                    size_id = Convert.ToInt32(txtSize.Text);
                }
                if (comSort.Text != "")
                {
                    sort_id = Convert.ToInt32(txtSort.Text);
                }
                if (txtCarton.Text != "")
                {
                    if (double.TryParse(txtCarton.Text, out carton))
                    {
                    }
                    else
                    {
                        MessageBox.Show("carton must be numeric");
                        return;
                    }
                }
                classification = txtClassification.Text;
                description    = txtDescription.Text;

                string       q      = "SELECT Data_ID from data where Color_ID=" + color_id + " and Size_ID=" + size_id + " and Sort_ID=" + sort_id + " and Description='" + description + "' and Carton=" + carton + " and Type_ID=" + txtType.Text + " and Factory_ID=" + txtFactory.Text + " and Group_ID=" + txtGroup.Text + " and Product_ID=" + txtProduct.Text + " and Classification='" + classification + "'";
                MySqlCommand comand = new MySqlCommand(q, conn);
                conn.Close();
                conn.Open();
                var resultValue = comand.ExecuteReader();
                if (!resultValue.HasRows)
                {
                    conn.Close();

                    MySqlCommand command = conn.CreateCommand();

                    string code = txtType.Text;

                    int typecount = txtType.Text.Length;

                    int factorycount = txtFactory.Text.Length;

                    int groupcount = txtGroup.Text.Length;

                    int productcount = txtProduct.Text.Length;

                    while (typecount < 4)
                    {
                        code = "0" + code;
                        typecount++;
                    }

                    string code2 = txtFactory.Text;

                    while (factorycount < 4)
                    {
                        code2 = "0" + code2;
                        factorycount++;
                    }

                    code = code + code2;

                    string code3 = txtGroup.Text;

                    while (groupcount < 4)
                    {
                        code3 = "0" + code3;
                        groupcount++;
                    }

                    code = code + code3;

                    string code4 = txtProduct.Text;

                    while (productcount < 4)
                    {
                        code4 = "0" + code4;
                        productcount++;
                    }

                    code = code + code4;

                    string query2 = "SELECT IFNULL(max(Code),1) FROM data where Type_ID=" + txtType.Text + " and Factory_ID=" + txtFactory.Text + " and Group_ID=" + txtGroup.Text + " and Product_ID=" + txtProduct.Text;
                    conn.Open();
                    MySqlCommand adpt    = new MySqlCommand(query2, conn);
                    string       maxCode = adpt.ExecuteScalar().ToString();
                    char []      arrCode = maxCode.ToCharArray();
                    int          result  = 1;
                    if (maxCode != "1")
                    {
                        string part5 = arrCode[16].ToString() + arrCode[17].ToString() + arrCode[18].ToString() + arrCode[19].ToString() + "";
                        result = Convert.ToInt32(part5);
                        result = result + 1;
                    }

                    conn.Close();

                    int resultcount = result.ToString().Length;

                    string code5 = result.ToString();

                    while (resultcount < 4)
                    {
                        code5 = "0" + code5;
                        resultcount++;
                    }

                    code = code + code5;

                    command.CommandText = "INSERT INTO data (Color_ID,Size_ID,Sort_ID,Description,Carton,Code,Type_ID,Factory_ID,Group_ID,Product_ID,Classification,Data_Date) VALUES (?Color_ID,?Size_ID,?Sort_ID,?Description,?Carton,?Code,?Type_ID,?Factory_ID,?Group_ID,?Product_ID,?Classification,?Data_Date)";

                    command.Parameters.AddWithValue("?Color_ID", color_id);
                    command.Parameters.AddWithValue("?Size_ID", size_id);
                    command.Parameters.AddWithValue("?Sort_ID", sort_id);
                    command.Parameters.AddWithValue("?Description", description);
                    command.Parameters.AddWithValue("?Carton", carton);
                    command.Parameters.AddWithValue("?Code", code);
                    command.Parameters.AddWithValue("?Type_ID", int.Parse(txtType.Text));
                    command.Parameters.AddWithValue("?Factory_ID", int.Parse(txtFactory.Text));
                    command.Parameters.AddWithValue("?Group_ID", int.Parse(txtGroup.Text));
                    command.Parameters.AddWithValue("?Product_ID", int.Parse(txtProduct.Text));
                    command.Parameters.AddWithValue("?Classification", classification);
                    command.Parameters.AddWithValue("?Data_Date", DateTime.Now.Date);
                    conn.Open();
                    command.ExecuteNonQuery();

                    query2 = "select Data_ID from data order by Data_ID desc limit 1";
                    comand = new MySqlCommand(query2, conn);
                    int data_ID = Convert.ToInt32(comand.ExecuteScalar());
                    //save image as bytes
                    command = conn.CreateCommand();
                    if (selectedImage != null)
                    {
                        command.CommandText = "INSERT INTO data_photo (Data_ID,Photo) VALUES (?Data_ID,?Photo)";
                        command.Parameters.AddWithValue("?Data_ID", data_ID);
                        command.Parameters.AddWithValue("?Photo", selectedImage);
                        command.ExecuteNonQuery();
                    }
                    if (products != null)
                    {
                        products.displayProducts();
                    }
                    UserControl.ItemRecord("data", "اضافة", data_ID, DateTime.Now, "", conn);
                    clear();
                    comType.Focus();
                }
                else
                {
                    MessageBox.Show("This item already exist");
                }
            }
            else
            {
                MessageBox.Show("you should fill all fields");
            }
        }
        private void btnCreateReturnBill_Click(object sender, EventArgs e)
        {
            try
            {
                dbconnection.Close();
                dbconnection.Open();
                if (dataGridView2.RowCount > 0 && txtReturnPermission.Text != "")
                {
                    int billNum = Convert.ToInt32(txtReturnPermission.Text);

                    string       query = "";
                    MySqlCommand com;
                    query = "select Store_Permission_Number from customer_return_bill where Store_Permission_Number=" + billNum;
                    com   = new MySqlCommand(query, dbconnection);
                    if (com.ExecuteScalar() != null)
                    {
                        MessageBox.Show("اذن المرتجع تم تسجيله من قبل");
                        dbconnection.Close();
                        return;
                    }
                    query = "select Branch_BillNumber from customer_return_bill where Branch_ID=" + BaseData.BranchID + " order by CustomerReturnBill_ID desc limit 1";
                    com   = new MySqlCommand(query, dbconnection);
                    int Branch_BillNumber = 1;
                    if (com.ExecuteScalar() != null)
                    {
                        Branch_BillNumber = Convert.ToInt32(com.ExecuteScalar()) + 1;
                    }
                    query = "insert into customer_return_bill (Customer_ID,Client_ID,Customer_Name,Client_Name, Branch_ID,Branch_BillNumber,Store_Permission_Number,Date,TotalCostAD,ReturnInfo,Type_Buy,Employee_ID,Employee_Name,Branch_Name) values (@Customer_ID,@Client_ID,@Customer_Name,@Client_Name,@Branch_ID,@Branch_BillNumber,@Store_Permission_Number,@Date,@TotalCostAD,@ReturnInfo,@Type_Buy,@Employee_ID,@Employee_Name,@Branch_Name) ";
                    com   = new MySqlCommand(query, dbconnection);

                    com.Parameters.Add("@Branch_BillNumber", MySqlDbType.Int16);
                    com.Parameters["@Branch_BillNumber"].Value = Branch_BillNumber;
                    com.Parameters.Add("@Branch_ID", MySqlDbType.Int16);
                    com.Parameters["@Branch_ID"].Value = Branch_ID;
                    com.Parameters.Add("@Branch_Name", MySqlDbType.VarChar);
                    com.Parameters["@Branch_Name"].Value = labBranchName.Text;
                    int storeNum = 0;
                    if (int.TryParse(txtReturnPermission.Text, out storeNum))
                    {
                        com.Parameters.Add("@Store_Permission_Number", MySqlDbType.Int16);
                        com.Parameters["@Store_Permission_Number"].Value = storeNum;
                    }
                    else
                    {
                        MessageBox.Show("اذن المخزن يجب ان يكون عدد");
                        dbconnection.Close();
                        return;
                    }

                    string          q    = "select customer_return_permission.Customer_ID,c1.Customer_Name,Client_ID,c2.Customer_Name from customer_return_permission left join customer as c1 on c1.Customer_ID=customer_return_permission.Customer_ID left join customer as c2 on c2.Customer_ID=customer_return_permission.Client_ID where CustomerReturnPermission_ID=" + storeNum;
                    MySqlCommand    c    = new MySqlCommand(q, dbconnection);
                    MySqlDataReader dr   = c.ExecuteReader();
                    bool            flag = false;
                    while (dr.Read())
                    {
                        if (dr[0].ToString() != "")
                        {
                            com.Parameters.Add("@Customer_ID", MySqlDbType.Int16);
                            com.Parameters["@Customer_ID"].Value = Convert.ToInt32(dr[0].ToString());
                            com.Parameters.Add("@Customer_Name", MySqlDbType.VarChar);
                            com.Parameters["@Customer_Name"].Value = dr[1].ToString();
                            flag = true;
                        }
                        else
                        {
                            com.Parameters.Add("@Customer_ID", MySqlDbType.Int16);
                            com.Parameters["@Customer_ID"].Value = null;
                            com.Parameters.Add("@Customer_Name", MySqlDbType.VarChar);
                            com.Parameters["@Customer_Name"].Value = "";
                        }
                        if (dr[2].ToString() != "")
                        {
                            com.Parameters.Add("@Client_ID", MySqlDbType.Int16);
                            com.Parameters["@Client_ID"].Value = Convert.ToInt32(dr[2].ToString());
                            com.Parameters.Add("@Client_Name", MySqlDbType.VarChar);
                            com.Parameters["@Client_Name"].Value = dr[3].ToString();
                            flag = true;
                        }
                        else
                        {
                            com.Parameters.Add("@Client_ID", MySqlDbType.Int16);
                            com.Parameters["@Client_ID"].Value = null;
                            com.Parameters.Add("@Client_Name", MySqlDbType.VarChar);
                            com.Parameters["@Client_Name"].Value = "";
                        }
                    }
                    dr.Close();

                    dbconnection.Close();
                    dbconnection.Open();
                    if (!flag)
                    {
                        q  = "select customer_bill.Customer_ID,c1.Customer_Name,Client_ID,c2.Customer_Name  from customer_bill left join customer as c1 on c1.Customer_ID=customer_bill.Customer_ID left join customer as c2 on c2.Customer_ID=customer_bill.Client_ID where Branch_BillNumber=" + labBillNumber.Text + " and Branch_ID=" + Branch_ID;
                        c  = new MySqlCommand(q, dbconnection);
                        dr = c.ExecuteReader();
                        while (dr.Read())
                        {
                            if (dr[0].ToString() != "")
                            {
                                com.Parameters["@Customer_ID"].Value = Convert.ToInt32(dr[0].ToString());

                                com.Parameters["@Customer_Name"].Value = dr[1].ToString();
                            }
                            else
                            {
                                com.Parameters["@Customer_ID"].Value   = null;
                                com.Parameters["@Customer_Name"].Value = "";
                            }
                            if (dr[2].ToString() != "")
                            {
                                com.Parameters["@Client_ID"].Value = Convert.ToInt32(dr[2].ToString());

                                com.Parameters["@Client_Name"].Value = dr[3].ToString();
                            }
                            else
                            {
                                com.Parameters["@Client_ID"].Value   = null;
                                com.Parameters["@Client_Name"].Value = "";
                            }
                        }
                        dr.Close();
                    }
                    com.Parameters.Add("@Date", MySqlDbType.DateTime);
                    com.Parameters["@Date"].Value = DateTime.Now;
                    com.Parameters.Add("@ReturnInfo", MySqlDbType.VarChar);
                    com.Parameters["@ReturnInfo"].Value = txtInfo.Text;
                    com.Parameters.Add("@TotalCostAD", MySqlDbType.Decimal);
                    com.Parameters["@TotalCostAD"].Value = Convert.ToDouble(txtBillTotalCostAD.Text);
                    com.Parameters.Add("@Type_Buy", MySqlDbType.VarChar);
                    com.Parameters["@Type_Buy"].Value = type;
                    com.Parameters.Add("@Employee_ID", MySqlDbType.Int16);
                    com.Parameters["@Employee_ID"].Value = UserControl.EmpID;
                    com.Parameters.Add("@Employee_Name", MySqlDbType.VarChar);
                    com.Parameters["@Employee_Name"].Value = UserControl.EmpName;
                    com.ExecuteNonQuery();

                    query = "select CustomerReturnBill_ID from customer_return_bill order by CustomerReturnBill_ID desc limit 1";
                    com   = new MySqlCommand(query, dbconnection);
                    MySqlDataReader dr1 = com.ExecuteReader();
                    int             id  = 0;
                    while (dr1.Read())
                    {
                        id = Convert.ToInt32(dr1[0].ToString());
                    }
                    dr1.Close();


                    query = " insert into customer_return_bill_details (CustomerReturnBill_ID,Data_ID,Type,TotalMeter,PriceBD,PriceAD,TotalAD,SellDiscount,CustomerBill_ID,Delegate_ID,Store_ID)values (@CustomerReturnBill_ID,@Data_ID,@Type,@TotalMeter,@PriceBD,@PriceAD,@TotalAD,@SellDiscount,@CustomerBill_ID,@Delegate_ID,@Store_ID) ";
                    com   = new MySqlCommand(query, dbconnection);
                    com.Parameters.Add("@CustomerReturnBill_ID", MySqlDbType.Int16);
                    com.Parameters.Add("@Data_ID", MySqlDbType.Int16);
                    com.Parameters.Add("@Type", MySqlDbType.VarChar);
                    com.Parameters.Add("@TotalMeter", MySqlDbType.Decimal);
                    com.Parameters.Add("@PriceBD", MySqlDbType.Decimal);
                    com.Parameters.Add("@PriceAD", MySqlDbType.Decimal);
                    com.Parameters.Add("@TotalAD", MySqlDbType.Decimal);
                    com.Parameters.Add("@SellDiscount", MySqlDbType.Decimal);
                    com.Parameters.Add("@CustomerBill_ID", MySqlDbType.Int16);
                    com.Parameters.Add("@Delegate_ID", MySqlDbType.Int16);
                    com.Parameters.Add("@Store_ID", MySqlDbType.Int16);
                    foreach (DataGridViewRow row2 in dataGridView2.Rows)
                    {
                        if (row2.Cells[0].Value != null)
                        {
                            com.Parameters["@CustomerReturnBill_ID"].Value = id;
                            com.Parameters["@Data_ID"].Value    = Convert.ToInt32(row2.Cells[0].Value);
                            com.Parameters["@Type"].Value       = row2.Cells[11].Value;
                            com.Parameters["@TotalMeter"].Value = Convert.ToDouble(row2.Cells["Quantity"].Value);
                            com.Parameters["@priceBD"].Value    = Convert.ToDouble(row2.Cells["priceBD"].Value);
                            com.Parameters["@PriceAD"].Value    = Convert.ToDouble(row2.Cells["priceAD"].Value);
                            com.Parameters["@TotalAD"].Value    = Convert.ToDouble(row2.Cells["totalAD"].Value);
                            if (row2.Cells[11].Value.ToString() != "عرض")
                            {
                                com.Parameters["@SellDiscount"].Value = Convert.ToDouble(row2.Cells["Discount"].Value);
                            }
                            else
                            {
                                com.Parameters["@SellDiscount"].Value = 0;
                            }
                            if (row2.Cells["CustomerBill_ID"].Value != null && row2.Cells["Delegate_ID"].Value != null)
                            {
                                com.Parameters["@CustomerBill_ID"].Value = Convert.ToInt32(row2.Cells["CustomerBill_ID"].Value);
                                com.Parameters["@Delegate_ID"].Value     = Convert.ToInt32(row2.Cells["Delegate_ID"].Value);
                            }
                            else
                            {
                                com.Parameters["@CustomerBill_ID"].Value = 0;
                                com.Parameters["@Delegate_ID"].Value     = Convert.ToInt32(txtDelegate.Text);
                            }
                            com.Parameters["@Store_ID"].Value = Convert.ToInt32(row2.Cells[12].Value);
                            com.ExecuteNonQuery();
                        }
                    }

                    MessageBox.Show("فاتورة مرتجع رقم " + Branch_BillNumber);
                    UserControl.ItemRecord("customer_return_bill", "اضافة", id, DateTime.Now, "", dbconnection);
                    clear();
                }
                else
                {
                    MessageBox.Show("تاكد من البيانات");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
Beispiel #25
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (Customer_Type == "عميل" && flag)
                {
                    if (comEnginner.Text != "")
                    {
                    }
                    else
                    {
                        MessageBox.Show("يجب اختيار الضامن");
                        dbconnection.Close();
                        return;
                    }
                }
                Form prompt = new Form()
                {
                    Width           = 500,
                    Height          = 220,
                    FormBorderStyle = FormBorderStyle.FixedDialog,
                    Text            = "",
                    StartPosition   = FormStartPosition.CenterScreen,
                    MaximizeBox     = false,
                    MinimizeBox     = false
                };
                Label textLabel = new Label()
                {
                    Left = 340, Top = 20, Text = "ما هو سبب التعديل؟"
                };
                TextBox textBox = new TextBox()
                {
                    Left = 50, Top = 50, Width = 385, Multiline = true, Height = 80, RightToLeft = RightToLeft
                };
                Button confirmation = new Button()
                {
                    Text = "تأكيد", Left = 200, Width = 100, Top = 140, DialogResult = DialogResult.OK
                };
                prompt.Controls.Add(textBox);
                prompt.Controls.Add(confirmation);
                prompt.Controls.Add(textLabel);
                prompt.AcceptButton = confirmation;
                if (prompt.ShowDialog() == DialogResult.OK)
                {
                    if (textBox.Text != "")
                    {
                        if (txtName.Text != "" && checkedListBoxControlPhone.ItemCount > 0 && (radioAgel.Checked || radioKash.Checked))
                        {
                            dbconnection.Open();
                            if (checkNameExist())
                            {
                                string       query = "update customer set Customer_Name=@Customer_Name,Customer_NationalID=@Customer_NationalID,Customer_Email=@Customer_Email,Customer_Address=@Customer_Address,Customer_Info=@Customer_Info,Customer_Type=@Customer_Type,Type=@Type,Customer_OpenAccount=@Customer_OpenAccount where Customer_ID=" + selRow[0].ToString();
                                MySqlCommand com   = new MySqlCommand(query, dbconnection);
                                com.Parameters.Add("@Customer_Name", MySqlDbType.VarChar, 255);
                                com.Parameters["@Customer_Name"].Value = txtName.Text;
                                com.Parameters.Add("@Customer_Address", MySqlDbType.VarChar, 255);
                                com.Parameters["@Customer_Address"].Value = txtAddress.Text;
                                com.Parameters.Add("@Customer_OpenAccount", MySqlDbType.Decimal);
                                double re = 0;
                                if (Double.TryParse(txtOpenAccount.Text, out re))
                                {
                                    com.Parameters["@Customer_OpenAccount"].Value = re;
                                }
                                else
                                {
                                    com.Parameters["@Customer_OpenAccount"].Value = 0;
                                }
                                com.Parameters.Add("@Customer_Email", MySqlDbType.VarChar, 255);
                                com.Parameters["@Customer_Email"].Value = txtEmail.Text;
                                if (txtNationalID.Text != "")
                                {
                                    com.Parameters.Add("@Customer_NationalID", MySqlDbType.VarChar, 255);
                                    com.Parameters["@Customer_NationalID"].Value = txtNationalID.Text;
                                }
                                else
                                {
                                    com.Parameters.Add("@Customer_NationalID", MySqlDbType.VarChar, 255);
                                    com.Parameters["@Customer_NationalID"].Value = null;
                                }
                                com.Parameters.Add("@Customer_Info", MySqlDbType.VarChar, 255);
                                com.Parameters["@Customer_Info"].Value = txtINF.Text;
                                if (Customer_Type != "")
                                {
                                    com.Parameters.Add("@Customer_Type", MySqlDbType.VarChar, 255);
                                    com.Parameters["@Customer_Type"].Value = Customer_Type;
                                }
                                else
                                {
                                    MessageBox.Show("برجاء اختيار النوع");
                                    dbconnection.Close();
                                    return;
                                }

                                com.Parameters.Add("@Type", MySqlDbType.VarChar, 255);
                                com.Parameters["@Type"].Value = Type;

                                com.ExecuteNonQuery();
                                if (Customer_Type == "عميل" && flag)
                                {
                                    AddClientToEng_Con();
                                }

                                UserControl.ItemRecord("customer", "تعديل", Convert.ToInt32(selRow[0].ToString()), DateTime.Now, textBox.Text, dbconnection);

                                //MessageBox.Show("تم");
                                //clear();
                                // xtraTabPage.ImageOptions.Image = null;
                                //MainForm.objFormCustomer.search();
                                mainTabControl.TabPages.Remove(MainForm.MainTabPageUpdateCustomer);
                                mainTabControl.TabPages.Remove(MainForm.MainTabPageUpdateCustomer2);
                            }
                            else
                            {
                                MessageBox.Show("هذا الاسم موجود من قبل");
                            }
                        }
                        else
                        {
                            MessageBox.Show("برجاء ادخال البيانات كاملة");
                        }
                    }
                    else
                    {
                        MessageBox.Show("يجب كتابة السبب");
                    }
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
        void delete(GridView view)
        {
            int[] selRows = ((GridView)gridControl1.MainView).GetSelectedRows();
            // && gridView1.GetRowCellDisplayText(gridView1.GetSelectedRows()[0], "Error") == "0"
            if (selRows.Length > 0)
            {
                if (MessageBox.Show("هل انت متاكد انك تريد الحذف؟", "تحذير", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                {
                    return;
                }

                Form prompt = new Form()
                {
                    Width           = 500,
                    Height          = 220,
                    FormBorderStyle = FormBorderStyle.FixedDialog,
                    Text            = "",
                    StartPosition   = FormStartPosition.CenterScreen,
                    MaximizeBox     = false,
                    MinimizeBox     = false
                };
                Label textLabel = new Label()
                {
                    Left = 340, Top = 20, Text = "ما هو سبب الحذف؟"
                };
                TextBox textBox = new TextBox()
                {
                    Left = 50, Top = 50, Width = 385, Multiline = true, Height = 80, RightToLeft = RightToLeft
                };
                Button confirmation = new Button()
                {
                    Text = "تأكيد", Left = 200, Width = 100, Top = 140, DialogResult = DialogResult.OK
                };
                prompt.Controls.Add(textBox);
                prompt.Controls.Add(confirmation);
                prompt.Controls.Add(textLabel);
                prompt.AcceptButton = confirmation;
                if (prompt.ShowDialog() == DialogResult.OK)
                {
                    if (textBox.Text != "")
                    {
                        conn.Open();
                        for (int i = 0; i < selRows.Length; i++)
                        {
                            DataRowView selRow = (DataRowView)(((GridView)gridControl1.MainView).GetRow(selRows[i]));

                            string       query  = "delete from dash_details where DashDetails_ID=" + selRow[0].ToString();
                            MySqlCommand comand = new MySqlCommand(query, conn);
                            comand.ExecuteNonQuery();
                            main.test(/*delegateID,*/ billNum);

                            UserControl.ItemRecord("dash_details", "حذف", Convert.ToInt32(selRow[0].ToString()), DateTime.Now, textBox.Text, conn);
                        }
                        conn.Close();
                        search();
                    }
                    else
                    {
                        MessageBox.Show("يجب كتابة السبب");
                    }
                }
                else
                {
                }
            }
            else
            {
                MessageBox.Show("تاكد من اختيارك");
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtQuantity.Text != "")
            {
                double quantity = 0;
                if (double.TryParse(txtQuantity.Text, out quantity))
                {
                    try
                    {
                        dbconnection.Open();
                        string       query = "select Total_Meters from storage where Store_ID=" + storeID + " and Data_ID=" + selRow["Data_ID"].ToString();
                        MySqlCommand com   = new MySqlCommand(query, dbconnection);
                        if (com.ExecuteScalar() != null)
                        {
                            double totalf = Convert.ToInt32(com.ExecuteScalar());
                            totalf = (totalf + rowQuantity);

                            if ((totalf - quantity) >= 0)
                            {
                                query = "update storage set Total_Meters=" + (totalf - quantity) + " where Store_ID=" + storeID + " and Data_ID=" + selRow["Data_ID"].ToString();
                                com   = new MySqlCommand(query, dbconnection);
                                com.ExecuteNonQuery();

                                UserControl.ItemRecord("storage", "تعديل", Convert.ToInt16(selRow["Data_ID"]), DateTime.Now, "تعديل مرتجع اذن مخزن", dbconnection);

                                query = "update import_storage_return_details set Total_Meters=" + quantity + " where ImportStorageReturnDetails_ID=" + selRow["ImportStorageReturnDetails_ID"].ToString();
                                com   = new MySqlCommand(query, dbconnection);
                                com.ExecuteNonQuery();

                                dbconnection.Close();
                                if (storageReturnBillUpdate == null)
                                {
                                    permissionReturnedReport.refreshView(rowHandel, Convert.ToDouble(txtQuantity.Text));
                                }
                                else /*if (formName == "StorageReturnBill_Update")*/
                                {
                                    storageReturnBillUpdate.refreshView(rowHandel, Convert.ToDouble(txtQuantity.Text));

                                    permissionReturnedReport.refreshView(rowHandel, Convert.ToDouble(txtQuantity.Text));
                                }
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("لا يوجد كمية كافية");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    dbconnection.Close();
                }
                else
                {
                    MessageBox.Show("الكمية يجب ان تكون عدد");
                }
            }
            else
            {
                MessageBox.Show("يجب ادخال الكمية");
            }
        }
Beispiel #28
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtQuantity.Text != "" && comStore.Text != "")
                {
                    double quantity = 0;
                    if (double.TryParse(txtQuantity.Text, out quantity))
                    {
                        conn.Open();
                        if (!checkQuantityInStore(quantity))
                        {
                            MessageBox.Show("لا يوجد كمية كافية من العنصر فى المخزن");
                            conn.Close();
                            return;
                        }

                        cartons = 0;
                        if (selRow["الكود"].ToString().Length >= 20)
                        {
                            string       q = "select Carton from data where Code='" + selRow["الكود"].ToString() + "'";
                            MySqlCommand c = new MySqlCommand(q, conn);
                            if (c.ExecuteScalar() != null)
                            {
                                if (Convert.ToDouble(c.ExecuteScalar().ToString()) > 0)
                                {
                                    if (cartonNumCheck())
                                    {
                                    }

                                    /*else
                                     * {
                                     *  conn.Close();
                                     *  return;
                                     * }*/
                                }
                            }
                        }

                        /*Form prompt = new Form()
                         * {
                         *  Width = 500,
                         *  Height = 220,
                         *  FormBorderStyle = FormBorderStyle.FixedDialog,
                         *  Text = "",
                         *  StartPosition = FormStartPosition.CenterScreen,
                         *  MaximizeBox = false,
                         *  MinimizeBox = false
                         * };
                         * Label textLabel = new Label() { Left = 340, Top = 20, Text = "ما هو سبب التعديل؟" };
                         * TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 385, Multiline = true, Height = 80, RightToLeft = RightToLeft };
                         * Button confirmation = new Button() { Text = "تأكيد", Left = 200, Width = 100, Top = 140, DialogResult = DialogResult.OK };
                         * prompt.Controls.Add(textBox);
                         * prompt.Controls.Add(confirmation);
                         * prompt.Controls.Add(textLabel);
                         * prompt.AcceptButton = confirmation;
                         * if (prompt.ShowDialog() == DialogResult.OK)
                         * {
                         *  if (textBox.Text != "")
                         *  {
                         *      /*string query = "select sum(storage.Total_Meters) from storage where storage.Code='" + selRow["الكود"].ToString() + "' group by storage.Code";
                         *      MySqlCommand comand = new MySqlCommand(query, conn);
                         *      double TotalMeters = Convert.ToDouble(comand.ExecuteScalar());*/

                        //quantity <= TotalMeters

                        string       query  = "update dash_details set Quantity=" + quantity + ",Cartons=" + cartons + ", Store_ID=" + comStore.SelectedValue.ToString() + " , Store_Name='" + comStore.Text + "' where DashDetails_ID=" + Convert.ToInt32(selRow[0].ToString());
                        MySqlCommand comand = new MySqlCommand(query, conn);
                        comand.ExecuteNonQuery();

                        UserControl.ItemRecord("dash_details", "تعديل", Convert.ToInt32(selRow[0].ToString()), DateTime.Now, "", conn);

                        conn.Close();
                        MainForm.ProductsDetailsReport.loadFunc();
                        this.Close();

                        //    }
                        //    else
                        //    {
                        //        MessageBox.Show("يجب كتابة السبب");
                        //    }
                        //}
                    }
                    else
                    {
                        MessageBox.Show("الكمية يجب ان تكون عدد");
                    }
                }
                else
                {
                    MessageBox.Show("يجب ادخال البيانات كاملة");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            conn.Close();
        }
Beispiel #29
0
        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            try
            {
                if (dataGridView2.Rows.Count > 0)
                {
                    if (txtSetName.Text != "")
                    {
                        string       query  = "select Set_Name from sets where Set_Name='" + txtSetName.Text + "'";
                        MySqlCommand comand = new MySqlCommand(query, dbconnection);
                        dbconnection.Open();
                        MySqlDataReader dr = comand.ExecuteReader();
                        while (dr.Read())
                        {
                            if (dr["Set_Name"].ToString() == txtSetName.Text)
                            {
                                MessageBox.Show("this set already exist");
                                dr.Close();
                                dbconnection.Close();
                                return;
                            }
                        }
                        dr.Close();

                        if (selectedImage == null)
                        {
                            query  = "INSERT INTO sets (Set_Name,Factory_ID,Type_ID) VALUES (@Set_Name,@Factory_ID,@Type_ID)";
                            comand = new MySqlCommand(query, dbconnection);
                            comand.Parameters.AddWithValue("@Set_Name", txtSetName.Text);
                            string       q   = "select Type_ID from type where Type_Name='" + dataGridView2.Rows[0].Cells[3].Value.ToString() + "'";
                            MySqlCommand com = new MySqlCommand(q, dbconnection);
                            comand.Parameters.Add("@Type_ID", MySqlDbType.Int16);
                            comand.Parameters["@Type_ID"].Value = com.ExecuteScalar();

                            q   = "select Factory_ID from factory where Factory_Name='" + dataGridView2.Rows[0].Cells[4].Value.ToString() + "'";
                            com = new MySqlCommand(q, dbconnection);
                            comand.Parameters.Add("@Factory_ID", MySqlDbType.Int16);
                            comand.Parameters["@Factory_ID"].Value = com.ExecuteScalar();

                            //q = "select Group_ID from groupo where Group_Name='" + dataGridView2.Rows[0].Cells[5].Value.ToString() + "'";
                            //com = new MySqlCommand(q, dbconnection);
                            //comand.Parameters.Add("@Group_ID", MySqlDbType.Int16);
                            //comand.Parameters["@Group_ID"].Value = com.ExecuteScalar();
                            comand.ExecuteNonQuery();
                        }
                        else
                        {
                            query  = "INSERT INTO sets (Set_Name,Set_Photo,Factory_ID,Type_ID) VALUES (@Set_Name,@Set_Photo,@Factory_ID,@Type_ID)";
                            comand = new MySqlCommand(query, dbconnection);

                            comand.Parameters.AddWithValue("@Set_Name", txtSetName.Text);
                            comand.Parameters.Add("@Set_Photo", MySqlDbType.LongBlob);
                            comand.Parameters["@Set_Photo"].Value = selectedImage;

                            string       q   = "select Type_ID from type where Type_Name='" + dataGridView2.Rows[0].Cells[3].Value.ToString() + "'";
                            MySqlCommand com = new MySqlCommand(q, dbconnection);
                            comand.Parameters.Add("@Type_ID", MySqlDbType.Int16);
                            comand.Parameters["@Type_ID"].Value = com.ExecuteScalar();

                            q   = "select Factory_ID from factory where Factory_Name='" + dataGridView2.Rows[0].Cells[4].Value.ToString() + "'";
                            com = new MySqlCommand(q, dbconnection);
                            comand.Parameters.Add("@Factory_ID", MySqlDbType.Int16);
                            comand.Parameters["@Factory_ID"].Value = com.ExecuteScalar();

                            //q = "select Group_ID from groupo where Group_Name='" + dataGridView2.Rows[0].Cells[5].Value.ToString()+"'";
                            //com = new MySqlCommand(q, dbconnection);
                            //comand.Parameters.Add("@Group_ID", MySqlDbType.Int16);
                            //comand.Parameters["@Group_ID"].Value = com.ExecuteScalar();


                            comand.ExecuteNonQuery();
                        }

                        query  = "select Set_ID from sets order by Set_ID desc limit 1";
                        comand = new MySqlCommand(query, dbconnection);
                        int set_id = Convert.ToInt32(comand.ExecuteScalar().ToString());

                        foreach (DataGridViewRow item in dataGridView2.Rows)
                        {
                            query  = "INSERT INTO set_Details (Set_ID,Data_ID,Quantity) VALUES (@Set_ID,@Data_ID,@Quantity)";
                            comand = new MySqlCommand(query, dbconnection);
                            comand.Parameters.AddWithValue("@Set_ID", set_id);
                            comand.Parameters.AddWithValue("@Data_ID", item.Cells[0].Value);
                            comand.Parameters.AddWithValue("@Quantity", double.Parse(item.Cells[2].Value.ToString()));
                            comand.ExecuteNonQuery();
                        }

                        query  = "INSERT INTO set_photo (Set_ID,Photo) VALUES (@Set_ID,@Photo)";
                        comand = new MySqlCommand(query, dbconnection);
                        comand.Parameters.AddWithValue("@Set_ID", set_id);
                        comand.Parameters.Add("@Photo", MySqlDbType.LongBlob);
                        comand.Parameters["@Photo"].Value = selectedImage;
                        comand.ExecuteNonQuery();

                        UserControl.ItemRecord("sets", "add", Convert.ToInt32(set_id.ToString()), DateTime.Now, "", dbconnection);

                        MessageBox.Show("Done");
                        clear();
                        ataqm.DisplayAtaqm();
                    }
                    else
                    {
                        MessageBox.Show("Please fill all fields with right format");
                    }
                }
                else
                {
                    MessageBox.Show("Please insert at least one item");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (comFromStore.Text != "" && comToStore.Text != "" && comFromStore.SelectedValue != null && comToStore.SelectedValue != null)
                {
                    if (row1 == null)
                    {
                        MessageBox.Show("يجب اختيار بند");
                        return;
                    }

                    if (IsItemAdded())
                    {
                        MessageBox.Show("هذا العنصر تم اضافتة من قبل");
                        return;
                    }

                    if (txtQuantity.Text != "")
                    {
                        double neededQuantity = 0;
                        if (!double.TryParse(txtQuantity.Text, out neededQuantity))
                        {
                            MessageBox.Show("الكمية يجب ان تكون عدد");
                            return;
                        }

                        dbconnection.Open();
                        double quantity = 0;
                        if (row1["الكمية"].ToString() != "")
                        {
                            quantity = Convert.ToDouble(row1["الكمية"].ToString());
                        }

                        if (neededQuantity <= quantity)
                        {
                            string       query = "insert into transfer_product_details (Data_ID,Quantity,TransferProduct_ID,CustomerBill_ID) values (@Data_ID,@Quantity,@TransferProduct_ID,@CustomerBill_ID)";
                            MySqlCommand com   = new MySqlCommand(query, dbconnection);
                            com.Parameters.Add("@Data_ID", MySqlDbType.Int16);
                            com.Parameters["@Data_ID"].Value = row1["Data_ID"].ToString();
                            com.Parameters.Add("@Quantity", MySqlDbType.Decimal);
                            com.Parameters["@Quantity"].Value = neededQuantity;
                            com.Parameters.Add("@TransferProduct_ID", MySqlDbType.Int16);
                            com.Parameters["@TransferProduct_ID"].Value = selRow["رقم التحويل"].ToString();
                            com.Parameters.Add("@CustomerBill_ID", MySqlDbType.Int16);
                            com.Parameters["@CustomerBill_ID"].Value = CustomerBillID;
                            com.ExecuteNonQuery();

                            if (txtBillNum.Text == "")
                            {
                                //query = "select sum(Total_Meters) from storage where Data_ID=" + row1[0].ToString() + " and Store_ID=" + comFromStore.SelectedValue.ToString() + " group by Data_ID";
                                //com = new MySqlCommand(query, dbconnection);
                                //double quantity = Convert.ToDouble(com.ExecuteScalar().ToString());
                                double meters = quantity - neededQuantity;
                                query = "update storage set Total_Meters=" + meters + " where Data_ID=" + row1[0].ToString() + " and Store_ID=" + comFromStore.SelectedValue.ToString();
                                com   = new MySqlCommand(query, dbconnection);
                                com.ExecuteNonQuery();

                                query = "select OpenStorageAccount_ID from open_storage_account where Data_ID=" + row1["Data_ID"].ToString() + " and Store_ID=" + comToStore.SelectedValue.ToString();
                                com   = new MySqlCommand(query, dbconnection);
                                if (com.ExecuteScalar() == null)
                                {
                                    query = "insert into open_storage_account (Data_ID,Quantity,Store_ID,Store_Place_ID,Date,Note) values (@Data_ID,@Quantity,@Store_ID,@Store_Place_ID,@Date,@Note)";
                                    com   = new MySqlCommand(query, dbconnection);
                                    com.Parameters.Add("@Data_ID", MySqlDbType.Int16);
                                    com.Parameters["@Data_ID"].Value = row1["Data_ID"].ToString();
                                    com.Parameters.Add("@Quantity", MySqlDbType.Decimal);
                                    com.Parameters["@Quantity"].Value = 0;
                                    com.Parameters.Add("@Store_ID", MySqlDbType.Int16);
                                    com.Parameters["@Store_ID"].Value = comToStore.SelectedValue.ToString();
                                    com.Parameters.Add("@Store_Place_ID", MySqlDbType.Int16);
                                    com.Parameters["@Store_Place_ID"].Value = comStorePlace.SelectedValue.ToString();
                                    com.Parameters.Add("@Date", MySqlDbType.Date, 0);
                                    DateTime date = DateTime.Now;
                                    string   d    = date.ToString("yyyy-MM-dd");
                                    com.Parameters["@Date"].Value = d;
                                    com.Parameters.Add("@Note", MySqlDbType.VarChar);
                                    com.Parameters["@Note"].Value = "تعديل تحويل";
                                    com.ExecuteNonQuery();

                                    UserControl.ItemRecord("open_storage_account", "اضافة", Convert.ToInt32(row1["Data_ID"].ToString()), DateTime.Now, "تعديل تحويل", dbconnection);
                                }

                                query = "select sum(Total_Meters) from storage where Data_ID=" + row1[0].ToString() + " and Store_ID=" + comToStore.SelectedValue.ToString() + " group by Data_ID";
                                com   = new MySqlCommand(query, dbconnection);
                                if (com.ExecuteScalar() != null)
                                {
                                    quantity = Convert.ToDouble(com.ExecuteScalar().ToString());
                                    meters   = quantity + neededQuantity;
                                    query    = "update storage set Total_Meters=" + meters + " where Data_ID=" + row1[0].ToString() + " and Store_ID=" + comToStore.SelectedValue.ToString();
                                    com      = new MySqlCommand(query, dbconnection);
                                    com.ExecuteNonQuery();
                                }
                                else
                                {
                                    query = "insert into storage (Store_ID,Store_Place_ID,Storage_Date,Type,Data_ID,Total_Meters,Note) values (@Store_ID,@Store_Place_ID,@Storage_Date,@Type,@Data_ID,@Total_Meters,@Note)";
                                    com   = new MySqlCommand(query, dbconnection);
                                    com.Parameters.Add("@Store_ID", MySqlDbType.Int16);
                                    com.Parameters["@Store_ID"].Value = comToStore.SelectedValue.ToString();
                                    com.Parameters.Add("@Store_Place_ID", MySqlDbType.Int16);
                                    com.Parameters["@Store_Place_ID"].Value = comStorePlace.SelectedValue.ToString();
                                    com.Parameters.Add("@Storage_Date", MySqlDbType.DateTime);
                                    com.Parameters["@Storage_Date"].Value = DateTime.Now;
                                    com.Parameters.Add("@Type", MySqlDbType.VarChar);
                                    com.Parameters["@Type"].Value = "بند";
                                    com.Parameters.Add("@Data_ID", MySqlDbType.Int16);
                                    com.Parameters["@Data_ID"].Value = row1["Data_ID"].ToString();
                                    com.Parameters.Add("@Total_Meters", MySqlDbType.Decimal);
                                    com.Parameters["@Total_Meters"].Value = neededQuantity;
                                    com.Parameters.Add("@Note", MySqlDbType.VarChar);
                                    com.Parameters["@Note"].Value = "تعديل تحويل";
                                    com.ExecuteNonQuery();
                                }
                            }

                            gridView2.AddNewRow();
                            int rowHandle = gridView2.GetRowHandle(gridView2.DataRowCount);
                            if (gridView2.IsNewItemRow(rowHandle) && row1 != null)
                            {
                                gridView2.SetRowCellValue(rowHandle, gridView2.Columns["Data_ID"], row1["Data_ID"].ToString());
                                gridView2.SetRowCellValue(rowHandle, gridView2.Columns["الكود"], row1["الكود"].ToString());
                                gridView2.SetRowCellValue(rowHandle, gridView2.Columns["النوع"], row1["النوع"].ToString());
                                gridView2.SetRowCellValue(rowHandle, gridView2.Columns["الاسم"], row1["الاسم"].ToString());
                                gridView2.SetRowCellValue(rowHandle, gridView2.Columns["الكرتنة"], row1["الكرتنة"].ToString());
                                gridView2.SetRowCellValue(rowHandle, gridView2.Columns["الكمية"], neededQuantity);
                                if (comBranch.Text != "" && txtBillNum.Text != "")
                                {
                                    gridView2.SetRowCellValue(rowHandle, gridView2.Columns["رقم الفاتورة"], comBranch.Text + " " + txtBillNum.Text);
                                    gridView2.SetRowCellValue(rowHandle, gridView2.Columns["CustomerBill_ID"], CustomerBillID);
                                }
                                else
                                {
                                    gridView2.SetRowCellValue(rowHandle, gridView2.Columns["رقم الفاتورة"], "");
                                    gridView2.SetRowCellValue(rowHandle, gridView2.Columns["CustomerBill_ID"], 0);
                                }
                            }

                            txtQuantity.Text        = "";
                            txtCode.Text            = "";
                            txtBillNum.Text         = "";
                            comBranch.SelectedIndex = -1;
                        }
                        else if (neededQuantity > quantity)
                        {
                            MessageBox.Show("لا يوجد كمية كافية");
                        }
                    }
                    else
                    {
                        MessageBox.Show("يجب ادخال جميع البيانات");
                    }
                }
                else
                {
                    MessageBox.Show("يجب اختيار المخازن");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }