Int64 ICRMCustomerDataAccess.Add(CRMCustomerEntity cRMCustomerEntity, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Add(cRMCustomerEntity, option); break; } case TransactionRequired.Yes: { retValues = AddTran(cRMCustomerEntity, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private Int64 UpdateTran(CRMCustomerEntity cRMCustomerEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMCustomer_SET"; Database db = DatabaseFactory.CreateDatabase(); using (DbCommand cmd = db.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option, db); AddOutputParameter(cmd, db); AddFilterExpressionParameter(cmd, filterExpression, db); db.AddInParameter(cmd, "@CustomerID", DbType.Int64, cRMCustomerEntity.CustomerID); db.AddInParameter(cmd, "@FirstName", DbType.String, cRMCustomerEntity.FirstName); db.AddInParameter(cmd, "@MiddleName", DbType.String, cRMCustomerEntity.MiddleName); db.AddInParameter(cmd, "@LastName", DbType.String, cRMCustomerEntity.LastName); db.AddInParameter(cmd, "@PrimaryEmail", DbType.String, cRMCustomerEntity.PrimaryEmail); db.AddInParameter(cmd, "@SecondaryEmail", DbType.String, cRMCustomerEntity.SecondaryEmail); db.AddInParameter(cmd, "@Phone", DbType.String, cRMCustomerEntity.Phone); db.AddInParameter(cmd, "@Fax", DbType.String, cRMCustomerEntity.Fax); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { using (IDataReader reader = db.ExecuteReader(cmd, transaction)) { returnCode = GetReturnCodeFromParameter(cmd); } if (returnCode > 0) { transaction.Commit(); } else { throw new ArgumentException("Error Code." + returnCode.ToString()); } } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { transaction.Dispose(); connection.Close(); connection = null; } } return(returnCode); }
private void SaveCRMCustomerEntity() { if (IsValid) { try { CRMCustomerEntity cRMCustomerEntity = BuildCRMCustomerEntity(); Int64 result = -1; if (cRMCustomerEntity.IsNew) { result = FCCCRMCustomer.GetFacadeCreate().Add(cRMCustomerEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(CRMCustomerEntity.FLD_NAME_CustomerID, cRMCustomerEntity.CustomerID.ToString(), SQLMatchType.Equal); result = FCCCRMCustomer.GetFacadeCreate().Update(cRMCustomerEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } if (result > 0) { _CustomerID = 0; _CRMCustomerEntity = new CRMCustomerEntity(); PrepareInitialView(); BindCRMCustomerList(); if (cRMCustomerEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "C RMCustomer Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "C RMCustomer Information has been updated successfully.", false); } } else { if (cRMCustomerEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add C RMCustomer Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update C RMCustomer Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
protected void lvCRMCustomer_ItemCommand(object sender, ListViewCommandEventArgs e) { Int64 CustomerID; Int64.TryParse(e.CommandArgument.ToString(), out CustomerID); if (CustomerID > 0) { if (string.Equals(e.CommandName, "EditItem")) { _CustomerID = CustomerID; PrepareEditView(); cpeEditor.Collapsed = false; cpeEditor.ClientState = "false"; } else if (string.Equals(e.CommandName, "DeleteItem")) { try { Int64 result = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(CRMCustomerEntity.FLD_NAME_CustomerID, CustomerID.ToString(), SQLMatchType.Equal); CRMCustomerEntity cRMCustomerEntity = new CRMCustomerEntity(); result = FCCCRMCustomer.GetFacadeCreate().Delete(cRMCustomerEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No); if (result == 0) { _CustomerID = 0; _CRMCustomerEntity = new CRMCustomerEntity(); PrepareInitialView(); BindCRMCustomerList(); MiscUtil.ShowMessage(lblMessage, "C RMCustomer has been successfully deleted.", true); } else { MiscUtil.ShowMessage(lblMessage, "Failed to delete C RMCustomer.", true); } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } } }
private CRMCustomerEntity BuildCRMCustomerEntity() { CRMCustomerEntity cRMCustomerEntity = CurrentCRMCustomerEntity; cRMCustomerEntity.FirstName = txtFirstName.Text.Trim(); cRMCustomerEntity.MiddleName = txtMiddleName.Text.Trim(); cRMCustomerEntity.LastName = txtLastName.Text.Trim(); cRMCustomerEntity.PrimaryEmail = txtPrimaryEmail.Text.Trim(); cRMCustomerEntity.SecondaryEmail = txtSecondaryEmail.Text.Trim(); cRMCustomerEntity.Phone = txtPhone.Text.Trim(); cRMCustomerEntity.Fax = txtFax.Text.Trim(); return(cRMCustomerEntity); }
private Int64 DeleteTran(CRMCustomerEntity cRMCustomerEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMCustomer_SET"; Database db = DatabaseFactory.CreateDatabase(); using (DbCommand cmd = db.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd, db); AddFilterExpressionParameter(cmd, filterExpression, db); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { using (IDataReader reader = db.ExecuteReader(cmd, transaction)) { returnCode = GetReturnCodeFromParameter(cmd); } if (returnCode >= 0) { transaction.Commit(); } else { throw new ArgumentException("Error Code." + returnCode.ToString()); } } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { transaction.Dispose(); connection.Close(); connection = null; } } return(returnCode); }
private Int64 Update(CRMCustomerEntity cRMCustomerEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMCustomer_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); Database.AddInParameter(cmd, "@CustomerID", DbType.Int64, cRMCustomerEntity.CustomerID); Database.AddInParameter(cmd, "@FirstName", DbType.String, cRMCustomerEntity.FirstName); Database.AddInParameter(cmd, "@MiddleName", DbType.String, cRMCustomerEntity.MiddleName); Database.AddInParameter(cmd, "@LastName", DbType.String, cRMCustomerEntity.LastName); Database.AddInParameter(cmd, "@PrimaryEmail", DbType.String, cRMCustomerEntity.PrimaryEmail); Database.AddInParameter(cmd, "@SecondaryEmail", DbType.String, cRMCustomerEntity.SecondaryEmail); Database.AddInParameter(cmd, "@Phone", DbType.String, cRMCustomerEntity.Phone); Database.AddInParameter(cmd, "@Fax", DbType.String, cRMCustomerEntity.Fax); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("CRMCustomerEntity already exists. Please specify another CRMCustomerEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("CRMCustomerEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("CRMCustomerEntity already exists. Please specify another CRMCustomerEntity."); } } } } return(returnCode); }
private void PrepareEditView() { CRMCustomerEntity cRMCustomerEntity = CurrentCRMCustomerEntity; if (!cRMCustomerEntity.IsNew) { txtFirstName.Text = cRMCustomerEntity.FirstName.ToString(); txtMiddleName.Text = cRMCustomerEntity.MiddleName.ToString(); txtLastName.Text = cRMCustomerEntity.LastName.ToString(); txtPrimaryEmail.Text = cRMCustomerEntity.PrimaryEmail.ToString(); txtSecondaryEmail.Text = cRMCustomerEntity.SecondaryEmail.ToString(); txtPhone.Text = cRMCustomerEntity.Phone.ToString(); txtFax.Text = cRMCustomerEntity.Fax.ToString(); btnSubmit.Text = "Update"; btnAddNew.Visible = true; } }
private Int64 Delete(CRMCustomerEntity cRMCustomerEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMCustomer_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("CRMCustomerEntity already exists. Please specify another CRMCustomerEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("CRMCustomerEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("CRMCustomerEntity already exists. Please specify another CRMCustomerEntity."); } } } } return(returnCode); }
protected void btnAddNew_Click(object sender, EventArgs e) { _CustomerID = 0; _CRMCustomerEntity = new CRMCustomerEntity(); PrepareInitialView(); }
Int64 ICRMCustomerFacade.Delete(CRMCustomerEntity cRMCustomerEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateCRMCustomerDataAccess().Delete(cRMCustomerEntity, filterExpression, option, reqTran)); }
Int64 ICRMCustomerFacade.Add(CRMCustomerEntity cRMCustomerEntity, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateCRMCustomerDataAccess().Add(cRMCustomerEntity, option, reqTran)); }