private void simpleButtonOK_Click(object sender, System.EventArgs e) { //Must Select A Leave Type if (lkpEdtLeaveType.Text.Length == 0) { MessageBox.Show(this, "Please select a Leave Type."); this.DialogResult = DialogResult.None; return; } if (lkpEdtLeaveType.Text != "0") { //For Case Other Only, the End Date Selected must be later than the current Expiry Date if (lkpEdtLeaveType.Text == "OTHER") { if (DateTime.Compare(dtEdtLeaveEndDate.DateTime.Date, ACMS.Convert.ToDBDateTime(myExpiryDate)) < 0) { MessageBox.Show(this, "New expiry date must be after current expiry date.", this.Text); this.DialogResult = DialogResult.None; return; } dtEdtLeaveStartDate.DateTime = ACMS.Convert.ToDBDateTime(myExpiryDate); //Need to Change this to refer to the expiry date passed in //Remarks must not empty if (txtOther.Text == "") { MessageBox.Show(this, "Remarks cannot be empty.", this.Text); this.DialogResult = DialogResult.None; return; } } else { //Empty remarks txtOther.Text = ""; } //Start Date Selected must be greater than the End Date Selected if (DateTime.Compare(dtEdtLeaveStartDate.DateTime.Date, dtEdtLeaveEndDate.DateTime.Date) > 0) { MessageBox.Show(this, "Start Date must earlier than end date"); this.DialogResult = DialogResult.None; return; } //Start Date Selected must be greater than Credit Package Start Date if ((DateTime.Compare(ACMS.Convert.ToDBDateTime(myStartDate), dtEdtLeaveStartDate.DateTime.Date) > 0 || DateTime.Compare(ACMS.Convert.ToDBDateTime(myStartDate), dtEdtLeaveStartDate.DateTime.Date) == 0) && lkpEdtLeaveType.Text != "OTHER") { MessageBox.Show(this, "Leave start date must be after package start date"); this.DialogResult = DialogResult.None; return; } //Start Date cannot be later than the current Credit package expiry Date if (DateTime.Compare(dtEdtLeaveStartDate.DateTime.Date, ACMS.Convert.ToDBDateTime(myExpiryDate)) > 0) { MessageBox.Show(this, "Extension Start Date cannot be later than Member's Credit Package Expiry Date."); this.DialogResult = DialogResult.None; return; } //Minimum 3 days extension if ((dtEdtLeaveEndDate.DateTime.Date - dtEdtLeaveStartDate.DateTime.Date).TotalDays < 3) { MessageBox.Show(this, "Minimum extension of 3 days is required."); this.DialogResult = DialogResult.None; return; } } //Get Extension history for current credit package TblCreditPackageExtension CreditPkgExtension = new TblCreditPackageExtension(); CreditPkgExtension.NCreditPackageID = myMemberCreditPackageID; DataTable dtCreditPkgExtension = CreditPkgExtension.SelectAllWnCreditPackageIDLogic(); DateTime ExtStartDate = dtEdtLeaveStartDate.DateTime.Date; DateTime ExtEndDate = dtEdtLeaveEndDate.DateTime.Date; if (dtCreditPkgExtension != null && dtCreditPkgExtension.Rows.Count > 0) { int r; //Loop through the extension history for the selected credit package for (r = 0; r <= dtCreditPkgExtension.Rows.Count - 1; r++) { //To See If Overlapped date in extension package if (ExtStartDate < ACMS.Convert.ToDateTime(dtCreditPkgExtension.Rows[r]["dtEndDate"]) && ExtEndDate >= ACMS.Convert.ToDateTime(dtCreditPkgExtension.Rows[r]["dtStartDate"]) || (ExtEndDate < ExtStartDate)) { MessageBox.Show(this, "Overlapped date in extension credit package."); this.DialogResult = DialogResult.None; return; } } } try { //Create New Credit Package Extension TimeSpan nDaysExtend = Convert.ToDateTime(ExtEndDate).Subtract(Convert.ToDateTime(ExtStartDate)); int nDaysExtended = Convert.ToInt32(nDaysExtend.TotalDays) + 1; DateTime dtOldExpiry = Convert.ToDateTime(myExpiryDate); DateTime dtNewExpiry = dtOldExpiry.AddDays(nDaysExtend.TotalDays + 1); DateTime dtCreateDate = System.DateTime.Now; DateTime dtStartDate = dtEdtLeaveStartDate.DateTime.Date; DateTime dtEndDate = dtEdtLeaveEndDate.DateTime.Date; int nStatusID = 0; int nReasonID = Convert.ToInt32(lkpEdtLeaveType.EditValue); string strRemarks = txtOther.Text.ToString(); int nEmployeeID = curEmployeeID; int nCreditPackageID = myMemberCreditPackageID; SaveExtensionHistory(nCreditPackageID, curMembershipID, dtOldExpiry, dtNewExpiry, dtStartDate, dtEndDate, nDaysExtended, nStatusID, nReasonID, strRemarks, nEmployeeID, dtCreateDate); } catch (Exception ex) { this.DialogResult = DialogResult.None; MessageBox.Show(this, ex.Message); } }
private void SaveExtensionHistory(int nCreditPackageID, string strMembershipID, DateTime dtOldExpiry, DateTime dtNewExpiry, DateTime dtStartDate, DateTime dtEndDate, int nDaysExtended, int nStatusID, int nReasonID, string strRemarks, int nEmployeeID, DateTime dtCreateDate) { int nCreditPackageStatusID = -1; if (DateTime.Compare(dtNewExpiry, DateTime.Now) > 0) { nCreditPackageStatusID = 0; } ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider(); TblMemberCreditPackage myMemberCreditPackage = new TblMemberCreditPackage(); TblCreditPackageExtension myCreditPackageExtension = new TblCreditPackageExtension(); myMemberCreditPackage.MainConnectionProvider = connProvider; myCreditPackageExtension.MainConnectionProvider = connProvider; connProvider.OpenConnection(); connProvider.BeginTransaction("SaveCreditPackageExtension"); try { //Update MemberCreditPackage - New Expiry Date & Status ID by nCreditPackageID myMemberCreditPackage.MemberCreditPackage_ExtensionUpdate(nCreditPackageID, nCreditPackageStatusID, dtNewExpiry, strMembershipID); //Add Record to Credit Package Extension myCreditPackageExtension.NCreditPackageID = nCreditPackageID; myCreditPackageExtension.DtOldExpiry = dtOldExpiry; myCreditPackageExtension.DtNewExpiry = dtNewExpiry; myCreditPackageExtension.DtStartDate = dtStartDate; myCreditPackageExtension.DtEndDate = dtEndDate; myCreditPackageExtension.NDaysExtended = nDaysExtended; myCreditPackageExtension.NStatusID = nStatusID; myCreditPackageExtension.NReasonID = nReasonID; myCreditPackageExtension.StrRemarks = strRemarks; myCreditPackageExtension.NEmployeeID = nEmployeeID; myCreditPackageExtension.Insert(); //Commit Transaction connProvider.CommitTransaction(); //*** Remember to Disable the Update Expiry Button for Credit Packages } catch { //RollBack Transaction connProvider.RollbackTransaction("SaveCreditPackageExtension"); } finally { //connProvider.CurrentTransaction.Dispose(); //connProvider.DBConnection.Close(); if (connProvider.CurrentTransaction != null) { connProvider.CurrentTransaction.Dispose(); } if (connProvider.DBConnection != null) { if (connProvider.DBConnection.State == ConnectionState.Open) { connProvider.DBConnection.Close(); } } myMemberCreditPackage.MainConnactionIsCreatedLocal = true; myCreditPackageExtension.MainConnactionIsCreatedLocal = true; } }
public void DeleteLastCreditPackageExtensionHistory(int nCreditPackageID, int last_nExtensionID, string CurrentMembershipID) { ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider(); TblMemberCreditPackage myMemberCreditPackage = new TblMemberCreditPackage(); TblCreditPackageExtension myCreditPackageExtension = new TblCreditPackageExtension(); myMemberCreditPackage.MainConnectionProvider = connProvider; myCreditPackageExtension.MainConnectionProvider = connProvider; connProvider.OpenConnection(); connProvider.BeginTransaction("SaveCreditPackageExtension"); myCreditPackageExtension.NCreditPackageID = nCreditPackageID; DataTable tblCreditPackageExtension = myCreditPackageExtension.SelectAllWnCreditPackageIDLogic(); if (tblCreditPackageExtension == null) { throw new Exception("This extension row has been deleted by others"); } else if (tblCreditPackageExtension.Rows.Count == 0) { throw new Exception("This extension row has been deleted by others"); } if (tblCreditPackageExtension.Rows.Count > 0) { DataRow[] rowList = tblCreditPackageExtension.Select(" nStatusID = 0 AND nExtensionID > " + last_nExtensionID.ToString()); if (rowList.Length > 0) // mean is not last package extension { throw new Exception("Only the most recent package extension can be deleted."); } } DataRow[] deletedDataRowList = tblCreditPackageExtension.Select("nStatusID = 0 and nExtensionID = " + last_nExtensionID, "nExtensionID", DataViewRowState.CurrentRows); if (deletedDataRowList.Length == 0) { throw new Exception("This extension row has been deleted by others"); } DateTime dtOldExpiry = Convert.ToDateTime(deletedDataRowList[0]["dtOldExpiry"]); int nCreditPackageStatusID = -1; if (DateTime.Compare(dtOldExpiry, DateTime.Now) < 0) { nCreditPackageStatusID = 1; } try { //Update Credit Package Extension set nStatusID = 1 => Deleted myCreditPackageExtension.MemberCreditPackage_ExtensionDelete(nCreditPackageID, last_nExtensionID); //Update Member Credit Package Expiry Date; nStatusID = 1 If Expired myMemberCreditPackage.MemberCreditPackage_ExtensionUpdate(nCreditPackageID, nCreditPackageStatusID, dtOldExpiry, CurrentMembershipID); connProvider.CommitTransaction(); } catch (Exception) { connProvider.RollbackTransaction("SaveCreditPackageExtension"); throw new Exception("Failed to Create New Extension"); } finally { if (connProvider.CurrentTransaction != null) { connProvider.CurrentTransaction.Dispose(); } if (connProvider.DBConnection != null) { if (connProvider.DBConnection.State == ConnectionState.Open) { connProvider.DBConnection.Close(); } } myMemberCreditPackage.MainConnactionIsCreatedLocal = true; myCreditPackageExtension.MainConnactionIsCreatedLocal = true; } }