private Int64 UpdateTran(CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMCustomerAddressInfo_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, "@CustomerAddressInfoID", DbType.Int64, cRMCustomerAddressInfoEntity.CustomerAddressInfoID); db.AddInParameter(cmd, "@CustomerID", DbType.Int64, cRMCustomerAddressInfoEntity.CustomerID); db.AddInParameter(cmd, "@CustomerAddressTypeID", DbType.Int64, cRMCustomerAddressInfoEntity.CustomerAddressTypeID); db.AddInParameter(cmd, "@AddressLine1", DbType.String, cRMCustomerAddressInfoEntity.AddressLine1); db.AddInParameter(cmd, "@AddressLine2", DbType.String, cRMCustomerAddressInfoEntity.AddressLine2); db.AddInParameter(cmd, "@CountryID", DbType.Int64, cRMCustomerAddressInfoEntity.CountryID); db.AddInParameter(cmd, "@CityID", DbType.Int64, cRMCustomerAddressInfoEntity.CityID); db.AddInParameter(cmd, "@ZipCode", DbType.String, cRMCustomerAddressInfoEntity.ZipCode); db.AddInParameter(cmd, "@Phone", DbType.String, cRMCustomerAddressInfoEntity.Phone); db.AddInParameter(cmd, "@Email", DbType.String, cRMCustomerAddressInfoEntity.Email); db.AddInParameter(cmd, "@WebLink", DbType.String, cRMCustomerAddressInfoEntity.WebLink); 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); }
Int64 ICRMCustomerAddressInfoDataAccess.Add(CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Add(cRMCustomerAddressInfoEntity, option); break; } case TransactionRequired.Yes: { retValues = AddTran(cRMCustomerAddressInfoEntity, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private CRMCustomerAddressInfoEntity BuildCRMCustomerAddressInfoEntity() { CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity = CurrentCRMCustomerAddressInfoEntity; if (ddlCustomerID.Items.Count > 0) { if (ddlCustomerID.SelectedValue == "0") { } else { cRMCustomerAddressInfoEntity.CustomerID = Int64.Parse(ddlCustomerID.SelectedValue); } } if (ddlCustomerAddressTypeID.Items.Count > 0) { if (ddlCustomerAddressTypeID.SelectedValue == "0") { } else { cRMCustomerAddressInfoEntity.CustomerAddressTypeID = Int64.Parse(ddlCustomerAddressTypeID.SelectedValue); } } cRMCustomerAddressInfoEntity.AddressLine1 = txtAddressLine1.Text.Trim(); cRMCustomerAddressInfoEntity.AddressLine2 = txtAddressLine2.Text.Trim(); if (ddlCountryID.Items.Count > 0) { if (ddlCountryID.SelectedValue == "0") { cRMCustomerAddressInfoEntity.CountryID = null; } else { cRMCustomerAddressInfoEntity.CountryID = Int64.Parse(ddlCountryID.SelectedValue); } } if (ddlCityID.Items.Count > 0) { if (ddlCityID.SelectedValue == "0") { cRMCustomerAddressInfoEntity.CityID = null; } else { cRMCustomerAddressInfoEntity.CityID = Int64.Parse(ddlCityID.SelectedValue); } } cRMCustomerAddressInfoEntity.ZipCode = txtZipCode.Text.Trim(); cRMCustomerAddressInfoEntity.Phone = txtPhone.Text.Trim(); cRMCustomerAddressInfoEntity.Email = txtEmail.Text.Trim(); cRMCustomerAddressInfoEntity.WebLink = txtWebLink.Text.Trim(); return(cRMCustomerAddressInfoEntity); }
private void SaveCRMCustomerAddressInfoEntity() { if (IsValid) { try { CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity = BuildCRMCustomerAddressInfoEntity(); Int64 result = -1; if (cRMCustomerAddressInfoEntity.IsNew) { result = FCCCRMCustomerAddressInfo.GetFacadeCreate().Add(cRMCustomerAddressInfoEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(CRMCustomerAddressInfoEntity.FLD_NAME_CustomerAddressInfoID, cRMCustomerAddressInfoEntity.CustomerAddressInfoID.ToString(), SQLMatchType.Equal); result = FCCCRMCustomerAddressInfo.GetFacadeCreate().Update(cRMCustomerAddressInfoEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } if (result > 0) { _CustomerAddressInfoID = 0; _CRMCustomerAddressInfoEntity = new CRMCustomerAddressInfoEntity(); PrepareInitialView(); BindCRMCustomerAddressInfoList(); if (cRMCustomerAddressInfoEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "C RMCustomer Address Info Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "C RMCustomer Address Info Information has been updated successfully.", false); } } else { if (cRMCustomerAddressInfoEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add C RMCustomer Address Info Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update C RMCustomer Address Info Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
protected void lvCRMCustomerAddressInfo_ItemCommand(object sender, ListViewCommandEventArgs e) { Int64 CustomerAddressInfoID; Int64.TryParse(e.CommandArgument.ToString(), out CustomerAddressInfoID); if (CustomerAddressInfoID > 0) { if (string.Equals(e.CommandName, "EditItem")) { _CustomerAddressInfoID = CustomerAddressInfoID; PrepareEditView(); cpeEditor.Collapsed = false; cpeEditor.ClientState = "false"; } else if (string.Equals(e.CommandName, "DeleteItem")) { try { Int64 result = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(CRMCustomerAddressInfoEntity.FLD_NAME_CustomerAddressInfoID, CustomerAddressInfoID.ToString(), SQLMatchType.Equal); CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity = new CRMCustomerAddressInfoEntity(); result = FCCCRMCustomerAddressInfo.GetFacadeCreate().Delete(cRMCustomerAddressInfoEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No); if (result == 0) { _CustomerAddressInfoID = 0; _CRMCustomerAddressInfoEntity = new CRMCustomerAddressInfoEntity(); PrepareInitialView(); BindCRMCustomerAddressInfoList(); MiscUtil.ShowMessage(lblMessage, "C RMCustomer Address Info has been successfully deleted.", true); } else { MiscUtil.ShowMessage(lblMessage, "Failed to delete C RMCustomer Address Info.", true); } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } } }
private Int64 DeleteTran(CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMCustomerAddressInfo_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(CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMCustomerAddressInfo_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); Database.AddInParameter(cmd, "@CustomerAddressInfoID", DbType.Int64, cRMCustomerAddressInfoEntity.CustomerAddressInfoID); Database.AddInParameter(cmd, "@CustomerID", DbType.Int64, cRMCustomerAddressInfoEntity.CustomerID); Database.AddInParameter(cmd, "@CustomerAddressTypeID", DbType.Int64, cRMCustomerAddressInfoEntity.CustomerAddressTypeID); Database.AddInParameter(cmd, "@AddressLine1", DbType.String, cRMCustomerAddressInfoEntity.AddressLine1); Database.AddInParameter(cmd, "@AddressLine2", DbType.String, cRMCustomerAddressInfoEntity.AddressLine2); Database.AddInParameter(cmd, "@CountryID", DbType.Int64, cRMCustomerAddressInfoEntity.CountryID); Database.AddInParameter(cmd, "@CityID", DbType.Int64, cRMCustomerAddressInfoEntity.CityID); Database.AddInParameter(cmd, "@ZipCode", DbType.String, cRMCustomerAddressInfoEntity.ZipCode); Database.AddInParameter(cmd, "@Phone", DbType.String, cRMCustomerAddressInfoEntity.Phone); Database.AddInParameter(cmd, "@Email", DbType.String, cRMCustomerAddressInfoEntity.Email); Database.AddInParameter(cmd, "@WebLink", DbType.String, cRMCustomerAddressInfoEntity.WebLink); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("CRMCustomerAddressInfoEntity already exists. Please specify another CRMCustomerAddressInfoEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("CRMCustomerAddressInfoEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("CRMCustomerAddressInfoEntity already exists. Please specify another CRMCustomerAddressInfoEntity."); } } } } return(returnCode); }
private Int64 Delete(CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMCustomerAddressInfo_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("CRMCustomerAddressInfoEntity already exists. Please specify another CRMCustomerAddressInfoEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("CRMCustomerAddressInfoEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("CRMCustomerAddressInfoEntity already exists. Please specify another CRMCustomerAddressInfoEntity."); } } } } return(returnCode); }
private void PrepareEditView() { CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity = CurrentCRMCustomerAddressInfoEntity; if (!cRMCustomerAddressInfoEntity.IsNew) { if (ddlCustomerID.Items.Count > 0 && cRMCustomerAddressInfoEntity.CustomerID != null) { ddlCustomerID.SelectedValue = cRMCustomerAddressInfoEntity.CustomerID.ToString(); } if (ddlCustomerAddressTypeID.Items.Count > 0 && cRMCustomerAddressInfoEntity.CustomerAddressTypeID != null) { ddlCustomerAddressTypeID.SelectedValue = cRMCustomerAddressInfoEntity.CustomerAddressTypeID.ToString(); } txtAddressLine1.Text = cRMCustomerAddressInfoEntity.AddressLine1.ToString(); txtAddressLine2.Text = cRMCustomerAddressInfoEntity.AddressLine2.ToString(); if (ddlCountryID.Items.Count > 0 && cRMCustomerAddressInfoEntity.CountryID != null) { ddlCountryID.SelectedValue = cRMCustomerAddressInfoEntity.CountryID.ToString(); } if (ddlCityID.Items.Count > 0 && cRMCustomerAddressInfoEntity.CityID != null) { ddlCityID.SelectedValue = cRMCustomerAddressInfoEntity.CityID.ToString(); } txtZipCode.Text = cRMCustomerAddressInfoEntity.ZipCode.ToString(); txtPhone.Text = cRMCustomerAddressInfoEntity.Phone.ToString(); txtEmail.Text = cRMCustomerAddressInfoEntity.Email.ToString(); txtWebLink.Text = cRMCustomerAddressInfoEntity.WebLink.ToString(); btnSubmit.Text = "Update"; btnAddNew.Visible = true; } }
Int64 ICRMCustomerAddressInfoFacade.Delete(CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateCRMCustomerAddressInfoDataAccess().Delete(cRMCustomerAddressInfoEntity, filterExpression, option, reqTran)); }
Int64 ICRMCustomerAddressInfoFacade.Add(CRMCustomerAddressInfoEntity cRMCustomerAddressInfoEntity, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateCRMCustomerAddressInfoDataAccess().Add(cRMCustomerAddressInfoEntity, option, reqTran)); }
protected void btnAddNew_Click(object sender, EventArgs e) { _CustomerAddressInfoID = 0; _CRMCustomerAddressInfoEntity = new CRMCustomerAddressInfoEntity(); PrepareInitialView(); }