public bool SavePOS(ACMSLogic.POS pos) { ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider(); //ACMSDAL.ConnectionProvider connProvider1 = new ConnectionProvider(); try { DataTable branchReceiptNoTable = new DataTable(); int latestReceiptNo = GetLatestReceiptNo(connProvider, pos, ref branchReceiptNoTable) + 1; string receiptNo = pos.StrBranchCode.ToString().Trim() + pos.NTerminalID.ToString().Trim() + latestReceiptNo.ToString().Trim(); pos.StrReceiptNo = receiptNo; //Derek Instalment Plan Need to Add PaymentPlan Table Here //Get pos.NCategoryID here to determine if the item is Pay O/S //Here Can get the new Receipt No Value //3 Main table that always need to update TblReceipt receipt = new TblReceipt(); TblReceiptEntries receiptEntries = new TblReceiptEntries(); TblReceiptPayment receiptPayment = new TblReceiptPayment(); TblPaymentPlan myPaymentPlan = new TblPaymentPlan(); receipt.MainConnectionProvider = connProvider; receiptEntries.MainConnectionProvider = connProvider; receiptPayment.MainConnectionProvider = connProvider; myPaymentPlan.MainConnectionProvider = connProvider; connProvider.OpenConnection(); connProvider.BeginTransaction("SaveReceipt"); DataTable receiptTable = pos.ReceiptMasterTable.Copy(); DataTable receiptEntriesTable = pos.ReceiptItemsTable.Copy(); DataTable receiptPaymentTable = pos.ReceiptPaymentTable.Copy(); DataTable freeMemberPackageTable = receipt.FillSchema("Select * From tblMemberPackage"); // use to store the free member package. DataTable freeMemberCreditPackageTable = receipt.FillSchema("Select * From tblMemberCreditPackage"); if (pos.PaymentPlanTable != null && pos.NCategoryID != 0) { DataTable paymentPlanTable = pos.PaymentPlanTable.Copy(); if (paymentPlanTable != null && paymentPlanTable.Rows.Count > 0) { foreach (DataRow r in paymentPlanTable.Rows) { r["strReceiptNo"] = pos.StrReceiptNo; if (r["nInstalmentNo"].ToString() == "1") { r["strPaymentReceiptNo"] = pos.StrReceiptNo; myPaymentPlan.IPPPrimaryEntry(r["strReceiptNo"].ToString(), Convert.ToInt32(r["nInstalmentNo"]), r["strPaymentReceiptNo"].ToString(), Convert.ToDecimal(r["mPaymentPlanAmt"]), Convert.ToDecimal(r["mPaidAmount"]), Convert.ToDecimal(r["mAdjustedPaymentPlanAmt"]), Convert.ToDecimal(r["mOutstandingAmt"]), Convert.ToDateTime(r["dtPaymentDate"]), Convert.ToDateTime(r["dtDueDate"]), Convert.ToDateTime(r["dtFinalDueDate"]), Convert.ToInt32(r["nPaymentPlanID"])); } else { myPaymentPlan.IPPSubsequentEntry(r["strReceiptNo"].ToString(), Convert.ToInt32(r["nInstalmentNo"]), Convert.ToDecimal(r["mPaymentPlanAmt"]), Convert.ToDecimal(r["mPaidAmount"]), Convert.ToDecimal(r["mAdjustedPaymentPlanAmt"]), Convert.ToDecimal(r["mOutstandingAmt"]), Convert.ToDateTime(r["dtDueDate"]), Convert.ToDateTime(r["dtFinalDueDate"]), Convert.ToInt32(r["nPaymentPlanID"])); } } paymentPlanTable.AcceptChanges(); } pos.PaymentPlanTable.AcceptChanges(); } else if (pos.PaymentPlanTable != null && pos.NCategoryID == 0) { DataTable paymentPlanTable = pos.PaymentPlanTable.Copy(); if (paymentPlanTable != null && paymentPlanTable.Rows.Count > 0) { foreach (DataRow r in paymentPlanTable.Rows) { if (r["lastestUpdate"].ToString() == "1") { r["strPaymentReceiptNo"] = pos.StrReceiptNo; myPaymentPlan.IPPPrimaryUpdate(Convert.ToInt32(r["nPaymentPlanID"]), r["strReceiptNo"].ToString(), Convert.ToInt32(r["nInstalmentNo"]), r["strPaymentReceiptNo"].ToString(), Convert.ToDecimal(r["mPaidAmount"]), Convert.ToDecimal(r["mAdjustedPaymentPlanAmt"]), Convert.ToDecimal(r["mOutstandingAmt"]), Convert.ToDateTime(r["dtPaymentDate"])); } else { myPaymentPlan.IPPSubsequentUpdate(Convert.ToInt32(r["nPaymentPlanID"]), r["strReceiptNo"].ToString(), Convert.ToInt32(r["nInstalmentNo"]), Convert.ToDecimal(r["mPaidAmount"]), Convert.ToDecimal(r["mAdjustedPaymentPlanAmt"]), Convert.ToDecimal(r["mOutstandingAmt"])); } } //paymentPlanTable.AcceptChanges(); } pos.PaymentPlanTable.AcceptChanges(); } receipt.SaveData(receiptTable); receiptEntries.SaveData(receiptEntriesTable); receiptPayment.SaveData(receiptPaymentTable); receiptEntries.StrReceiptNo = pos.StrReceiptNo; DataTable savedReceiptEntriesTable = receiptEntries.SelectAllWstrReceiptNoLogic(); pos.ReceiptMasterTable.AcceptChanges(); if (pos.StrFreebieCode.HasValue && pos.StrFreebieCode.ToString() != "") { //Update Bill Freebie here if (pos.ReceiptFreebieTable.Rows.Count > 0) { TblReceiptFreebie receiptFreebie = new TblReceiptFreebie(); receiptFreebie.MainConnectionProvider = connProvider; DataTable receiptFreebieTable = pos.ReceiptFreebieTable.Copy(); // Save Bill Receipt Freebie receiptFreebie.SaveData(receiptFreebieTable); //TblProductInventory proInven = new TblProductInventory(); //proInven.MainConnectionProvider = connProvider; //// deduct stock //foreach (DataRow r in receiptFreebieTable.Rows) //{ // proInven.IncreaseQuantity(r["strItemCode"].ToString(), pos.StrBranchCode, -1); //} } if (pos.ReceiptPackageTable.Rows.Count > 0) { // update package foreach (DataRow r in pos.ReceiptPackageTable.Rows) { TblCreditPackage p = new TblCreditPackage(); p.StrCreditPackageCode = r["strPackageCode"].ToString(); p.SelectOne(); if (p.StrDescription.ToString() != "Null") { DataRow rowToAdd = freeMemberCreditPackageTable.NewRow(); ACMSLogic.MemberPackage.InitMemberCreditPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID, r["strPackageCode"].ToString(), r["strPromotionCode"].ToString(), true); // Add to freeMemberPackageTable and will save freeMemberCreditPackageTable.Rows.Add(rowToAdd); } else { DataRow rowToAdd = freeMemberPackageTable.NewRow(); ACMSLogic.MemberPackage.InitMemberPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID, r["strPackageCode"].ToString(), r["strPromotionCode"].ToString(), true); // Add to freeMemberPackageTable and will save freeMemberPackageTable.Rows.Add(rowToAdd); } } } //else //{ // throw new Exception("Bill Freebie have no free any product or package although the strFreebieCode is not null"); //} } if (pos.ReceiptItemsFreebiePackageTable.Rows.Count > 0) { foreach (DataRow r in pos.ReceiptItemsFreebiePackageTable.Rows) { TblCreditPackage p = new TblCreditPackage(); p.StrCreditPackageCode = r["strPackageCode"].ToString(); p.SelectOne(); if (p.StrDescription.ToString() != "Null") { DataRow rowToAdd = freeMemberCreditPackageTable.NewRow(); ACMSLogic.MemberPackage.InitMemberCreditPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID, r["strPackageCode"].ToString(), r["strPromotionCode"].ToString(), true); // Add to freeMemberPackageTable and will save freeMemberCreditPackageTable.Rows.Add(rowToAdd); } else { DataRow rowToAdd = freeMemberPackageTable.NewRow(); // Kean Yiap if (pos.NCategoryID == 34) { MemberPackage.InitMemberPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID, r["strPackageCode"].ToString(), "", true, -1, pos.dtPackageStart, pos.NProrateDays); } else { ACMSLogic.MemberPackage.InitMemberPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID, r["strPackageCode"].ToString(), r["strPromotionCode"].ToString(), true); } // Add to freeMemberPackageTable and will save freeMemberPackageTable.Rows.Add(rowToAdd); } } } if (pos.ReceiptItemsFreebieProductTable.Rows.Count > 0) { // Update product TblReceiptFreebie receiptFreebie = new TblReceiptFreebie(); receiptFreebie.MainConnectionProvider = connProvider; DataTable receiptItemsFreebieProductTable = pos.ReceiptFreebieTable.Clone(); // i have to use this structure bcoz i wan to save to this table; foreach (DataRow r in pos.ReceiptItemsFreebieProductTable.Rows) { DataRow rowToAdd = receiptItemsFreebieProductTable.NewRow(); rowToAdd["strReceiptNo"] = pos.StrReceiptNo; rowToAdd["strItemCode"] = r["strProductCode"]; rowToAdd["strPromotionCode"] = r["strPromotionCode"]; DataRow[] tempRows = savedReceiptEntriesTable.Select("nTempEntryID = " + r["nEntryID"].ToString(), "", DataViewRowState.CurrentRows); if (tempRows.Length > 0) rowToAdd["nEntryID"] = tempRows[0]["nEntryID"]; receiptItemsFreebieProductTable.Rows.Add(rowToAdd); } receiptFreebie.SaveData(receiptItemsFreebieProductTable); //TblProductInventory proInven = new TblProductInventory(); //proInven.MainConnectionProvider = connProvider; //foreach (DataRow r in receiptItemsFreebieProductTable.Rows) //{ // proInven.IncreaseQuantity(r["strItemCode"].ToString(), pos.StrBranchCode, -1); //} } if (freeMemberPackageTable.Rows.Count > 0) { // update the member package to database TblMemberPackage memberPackage = new TblMemberPackage(); memberPackage.MainConnectionProvider = connProvider; memberPackage.SaveData(freeMemberPackageTable); } if (freeMemberCreditPackageTable.Rows.Count > 0) { // update the member package to database TblMemberCreditPackage memberPackage = new TblMemberCreditPackage(); memberPackage.MainConnectionProvider = connProvider; memberPackage.SaveData(freeMemberCreditPackageTable); } //part 2 DeleteUselessIPP(connProvider, pos); UpdateRegistrationFee(connProvider, pos); UpdateOldPackSetDeactivate(connProvider, pos); //Update when upgrade PostToMemberCreditPackage(connProvider, pos); PostToMemberPackage(connProvider, pos); UpdateUsedCashVoucher(connProvider, pos); int ParentCategoryID = pos.NCategoryID; if (pos.NCategoryID == 10) { ParentCategoryID = UpgradePackage(connProvider, pos); if (ParentCategoryID == 10) { ParentCategoryID = UpgradeCreditPackage(connProvider, pos); } } TopUpCreditPackage(connProvider, pos); TopUpSingleTreatmentTransaction(connProvider, pos); MakeDeposit(connProvider, pos); CashVoucherTransaction(connProvider, pos); LockerTransaction(connProvider, pos); ForgetCardTransaction(connProvider, pos); ReplaceMembershipCardTransaction(connProvider, pos); //MineralWaterTransaction(connProvider, pos); TblRewards rewardcode = new TblRewards(); ACMSDAL.TblCategory category = new ACMSDAL.TblCategory(); category.NCategoryID = pos.NCategoryID; category.SelectOne(); int SalesCategory = ACMS.Convert.ToInt32(category.NSalesCategoryID); //Derek Instalment Plan - Here it assigned the Category to the Pay O/S Receipt Record if (pos.NCategoryID == 0) { ParentCategoryID = PayOutstanding(connProvider, pos); pos.StrRewardsCode = rewardcode.SelectRewards(ParentCategoryID, pos.StrBranchCode); } else pos.StrRewardsCode = rewardcode.SelectRewards(pos.NCategoryID, pos.StrBranchCode); if (pos.StrRewardsCode.HasValue && pos.StrRewardsCode.ToString() != "" && pos.StrRewardsCode.ToString() != "Null") { TblRewards rewards = new TblRewards(); rewards.StrRewardsCode = pos.StrRewardsCode.ToString(); rewards.SelectOne(); double dRewardPoint = 0; double dRewardPercent = (rewards.DRewardsPercent.IsNull ? 0 : rewards.DRewardsPercent.Value); double dRewardValue = (rewards.DRewardsValue.IsNull ? 0 : rewards.DRewardsValue.Value); //jackie 23 others give 50% GIRO //if (ParentCategoryID == 23 && pos.MNettAmount > 60)//pos.MNettAmount //{ // dRewardPercent = 50; //} if (dRewardPercent > 0 && dRewardValue == 0) { decimal mnettTotal = 0; if (pos.MOutstandingAmount > 0) { mnettTotal = pos.MNettAmount - (pos.MOutstandingAmount - pos.MGSTAmount); } else { mnettTotal = pos.MNettAmount; } dRewardPoint = ((double)mnettTotal) * dRewardPercent / 100; } else { if (pos.NCategoryID == 0) { dRewardPoint = dRewardValue; } } if (pos.NThisMonthBirthday == 1) { DialogResult result1 = MessageBox.Show("Member is having birthday this months. Do you want to give double point?", "Warning", MessageBoxButtons.YesNo); if (result1 == DialogResult.Yes) dRewardPoint *= 2; } TblRewardsTransaction rewardTran = new TblRewardsTransaction(); rewardTran.MainConnectionProvider = connProvider; if (pos.NCategoryID == 20) { rewardTran.StrMembershipID = pos.StrNewMembershipID; } else { rewardTran.StrMembershipID = pos.StrMembershipID; } rewardTran.DtDate = pos.DtDate; rewardTran.NTypeID = 1; rewardTran.NEmployeeID = pos.NCashierID; rewardTran.DRewardsPoints = dRewardPoint; rewardTran.StrReferenceNo = pos.StrReceiptNo; if (dRewardPoint > 0) // rewards point > 0 then insert records //3004 { rewardTran.Insert(); } } if (pos.StrRewardsCode.ToString() == "Null") pos.StrRewardsCode = ""; DataTable QtyTable = receiptEntries.Get_StrCodeReceiptNo(pos.StrReceiptNo); //check is the receipt fully paid string Nett = pos.MNettAmount.ToString(); string Outstanding = pos.MOutstandingAmount.ToString(); //if (pos.MOutstandingAmount == 0 && (pos.NCategoryID == 11 || pos.NCategoryID == 12)) // PostToStock(connProvider, QtyTable, pos); receiptTable = pos.ReceiptMasterTable.Copy(); int PosCategory = ACMS.Convert.ToInt32(receiptTable.Rows[0]["nCategoryID"]); if (PosCategory == 24) { receiptTable.Rows[0]["fDeposit"] = true; receipt.SaveData(receiptTable); } if (pos.StrBillReferenceNo != "") { receiptTable.Rows[0]["strBillReferenceNo"] = pos.StrBillReferenceNo; receipt.SaveData(receiptTable); } if (pos.NCategoryID == 0 || pos.NCategoryID == 10) { receipt.StrReceiptNo = pos.StrReceiptNo; receipt.SelectOne(); receipt.MOutstandingAmount = Convert.ToDecimal(pos.MOutstandingAmount); receipt.NCategoryID = ParentCategoryID; receipt.Update(); //TblReceipt receipt3 = new TblReceipt(); //receipt3.StrReceiptNo = pos.StrReceiptNo; //receipt3.SelectOne(); //receipt3.MOutstandingAmount = Convert.ToDecimal(pos.MOutstandingAmount); //receipt3.NCategoryID = ParentCategoryID; //receipt3.Update(); } if (pos.StrDeposit != "") { receipt.StrReceiptNo = pos.StrDeposit; DataTable tblDeposit = receipt.SelectOne(); if (tblDeposit.Rows.Count > 0) { receipt.FDeposit = false; receipt.Update(); } else { TblMemberPackage ConvertedPackage = new TblMemberPackage(); ConvertedPackage.NPackageID = ACMS.Convert.ToSqlInt32(pos.StrDeposit); ConvertedPackage.NStatusID = 1; ConvertedPackage.UpdateConvertedPackageStatus(); } } if (pos.ReceiptItemsTable.Select("", "", DataViewRowState.ModifiedCurrent).Length > 0) { receiptEntriesTable = pos.ReceiptItemsTable.Copy(); receipt.SaveData(receiptEntriesTable); } //1503 branchReceiptNoTable.Rows[0]["nReceiptNo"] = latestReceiptNo; SaveUpToDateReceiptNo(connProvider, branchReceiptNoTable); connProvider.CommitTransaction(); if (pos.StrDeposit != "") { TblReceipt receipt2 = new TblReceipt(); receipt2.StrReceiptNo = pos.StrDeposit; receipt2.SelectOne(); receipt2.StrChildReceiptNo = receiptNo; receipt2.Update(); } return true; } catch (Exception ex) { throw ex; } finally { if (connProvider.CurrentTransaction != null) connProvider.CurrentTransaction.Dispose(); if (connProvider.DBConnection != null) { if (connProvider.DBConnection.State == ConnectionState.Open) connProvider.DBConnection.Close(); } } }
public void NewRedemption(string strMembershipID, string itemCode, int qtyOfItemCodeToRedempt, ref int strTransNo) { ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider(); connProvider.OpenConnection(); TblRewardsCatalogue catalogue = new TblRewardsCatalogue(); catalogue.StrItemCode = itemCode; catalogue.SelectOne(); TblRewardsTransaction rewardTrans = new TblRewardsTransaction(); rewardTrans.MainConnectionProvider = connProvider; rewardTrans.StrMembershipID = strMembershipID; rewardTrans.DtDate = DateTime.Now; rewardTrans.NTypeID = 2; rewardTrans.StrReferenceNo = itemCode; rewardTrans.NEmployeeID = User.EmployeeID; rewardTrans.StrBranchCode = User.BranchCode; if (!catalogue.DRewardsPoints.IsNull) rewardTrans.DRewardsPoints = -catalogue.DRewardsPoints.Value * qtyOfItemCodeToRedempt; rewardTrans.Insert(); strTransNo = rewardTrans.NTransactionID.Value; TblPromotionFreebie promoFreebie = new TblPromotionFreebie(); promoFreebie.StrPromotionCode = itemCode; DataTable receiptFreebieTable = promoFreebie.SelectAllWstrPromotionCodeLogic(); //Code selected is Promotion Freebie Code if (receiptFreebieTable.Rows.Count > 0) { //TblProductInventory proInven = new TblProductInventory(); //proInven.MainConnectionProvider = connProvider; //// deduct stock //foreach (DataRow r in receiptFreebieTable.Rows) //{ // proInven.IncreaseQuantity(r["strItemCode"].ToString(), User.BranchCode, -qtyOfItemCodeToRedempt); //} } else { //Code selected is Package Code TblPackage pkg = new TblPackage(); pkg.StrPackageCode = itemCode; DataTable pkgTable = pkg.SelectOne(); if (pkgTable.Rows.Count > 0) { TblMemberPackage mp = new TblMemberPackage(); mp.SelectAll(); MemberPackage memberPackage = new MemberPackage(); DataTable memberPackageTable = memberPackage.New(false, strMembershipID); DataRow memberPackageRow = memberPackageTable.Rows[0]; memberPackageRow["strMembershipID"] = strMembershipID; memberPackageRow["dtPurchaseDate"] = DateTime.Now; memberPackageRow["strRemarks"] = "REWARDS"; memberPackageRow["nStatusID"] = 0; memberPackageRow["strPackageCode"] = itemCode; memberPackageRow["fFree"] = 1; mp.SaveData(memberPackageTable); } else { //Code selected is Product Code //TblProductInventory productInvent = new TblProductInventory(); //productInvent.MainConnectionProvider = connProvider; //productInvent.StrProductCode = itemCode; //productInvent.SelectOne(); //productInvent.NQuantity = ACMS.Convert.ToInt32(productInvent.NQuantity) - qtyOfItemCodeToRedempt; //productInvent.Update(); } } if (connProvider.CurrentTransaction != null) connProvider.CurrentTransaction.Dispose(); if (connProvider.DBConnection != null) { if (connProvider.DBConnection.State == ConnectionState.Open) connProvider.DBConnection.Close(); } }
private void btnSave_Click(object sender, EventArgs e) { strFreebiz = ""; bool is4 = false; bool is8 = false; if (lkpEdtSalesPersonID.Text == "") { UI.ShowErrorMessage(this, "Please select Sales Person"); lkpEdtSalesPersonID.Focus(); DialogResult = DialogResult.None; return; } else employeeID = ACMS.Convert.ToInt32(lkpEdtSalesPersonID.EditValue); if (txtName1.Text.ToString().Length == 0 && txtContact1.Text.ToString().Length == 0 && txtName2.Text.ToString().Length == 0 && txtContact2.Text.ToString().Length == 0 && txtName3.Text.ToString().Length == 0 && txtContact3.Text.ToString().Length == 0 && txtName4.Text.ToString().Length == 0 && txtContact4.Text.ToString().Length == 0) { UI.ShowErrorMessage(this, "Please enter 1st friend name & contact"); txtName1.Focus(); DialogResult = DialogResult.None; return; } if (txtName1.Text.ToString().Length != 0 || txtContact1.Text.ToString().Length != 0 || txtName2.Text.ToString().Length != 0 || txtContact2.Text.ToString().Length != 0 || txtName3.Text.ToString().Length != 0 || txtContact3.Text.ToString().Length != 0 || txtName4.Text.ToString().Length != 0 || txtContact4.Text.ToString().Length != 0) { if (txtName1.Text.ToString().Length == 0 && txtContact1.Text.ToString().Length == 0) { UI.ShowErrorMessage(this, "Please enter 1st friend name & contact"); txtName1.Focus(); DialogResult = DialogResult.None; return; } else if (txtName2.Text.ToString().Length == 0 && txtContact2.Text.ToString().Length == 0) { UI.ShowErrorMessage(this, "Please enter 2nd friend name & contact"); txtName2.Focus(); DialogResult = DialogResult.None; return; } else if (txtName3.Text.ToString().Length == 0 && txtContact3.Text.ToString().Length == 0) { UI.ShowErrorMessage(this, "Please enter 3rd friend name & contact"); txtName3.Focus(); DialogResult = DialogResult.None; return; } else if (txtName4.Text.ToString().Length == 0 && txtContact4.Text.ToString().Length == 0) { UI.ShowErrorMessage(this, "Please enter 4th friend name & contact"); txtName4.Focus(); DialogResult = DialogResult.None; return; } is4 = true; } if (txtName5.Text.ToString().Length != 0 || txtContact5.Text.ToString().Length != 0 || txtName6.Text.ToString().Length != 0 || txtContact6.Text.ToString().Length != 0 || txtName7.Text.ToString().Length != 0 || txtContact7.Text.ToString().Length != 0 || txtName8.Text.ToString().Length != 0 || txtContact8.Text.ToString().Length != 0) { if (txtName5.Text.ToString().Length == 0 && txtContact5.Text.ToString().Length == 0) { UI.ShowErrorMessage(this, "Please enter 5th friend name & contact"); txtName5.Focus(); DialogResult = DialogResult.None; return; } else if (txtName6.Text.ToString().Length == 0 && txtContact6.Text.ToString().Length == 0) { UI.ShowErrorMessage(this, "Please enter 6th friend name & contact"); txtName6.Focus(); DialogResult = DialogResult.None; return; } else if (txtName7.Text.ToString().Length == 0 && txtContact7.Text.ToString().Length == 0) { UI.ShowErrorMessage(this, "Please enter 7th friend name & contact"); txtName7.Focus(); DialogResult = DialogResult.None; return; } else if (txtName8.Text.ToString().Length == 0 && txtContact8.Text.ToString().Length == 0) { UI.ShowErrorMessage(this, "Please enter 8th friend name & contact"); txtName8.Focus(); DialogResult = DialogResult.None; return; } is4 = false; is8 = true; } if (ddl4Friends.Text.Length == 0 && is4) { UI.ShowErrorMessage(this, "Please select Reward for 4 friends!"); ddl4Friends.Focus(); DialogResult = DialogResult.None; return; } if (ddl8Friends.Text.Length == 0 && is8) { UI.ShowErrorMessage(this, "Please select Reward for 8 friends!"); ddl8Friends.Focus(); DialogResult = DialogResult.None; return; } if ((ddl4Friends.Text.Length != 0) && (ddl8Friends.Text.Length != 0)) { UI.ShowErrorMessage(this, "Please select only one Reward accordingly!"); DialogResult = DialogResult.None; return; } try { if (is4) { myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName1.Text, "", strTerminalBranchCode, "", cbGender1.Text, DateTime.Now, 13, "", txtContact1.Text, "",1); myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName2.Text, "", strTerminalBranchCode, "", cbGender2.Text, DateTime.Now, 13, "", txtContact2.Text, "", 1); myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName3.Text, "", strTerminalBranchCode, "", cbGender3.Text, DateTime.Now, 13, "", txtContact3.Text, "", 1); myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName4.Text, "", strTerminalBranchCode, "", cbGender4.Text, DateTime.Now, 13, "", txtContact4.Text, "", 1); TblRewards tr = new TblRewards(); ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider(); TblMember sqlMember = new TblMember(); TblRewardsTransaction sqlRewardsTransaction = new TblRewardsTransaction(); sqlRewardsTransaction.DRewardsPoints = Convert.ToInt16(ddl4Friends.EditValue.ToString()); sqlRewardsTransaction.DtDate = DateTime.Now; sqlRewardsTransaction.NEmployeeID = employeeID; sqlRewardsTransaction.NTypeID = 0; sqlRewardsTransaction.StrMembershipID = strMembershipID; sqlRewardsTransaction.StrReferenceNo = "4 Referral"; sqlRewardsTransaction.Insert(); } else if (is8) { myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName1.Text, "", strTerminalBranchCode, "", cbGender1.Text, DateTime.Now, 13, "", txtContact1.Text, "", 1); myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName2.Text, "", strTerminalBranchCode, "", cbGender2.Text, DateTime.Now, 13, "", txtContact2.Text, "", 1); myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName3.Text, "", strTerminalBranchCode, "", cbGender3.Text, DateTime.Now, 13, "", txtContact3.Text, "", 1); myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName4.Text, "", strTerminalBranchCode, "", cbGender4.Text, DateTime.Now, 13, "", txtContact4.Text, "", 1); myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName5.Text, "", strTerminalBranchCode, "", cbGender5.Text, DateTime.Now, 13, "", txtContact5.Text, "", 1); myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName6.Text, "", strTerminalBranchCode, "", cbGender6.Text, DateTime.Now, 13, "", txtContact6.Text, "", 1); myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName7.Text, "", strTerminalBranchCode, "", cbGender7.Text, DateTime.Now, 13, "", txtContact7.Text, "", 1); myContacts = new Contacts(); myContacts.NewContact(employeeID, txtName8.Text, "", strTerminalBranchCode, "", cbGender8.Text, DateTime.Now, 13, "", txtContact8.Text, "", 1); ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider(); TblMember sqlMember = new TblMember(); TblRewardsTransaction sqlRewardsTransaction = new TblRewardsTransaction(); sqlRewardsTransaction.DRewardsPoints = Convert.ToInt16(ddl8Friends.EditValue.ToString()); sqlRewardsTransaction.DtDate = DateTime.Now; sqlRewardsTransaction.NEmployeeID = employeeID; sqlRewardsTransaction.NTypeID = 0; sqlRewardsTransaction.StrMembershipID = strMembershipID; sqlRewardsTransaction.StrReferenceNo = "8 Referral"; sqlRewardsTransaction.Insert(); } MessageBox.Show("Intro Friends save successfully."); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.Close(); }
public bool SaveIntroduceFriend(string strMembershipID, string strIntroducerID, double point, int employeeID) { ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider(); TblMember sqlMember = new TblMember(); TblRewardsTransaction sqlRewardsTransaction = new TblRewardsTransaction(); try { sqlRewardsTransaction.MainConnectionProvider = connProvider; sqlMember.MainConnectionProvider = connProvider; connProvider.OpenConnection(); connProvider.BeginTransaction("SaveIntroduceFriend"); sqlMember.UpdateIntroducerMembershipID(strMembershipID, strIntroducerID); sqlRewardsTransaction.DRewardsPoints = point; sqlRewardsTransaction.DtDate = DateTime.Now; sqlRewardsTransaction.NEmployeeID = employeeID; sqlRewardsTransaction.NTypeID = 0; sqlRewardsTransaction.StrMembershipID = strIntroducerID; sqlRewardsTransaction.StrReferenceNo = strMembershipID; sqlRewardsTransaction.Insert(); for (int i=0;i<5;i++) { sqlMember.InsertFWFChance(strIntroducerID); } connProvider.CommitTransaction(); return true; } catch (Exception ex) { connProvider.RollbackTransaction("SaveIntroduceFriend"); if (ex.InnerException.Message.IndexOf("FK_tblMember_tblMember") >= 0 || ex.Message.IndexOf("FK_tblMember_tblMember") >= 0 || ex.InnerException.Message.IndexOf("FK_tblRewardsTransaction_tblMember") >= 0 || ex.Message.IndexOf("FK_tblRewardsTransaction_tblMember") >= 0) { ACMS.Utils.UI.ShowErrorMessage(null, "Please enter a valid Membership ID.", "Error"); return false; } else throw; } finally { if (connProvider.CurrentTransaction != null) connProvider.CurrentTransaction.Dispose(); if (connProvider.DBConnection != null) { if (connProvider.DBConnection.State == ConnectionState.Open) connProvider.DBConnection.Close(); connProvider.DBConnection.Dispose(); } sqlRewardsTransaction.Dispose(); sqlMember.Dispose(); } }