private void repositoryItemButtonEditPrint_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            //GetBillDetial();
            //DataTable dt1 = (DataTable)gridControlEditDetails.DataSource;
            DataRow row = gridViewEdit.GetFocusedDataRow();

            XRepBillResit report = new XRepBillResit();
            report.LoadDataSource(row["StoreTrID"].ToString());

            report.LblStoreTrIDTYPE.Text = row["StoreTrIDTYPE"].ToString();
            report.LblStoreTrIDDAY.Text = row["StoreTrIDDAY"].ToString();
            report.LblStoreTrDate.Text = DEStoreTrDate.Text;
            DataTable alsofof_NAMETbl = FXFW.SqlDB.LoadDataTable(String.Format(@"SELECT alsofof_NAME FROM CDalsofof
                WHERE alsofof_code = (SELECT alsofof_code FROM student WHERE asase_code = (Select Max(asase_code) From student) AND stu_code =
                (SELECT PERSONID FROM TBLStoreTransaction WHERE StoreTrID = {0}) )", row["StoreTrID"]));
            if (alsofof_NAMETbl.Rows.Count > 0)
                report.LblSaf.Text = alsofof_NAMETbl.Rows[0][0].ToString();

            report.LblPERSONID.Text = LUEPERSONID.Text;
            report.LblTotal.Text = LblTotal.Text;
            report.LblPayed.Text = LblTotal.Text;
            report.xrBarCodeItem.Text = row["StoreTrID"].ToString();

            DataTable dt = FXFW.SqlDB.LoadDataTable("SELECT Company FROM CDCompany");
            if (dt.Rows.Count > 0)
                report.LblCompany.Text = dt.Rows[0]["Company"].ToString();
            else
                report.LblCompany.Text = string.Empty;

            Program.ShowPrintPreview(report);
        }
        private void BtnSave_Click(object sender, EventArgs e)
        {
            //check for  - data
            if (TxtBillID.Text.Trim().Length == 0 || DEStoreTrDate.EditValue == null || LUEPERSONID.EditValue == null || LUEEMPID.EditValue == null || LUEStoreID.EditValue == null || LUEBillPayType.EditValue == null)
            {
                string ErrorText = "يجب ادخال كلا من" + "\n";
                ErrorText += "تاريخ الفاتوره" + "\n";
                ErrorText += "اسم المورد" + "\n";
                ErrorText += "المستلم" + "\n";
                ErrorText += "المخزن" + "\n";
                ErrorText += "نوع الدفع";
                MessageBox.Show(ErrorText, "بيانات غير مكتمله", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (ItemDetials.Rows.Count == 0)
            {
                MessageBox.Show("يجب ادخال تفاصيل الفاتوره", "بيانات غير مكتمله", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            foreach (DataRow row in ItemDetials.Rows)
            {
                if (row["SanfID"].ToString() == string.Empty)
                {
                    MessageBox.Show("يجب ادخال الصنف", "بيانات غير مكتمله", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if (MessageBox.Show("هل انت متأكد؟","حفظ الفاتوره...",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation) == DialogResult.No)
                return;
            SqlConnection con = new SqlConnection(FXFW.SqlDB.SqlConStr);
            SqlCommand cmd = new SqlCommand("", con);
            try
            {
                foreach (DataRow row in ItemDetials.Rows)
                {
                    if (row["SanfID"].ToString() == string.Empty || row["Quantity"].ToString() == string.Empty || row["Price"].ToString() == string.Empty || row["DiscountTypeId"].ToString() == string.Empty || row["Discount"].ToString() == string.Empty)
                    {
                        MessageBox.Show("بيانات صنف غير مكتمله", "بيانات غير مكتمله", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (ItemAvailability(row["SanfID"].ToString(), row["Quantity"].ToString()) == false)
                    {
                        Program.msg("لا يوجد كميه كافيه في المخزن", true, "", this);
                        return;
                    }
                }
                con.Open();

                string Totalkasm = "0", REM = "NULL", StoreTrID = "NULL", DiscountTypeId = "NULL", EMPID = "NULL";
                string StoreTrDate = string.Format("Convert(Datetime, '{0}', 103)", DEStoreTrDate.Text);
                string Today = string.Format("Convert(Datetime, '{0}/{1}/{2}', 103)", DEStoreTrDate.DateTime.Day, DEStoreTrDate.DateTime.Month, DEStoreTrDate.DateTime.Year);
                if (TxtTotalkasm.Text.Trim().Length != 0 && LUEDiscountTypeId.EditValue.ToString() != ((int)Program.DiscountType.بدون_خصم).ToString())
                    Totalkasm = TxtTotalkasm.Text.Trim();
                if (MemInfo.Text.Trim().Length != 0)
                    REM = String.Format("N'{0}'", MemInfo.Text.Trim());
                if (LUEDiscountTypeId.EditValue != null)
                    DiscountTypeId = LUEDiscountTypeId.EditValue.ToString();
                if (LUEEMPID.EditValue != null)
                    EMPID = LUEEMPID.EditValue.ToString();
                StoreTrID = Program.GetNewID("TBLStoreTransaction", "StoreTrID");
                string StoreTrIDDAY = Program.GetNewID("TBLStoreTransaction", "StoreTrIDDAY", "StoreTrDate = " + Today);
                string StoreTrIDTYPE = Program.GetNewID("TBLStoreTransaction", "StoreTrIDTYPE", "STTRANSTYPEID = 2");
                cmd.CommandText = string.Format(@"INSERT INTO TBLStoreTransaction (StoreTrID, STTRANSTYPEID, StoreTrDate, StoreTrIDDAY, StoreTrIDTYPE, PERSONID, BillPayTypeID, Totalkasm, REM, StoreID, EMPID, TRHEL, UserIN, TimeIN) VALUES
                ({0}, 2, {1}, {2}, (Select Isnull(Max(StoreTrIDTYPE) + 1, 1) From TBLStoreTransaction Where STTRANSTYPEID = 2), {3}, {4}, {5}, {6}, {7}, {8}, '{9}', {10}, GETDATE())",
                StoreTrID, StoreTrDate, StoreTrIDDAY, LUEPERSONID.EditValue, LUEBillPayType.EditValue, Totalkasm, REM, LUEStoreID.EditValue, EMPID, "False", FXFW.SqlDB.UserInfo.UserID);
                cmd.ExecuteNonQuery();
                bool HaveNoMortaga3 = false;
                foreach (DataRow row in ItemDetials.Rows)
                {

                    string SanfID = "NULL", Quantity = "0", Price = "0", Discount = "0";
                    SanfID = row["SanfID"].ToString();
                    if (row["Quantity"].ToString() != string.Empty)
                        Quantity = row["Quantity"].ToString();
                    if (row["Price"].ToString() != string.Empty)
                        Price = row["Price"].ToString();
                    if (row["Discount"].ToString() != string.Empty)
                        Discount = row["Discount"].ToString();
                    string harakatype = "2";
                    if (row["harakatype"].ToString() != string.Empty)
                    {
                        harakatype = row["harakatype"].ToString();
                        if (row["harakatype"].ToString() == "1" | row["harakatype"].ToString() == "3")// should do not show print if its mortaga3
                            HaveNoMortaga3 = true;
                    }

                    cmd.CommandText = string.Format(@"INSERT INTO StoreTransactionDetailes (StoreTrID, SanfID, Quantity, Price, Discount, harakatype, DiscountTypeId, ohda, ohdatypeid) VALUES
                    ({0}, {1}, {2}, {3}, {4}, {5}, {6}, 'false', 1)", StoreTrID, row["SanfID"], row["Quantity"], row["Price"], row["Discount"], harakatype, row["DiscountTypeId"]);
                    cmd.ExecuteNonQuery();
                }
            //                string ActionId = "2";
            //                if (Convert.ToDouble(LblTotal.Text) <= 0)
            //                {
            //                    ActionId = "1";
            //                    LblTotal.Text = (Convert.ToDouble(LblTotal.Text) * -1).ToString();
            //                }
            //                cmd.CommandText = string.Format(@"INSERT INTO TblAlkazna (ActionId, HarakaNo, ActionDate, Amony, notes, namee, closek, UserIn, TimeIn)
            //                VALUES ({0}, (Select Isnull(Max(HarakaNo) + 1, 1) From TblAlkazna Where ActionId = {0}), {1}, {2}, N'{3}', N'{4}', 1, {5}, GETDATE())",
            //                ActionId, StoreTrDate, LblTotal.Text, MemInfo.Text, "فاتورة مبيعات", FXFW.SqlDB.UserInfo.UserID);
            //                cmd.ExecuteNonQuery();

                // Print Bill Resit
                ShowTotal();

                XRepBillResit report = new XRepBillResit();
                report.LoadDataSource(StoreTrID);

                report.LblStoreTrIDTYPE.Text = StoreTrIDTYPE;
                report.LblStoreTrIDDAY.Text = StoreTrIDDAY;
                report.LblStoreTrDate.Text = DEStoreTrDate.Text;
                report.LblSaf.Text = FXFW.SqlDB.LoadDataTable(String.Format(@"SELECT alsofof_NAME FROM CDalsofof
                WHERE alsofof_code = (SELECT alsofof_code FROM student WHERE asase_code = (Select Max(asase_code) From student) AND stu_code =
                (SELECT PERSONID FROM TBLStoreTransaction WHERE StoreTrID = {0}) )", StoreTrID)).Rows[0][0].ToString() + ")";

                report.LblPERSONID.Text = LUEPERSONID.Text;
                report.LblTotal.Text = LblTotal.Text;
                report.LblPayed.Text = LblTotal.Text;
                report.xrBarCodeItem.Text = StoreTrID;

                DataTable dt = FXFW.SqlDB.LoadDataTable("SELECT Company FROM CDCompany");
                if (dt.Rows.Count > 0)
                    report.LblCompany.Text = dt.Rows[0]["Company"].ToString();
                else
                    report.LblCompany.Text = string.Empty;
                if (HaveNoMortaga3 == false)
                    Program.ShowPrintPreview(report);

                //using (BillResitFrm PrintResit = new BillResitFrm(StoreTrID, StoreTrIDDAY, StoreTrIDTYPE, DEStoreTrDate.Text, LUEPERSONID.Text, LblTotal.Text, LblTotal.Text))
                //    PrintResit.ShowDialog();

                MessageBox.Show("تم حفظ الفاتوره", "تمت الاضافه", MessageBoxButtons.OK, MessageBoxIcon.Information);
                BtnNew_Click(BtnNew, new EventArgs());
                LUEPERSONID.Focus();
            }
            catch (SqlException ex)
            {
                //Trn.Rollback();
                MessageBox.Show(ex.Message, ex.ErrorCode.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            con.Close();
        }