Пример #1
0
        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("سيتم الحفظ و الترحيل للخزنه" + Environment.NewLine + "هل انت متأكد؟","حفظ الفاتوره...",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation) == DialogResult.No)
            //    return;
            if (MessageBox.Show("هل انت متأكد؟", "حفظ الفاتوره...", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
            {
                return;
            }
            SqlConnection con = new SqlConnection(FXFW.SqlDB.SqlConStr);
            SqlCommand    cmd = new SqlCommand("", con);

            //SqlTransaction Trn = null;
            try
            {
                foreach (DataRow row in ItemDetials.Rows)
                {
                    if (row["SanfID"].ToString() == string.Empty || row["harakatype"].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 (row["DiscountTypeId"].ToString() != ((int)Program.DiscountType.بدون_خصم).ToString() && row["harakatype"].ToString() == ((int)Program.HarakaType.مرتجع).ToString())
                    {
                        MessageBox.Show("لا يمكن اضافة خصم لمرتجع", "بيانات خطاء", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (row["harakatype"].ToString() == ((int)Program.HarakaType.مبيعات).ToString())
                    {
                        if (ItemAvailability(row["SanfID"].ToString(), row["Quantity"].ToString()) == false)
                        {
                            Program.msg("لا يوجد كميه كافيه في المخزن", true, "", this);
                            return;
                        }
                    }
                }
                con.Open();
                //Trn = con.BeginTransaction();
                //cmd.Transaction = Trn;
                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();
                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 = "3";
                    if (row["harakatype"].ToString() != string.Empty)
                    {
                        harakatype = row["harakatype"].ToString();
                    }
                    cmd.CommandText = string.Format(@"INSERT INTO StoreTransactionDetailes (StoreTrID, SanfID, Quantity, Price, Discount, harakatype, DiscountTypeId, ohda, ohdatypeid) VALUES 
                    ({0}, {1}, {2}, {3}, {4}, {5}, {6}, 'true', 1)", StoreTrID, row["SanfID"], row["Quantity"], row["Price"], row["Discount"], row["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
                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());
                DEStoreTrDate.Focus();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message, ex.ErrorCode.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            con.Close();
        }
        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("سيتم الحفظ و الترحيل للخزنه" + Environment.NewLine + "هل انت متأكد؟","حفظ الفاتوره...",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation) == DialogResult.No)
            //    return;
            if (MessageBox.Show("هل انت متأكد؟","حفظ الفاتوره...",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation) == DialogResult.No)
                return;
            SqlConnection con = new SqlConnection(FXFW.SqlDB.SqlConStr);
            SqlCommand cmd = new SqlCommand("", con);
            //SqlTransaction Trn = null;
            try
            {
                foreach (DataRow row in ItemDetials.Rows)
                {
                    if (row["SanfID"].ToString() == string.Empty || row["harakatype"].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 (row["DiscountTypeId"].ToString() != ((int)Program.DiscountType.بدون_خصم).ToString() && row["harakatype"].ToString() == ((int)Program.HarakaType.مرتجع).ToString())
                    {
                        MessageBox.Show("لا يمكن اضافة خصم لمرتجع", "بيانات خطاء", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (row["harakatype"].ToString() == ((int)Program.HarakaType.مبيعات).ToString())
                    {
                        if (ItemAvailability(row["SanfID"].ToString(), row["Quantity"].ToString()) == false)
                        {
                            Program.msg("لا يوجد كميه كافيه في المخزن", true, "", this);
                            return;
                        }
                    }
                }
                con.Open();
                //Trn = con.BeginTransaction();
                //cmd.Transaction = Trn;
                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();
                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();
                    cmd.CommandText = string.Format(@"INSERT INTO StoreTransactionDetailes (StoreTrID, SanfID, Quantity, Price, Discount, harakatype, DiscountTypeId, ohda, ohdatypeid) VALUES
                    ({0}, {1}, {2}, {3}, {4}, {5}, {6}, 'true', 1)", StoreTrID, row["SanfID"], row["Quantity"], row["Price"], row["Discount"], row["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
                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());
                DEStoreTrDate.Focus();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message, ex.ErrorCode.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            con.Close();
        }