private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridView2.RowCount > 0)
                {
                    #region report
                    List <Transportation_Items> bi = new List <Transportation_Items>();
                    for (int i = 0; i < gridView2.RowCount; i++)
                    {
                        int rowHand = gridView2.GetRowHandle(i);

                        Transportation_Items item = new Transportation_Items()
                        {
                            Code = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الكود"]), Product_Type = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["النوع"]), Product_Name = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الاسم"]), Total_Meters = Convert.ToDouble(gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الكمية"]))
                        };
                        bi.Add(item);
                    }
                    Report_Transportation_Copy f = new Report_Transportation_Copy();
                    f.PrintInvoice(Convert.ToInt16(selRow["رقم التحويل"].ToString()), comFromStore.Text, comToStore.Text, selRow["تاريخ التحويل"].ToString(), bi);
                    f.ShowDialog();
                    #endregion
                }
                else
                {
                    MessageBox.Show("يجب ادخال جميع البيانات");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridView2.RowCount > 0)
                {
                    #region report
                    List <Transportation_Items> bi = new List <Transportation_Items>();
                    for (int i = 0; i < gridView2.RowCount; i++)
                    {
                        int rowHand = gridView2.GetRowHandle(i);

                        Transportation_Items item = new Transportation_Items()
                        {
                            Code = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الكود"]), Product_Type = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["النوع"]), Product_Name = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الاسم"]), Total_Meters = Convert.ToDouble(gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الكمية"])), Bill = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["فاتورة"])
                        };
                        bi.Add(item);
                    }
                    Report_Transportation_Bill_Copy f = new Report_Transportation_Bill_Copy();
                    f.PrintInvoice(TransferProductID, comFromStore.Text, comToStore.Text, Date.ToString(), bi);
                    f.ShowDialog();
                    #endregion

                    XtraTabPage xtraTabPage = getTabPage("تعديل بيانات تحويل فاتورة");
                    tabControlStoresContent.TabPages.Remove(xtraTabPage);
                }
                else
                {
                    MessageBox.Show("يجب ادخال جميع البيانات");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridView2.RowCount > 0 && comFromStore.Text != "" && comToStore.Text != "" && comFromStore.SelectedValue != null && comToStore.SelectedValue != null)
                {
                    dbconnection.Open();
                    string       query = "insert into transfer_product (From_Store,To_Store,Date) values (@From_Store,@To_Store,@Date)";
                    MySqlCommand com   = new MySqlCommand(query, dbconnection);
                    com.Parameters.Add("@From_Store", MySqlDbType.Int16);
                    com.Parameters["@From_Store"].Value = comFromStore.SelectedValue.ToString();
                    com.Parameters.Add("@To_Store", MySqlDbType.Int16);
                    com.Parameters["@To_Store"].Value = comToStore.SelectedValue.ToString();
                    com.Parameters.Add("@Date", MySqlDbType.DateTime);
                    com.Parameters["@Date"].Value = DateTime.Now;
                    com.ExecuteNonQuery();

                    query = "select TransferProduct_ID from transfer_product order by TransferProduct_ID desc limit 1";
                    com   = new MySqlCommand(query, dbconnection);
                    int transferProductID = Convert.ToInt32(com.ExecuteScalar().ToString());

                    for (int i = 0; i < gridView2.RowCount; i++)
                    {
                        int     rowhnd = gridView2.GetRowHandle(i);
                        DataRow row2   = gridView2.GetDataRow(rowhnd);
                        query = "insert into transfer_product_details (Data_ID,Quantity,TransferProduct_ID,CustomerBill_ID) values (@Data_ID,@Quantity,@TransferProduct_ID,@CustomerBill_ID)";
                        com   = new MySqlCommand(query, dbconnection);
                        com.Parameters.Add("@Data_ID", MySqlDbType.Int16);
                        com.Parameters["@Data_ID"].Value = row2["Data_ID"].ToString();
                        com.Parameters.Add("@Quantity", MySqlDbType.Decimal);
                        com.Parameters["@Quantity"].Value = row2["الكمية"].ToString();
                        com.Parameters.Add("@TransferProduct_ID", MySqlDbType.Int16);
                        com.Parameters["@TransferProduct_ID"].Value = transferProductID;
                        com.Parameters.Add("@CustomerBill_ID", MySqlDbType.Int16);
                        com.Parameters["@CustomerBill_ID"].Value = row2["CustomerBill_ID"].ToString();
                        com.ExecuteNonQuery();
                    }

                    #region report
                    List <Transportation_Items> bi = new List <Transportation_Items>();
                    for (int i = 0; i < gridView2.RowCount; i++)
                    {
                        int rowHand = gridView2.GetRowHandle(i);

                        Transportation_Items item = new Transportation_Items()
                        {
                            Code = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الكود"]), Product_Type = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["النوع"]), Product_Name = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الاسم"]), Total_Meters = Convert.ToDouble(gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الكمية"])), Bill = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["فاتورة"])
                        };
                        bi.Add(item);
                    }
                    Report_Transportation_Bill f = new Report_Transportation_Bill();
                    f.PrintInvoice(transferProductID, comFromStore.Text, comToStore.Text, bi);
                    f.ShowDialog();
                    #endregion

                    clear();
                }
                else
                {
                    MessageBox.Show("يجب ادخال جميع البيانات");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridView2.RowCount > 0 && comFromStore.Text != "" && comToStore.Text != "" && comFromStore.SelectedValue != null && comToStore.SelectedValue != null)
                {
                    dbconnection.Open();
                    string       query = "insert into transfer_product (From_Store,To_Store,Date) values (@From_Store,@To_Store,@Date)";
                    MySqlCommand com   = new MySqlCommand(query, dbconnection);
                    com.Parameters.Add("@From_Store", MySqlDbType.Int16);
                    com.Parameters["@From_Store"].Value = comFromStore.SelectedValue.ToString();
                    com.Parameters.Add("@To_Store", MySqlDbType.Int16);
                    com.Parameters["@To_Store"].Value = comToStore.SelectedValue.ToString();
                    com.Parameters.Add("@Date", MySqlDbType.DateTime);
                    com.Parameters["@Date"].Value = DateTime.Now;
                    com.ExecuteNonQuery();

                    query = "select TransferProduct_ID from transfer_product order by TransferProduct_ID desc limit 1";
                    com   = new MySqlCommand(query, dbconnection);
                    int transferProductID = Convert.ToInt32(com.ExecuteScalar().ToString());

                    for (int i = 0; i < gridView2.RowCount; i++)
                    {
                        int     rowhnd = gridView2.GetRowHandle(i);
                        DataRow row2   = gridView2.GetDataRow(rowhnd);
                        query = "insert into transfer_product_details (Data_ID,Quantity,TransferProduct_ID,CustomerBill_ID) values (@Data_ID,@Quantity,@TransferProduct_ID,@CustomerBill_ID)";
                        com   = new MySqlCommand(query, dbconnection);
                        com.Parameters.Add("@Data_ID", MySqlDbType.Int16);
                        com.Parameters["@Data_ID"].Value = row2["Data_ID"].ToString();
                        //com.Parameters.Add("@Balatat", MySqlDbType.Int16);
                        //com.Parameters["@Balatat"].Value = row2["عدد البلتات"].ToString();
                        //com.Parameters.Add("@Carton_Balata", MySqlDbType.Int16);
                        //com.Parameters["@Carton_Balata"].Value = row2["عدد الكراتين"].ToString();
                        com.Parameters.Add("@Quantity", MySqlDbType.Decimal);
                        com.Parameters["@Quantity"].Value = row2["الكمية"].ToString();
                        com.Parameters.Add("@TransferProduct_ID", MySqlDbType.Int16);
                        com.Parameters["@TransferProduct_ID"].Value = transferProductID;
                        com.Parameters.Add("@CustomerBill_ID", MySqlDbType.Int16);
                        com.Parameters["@CustomerBill_ID"].Value = 0;
                        com.ExecuteNonQuery();

                        query = "select sum(Total_Meters) from storage where Data_ID=" + row2[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 - Convert.ToDouble(row2["الكمية"].ToString());
                        query = "update storage set Total_Meters=" + meters + " where Data_ID=" + row2[0].ToString() + " and Store_ID=" + comFromStore.SelectedValue.ToString();
                        com   = new MySqlCommand(query, dbconnection);
                        com.ExecuteNonQuery();

                        UserControl.ItemRecord("storage", "تعديل", Convert.ToInt32(row2[0].ToString()), DateTime.Now, "طرح بسبب تحويل", dbconnection);

                        query = "select OpenStorageAccount_ID from open_storage_account where Data_ID=" + row2["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 = row2["Data_ID"].ToString();
                            com.Parameters.Add("@Quantity", MySqlDbType.Decimal);
                            com.Parameters["@Quantity"].Value = 0 /*row2["الكمية"].ToString()*/;
                            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);
                            com.Parameters["@Date"].Value = DateTime.Now;
                            com.Parameters.Add("@Note", MySqlDbType.VarChar);
                            com.Parameters["@Note"].Value = "تحويل";
                            com.ExecuteNonQuery();

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

                        query = "select sum(Total_Meters) from storage where Data_ID=" + row2[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 + Convert.ToDouble(row2["الكمية"].ToString());
                            query    = "update storage set Total_Meters=" + meters + " where Data_ID=" + row2[0].ToString() + " and Store_ID=" + comToStore.SelectedValue.ToString();
                            com      = new MySqlCommand(query, dbconnection);
                            com.ExecuteNonQuery();

                            UserControl.ItemRecord("storage", "تعديل", Convert.ToInt32(row2[0].ToString()), DateTime.Now, "تحويل", dbconnection);
                        }
                        else
                        {
                            query = "insert into storage (Store_ID,Storage_Date,Type,Data_ID,Store_Place_ID,Total_Meters,Note) values (@Store_ID,@Storage_Date,@Type,@Data_ID,@Store_Place_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 = row2["Data_ID"].ToString();
                            com.Parameters.Add("@Total_Meters", MySqlDbType.Decimal);
                            com.Parameters["@Total_Meters"].Value = row2["الكمية"].ToString();
                            com.Parameters.Add("@Note", MySqlDbType.VarChar);
                            com.Parameters["@Note"].Value = "تحويل";
                            com.ExecuteNonQuery();

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

                    #region report
                    List <Transportation_Items> bi = new List <Transportation_Items>();
                    for (int i = 0; i < gridView2.RowCount; i++)
                    {
                        int rowHand = gridView2.GetRowHandle(i);

                        Transportation_Items item = new Transportation_Items()
                        {
                            Code = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الكود"]), Product_Type = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["النوع"]), Product_Name = gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الاسم"]), Total_Meters = Convert.ToDouble(gridView2.GetRowCellDisplayText(rowHand, gridView2.Columns["الكمية"]))
                        };
                        bi.Add(item);
                    }
                    Report_Transportation f = new Report_Transportation();
                    f.PrintInvoice(transferProductID, comFromStore.Text, comToStore.Text, bi);
                    f.ShowDialog();
                    #endregion

                    clear();
                }
                else
                {
                    MessageBox.Show("يجب ادخال جميع البيانات");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            dbconnection.Close();
        }
        private void btnReport_Click(object sender, EventArgs e)
        {
            if (TransferProductID > 0)
            {
                try
                {
                    List <Transportation_Items> bi = new List <Transportation_Items>();
                    conn.Open();
                    string          query = "SELECT transfer_product.TransferProduct_ID as 'رقم التحويل',storeFrom.Store_Name as 'من مخزن',storeTo.Store_Name as 'الى مخزن',transfer_product.Date as 'تاريخ التحويل' FROM transfer_product left JOIN store as storeTo ON storeTo.Store_ID = transfer_product.To_Store left join store as storeFrom on storeFrom.Store_ID = transfer_product.From_Store where transfer_product.TransferProduct_ID=" + TransferProductID;
                    MySqlCommand    com   = new MySqlCommand(query, conn);
                    MySqlDataReader dr    = com.ExecuteReader();
                    while (dr.Read())
                    {
                        Transportation_Items item;
                        connectionReader2.Open();

                        string          q   = "SELECT data.Code as 'الكود',type.Type_Name as 'النوع',concat(product.Product_Name,' ',COALESCE(color.Color_Name,''),' ',data.Description,' ',groupo.Group_Name,' ',factory.Factory_Name,' ',COALESCE(size.Size_Value,''),' ',COALESCE(sort.Sort_Value,'')) as 'الاسم',transfer_product_details.Quantity as 'الكمية',concat(customer_bill.Branch_BillNumber,' ',customer_bill.Branch_Name) as 'رقم الفاتورة' FROM transfer_product_details INNER JOIN transfer_product ON transfer_product_details.TransferProduct_ID = transfer_product.TransferProduct_ID left JOIN store as storeTo ON storeTo.Store_ID = transfer_product.To_Store left join store as storeFrom on storeFrom.Store_ID = transfer_product.From_Store left JOIN customer_bill ON transfer_product_details.CustomerBill_ID = customer_bill.CustomerBill_ID INNER JOIN data ON transfer_product_details.Data_ID = data.Data_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 INNER JOIN groupo ON data.Group_ID = groupo.Group_ID INNER JOIN factory ON factory.Factory_ID = data.Factory_ID  INNER JOIN product ON product.Product_ID = data.Product_ID  INNER JOIN type ON type.Type_ID = data.Type_ID where transfer_product.TransferProduct_ID=" + dr["رقم التحويل"].ToString() + " order by SUBSTR(data.Code,1,16),color.Color_Name,data.Description,data.Sort_ID";
                        MySqlCommand    c   = new MySqlCommand(q, connectionReader2);
                        MySqlDataReader dr1 = c.ExecuteReader();
                        while (dr1.Read())
                        {
                            if (WithBill == false)
                            {
                                item = new Transportation_Items()
                                {
                                    Code = dr1["الكود"].ToString(), Product_Type = dr1["النوع"].ToString(), Product_Name = dr1["الاسم"].ToString(), Total_Meters = Convert.ToDouble(dr1["الكمية"].ToString())
                                };
                            }
                            else
                            {
                                item = new Transportation_Items()
                                {
                                    Code = dr1["الكود"].ToString(), Product_Type = dr1["النوع"].ToString(), Product_Name = dr1["الاسم"].ToString(), Total_Meters = Convert.ToDouble(dr1["الكمية"].ToString()), Bill = dr1["رقم الفاتورة"].ToString()
                                };
                            }
                            bi.Add(item);
                        }
                        dr1.Close();
                    }
                    if (WithBill == false)
                    {
                        Report_Transportation_Copy f = new Report_Transportation_Copy();
                        f.PrintInvoice(Convert.ToInt16(dr["رقم التحويل"].ToString()), dr["من مخزن"].ToString(), dr["الى مخزن"].ToString(), dr["تاريخ التحويل"].ToString(), bi);
                        dr.Close();
                        f.ShowDialog();
                    }
                    else
                    {
                        Report_Transportation_Bill_Copy f = new Report_Transportation_Bill_Copy();
                        f.PrintInvoice(Convert.ToInt16(dr["رقم التحويل"].ToString()), dr["من مخزن"].ToString(), dr["الى مخزن"].ToString(), dr["تاريخ التحويل"].ToString(), bi);
                        dr.Close();
                        f.ShowDialog();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                conn.Close();
                connectionReader2.Close();
            }
            else
            {
                MessageBox.Show("برجاء التاكد من اختيار عنصر");
            }
        }