Int64 ICRMLandOwnerDataAccess.Add(CRMLandOwnerEntity cRMLandOwnerEntity, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Add(cRMLandOwnerEntity, option); break; } case TransactionRequired.Yes: { retValues = AddTran(cRMLandOwnerEntity, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private void SaveCRMLandOwnerEntity() { if (IsValid) { try { CRMLandOwnerEntity cRMLandOwnerEntity = BuildCRMLandOwnerEntity(); Int64 result = -1; if (cRMLandOwnerEntity.IsNew) { result = FCCCRMLandOwner.GetFacadeCreate().Add(cRMLandOwnerEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(CRMLandOwnerEntity.FLD_NAME_LandOwnerID, cRMLandOwnerEntity.LandOwnerID.ToString(), SQLMatchType.Equal); result = FCCCRMLandOwner.GetFacadeCreate().Update(cRMLandOwnerEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } if (result > 0) { _LandOwnerID = 0; _CRMLandOwnerEntity = new CRMLandOwnerEntity(); PrepareInitialView(); BindCRMLandOwnerList(); if (cRMLandOwnerEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Landowner Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "Landowner Information has been updated successfully.", false); } } else { if (cRMLandOwnerEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add Landowner Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update Landowner Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
private Int64 Update(CRMLandOwnerEntity cRMLandOwnerEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMLandOwner_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); Database.AddInParameter(cmd, "@LandOwnerID", DbType.Int64, cRMLandOwnerEntity.LandOwnerID); Database.AddInParameter(cmd, "@LandBasicInfoID", DbType.Int64, cRMLandOwnerEntity.LandBasicInfoID); Database.AddInParameter(cmd, "@OwnerName", DbType.String, cRMLandOwnerEntity.OwnerName); Database.AddInParameter(cmd, "@ImageUrl", DbType.String, cRMLandOwnerEntity.ImageUrl); Database.AddInParameter(cmd, "@OwnPercentage", DbType.Decimal, cRMLandOwnerEntity.OwnPercentage); Database.AddInParameter(cmd, "@MobileNo", DbType.String, cRMLandOwnerEntity.MobileNo); Database.AddInParameter(cmd, "@LandPhone", DbType.String, cRMLandOwnerEntity.LandPhone); Database.AddInParameter(cmd, "@PresentAddress", DbType.String, cRMLandOwnerEntity.PresentAddress); Database.AddInParameter(cmd, "@FatherName", DbType.String, cRMLandOwnerEntity.FatherName); Database.AddInParameter(cmd, "@MotherName", DbType.String, cRMLandOwnerEntity.MotherName); Database.AddInParameter(cmd, "@SpouseName", DbType.String, cRMLandOwnerEntity.SpouseName); Database.AddInParameter(cmd, "@DateOfBirth", DbType.DateTime, cRMLandOwnerEntity.DateOfBirth); Database.AddInParameter(cmd, "@Email", DbType.String, cRMLandOwnerEntity.Email); Database.AddInParameter(cmd, "@BusinessDetails", DbType.String, cRMLandOwnerEntity.BusinessDetails); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("CRMLandOwnerEntity already exists. Please specify another CRMLandOwnerEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("CRMLandOwnerEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("CRMLandOwnerEntity already exists. Please specify another CRMLandOwnerEntity."); } } } } return(returnCode); }
protected void lvCRMLandOwner_ItemCommand(object sender, ListViewCommandEventArgs e) { Int64 LandOwnerID; Int64.TryParse(e.CommandArgument.ToString(), out LandOwnerID); if (LandOwnerID > 0) { if (string.Equals(e.CommandName, "EditItem")) { _LandOwnerID = LandOwnerID; PrepareEditView(); cpeEditor.Collapsed = false; cpeEditor.ClientState = "false"; } else if (string.Equals(e.CommandName, "DeleteItem")) { try { Int64 result = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(CRMLandOwnerEntity.FLD_NAME_LandOwnerID, LandOwnerID.ToString(), SQLMatchType.Equal); CRMLandOwnerEntity cRMLandOwnerEntity = new CRMLandOwnerEntity(); result = FCCCRMLandOwner.GetFacadeCreate().Delete(cRMLandOwnerEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No); if (result == 0) { _LandOwnerID = 0; _CRMLandOwnerEntity = new CRMLandOwnerEntity(); PrepareInitialView(); BindCRMLandOwnerList(); MiscUtil.ShowMessage(lblMessage, "C RMLandowner has been successfully deleted.", true); } else { MiscUtil.ShowMessage(lblMessage, "Failed to delete C RMLandowner.", true); } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } } }
private Int64 DeleteTran(CRMLandOwnerEntity cRMLandOwnerEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMLandOwner_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 Delete(CRMLandOwnerEntity cRMLandOwnerEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMLandOwner_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("CRMLandOwnerEntity already exists. Please specify another CRMLandOwnerEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("CRMLandOwnerEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("CRMLandOwnerEntity already exists. Please specify another CRMLandOwnerEntity."); } } } } return(returnCode); }
private void PrepareEditView() { CRMLandOwnerEntity cRMLandOwnerEntity = CurrentCRMLandOwnerEntity; if (!cRMLandOwnerEntity.IsNew) { txtOwnerName.Text = cRMLandOwnerEntity.OwnerName.ToString(); txtOwnPercentage.Text = cRMLandOwnerEntity.OwnPercentage.ToString(); txtMobileNo.Text = cRMLandOwnerEntity.MobileNo.ToString(); txtLandPhone.Text = cRMLandOwnerEntity.LandPhone.ToString(); txtPresentAddress.Text = cRMLandOwnerEntity.PresentAddress.ToString(); txtFatherName.Text = cRMLandOwnerEntity.FatherName.ToString(); txtMotherName.Text = cRMLandOwnerEntity.MotherName.ToString(); txtSpouseName.Text = cRMLandOwnerEntity.SpouseName.ToString(); txtDateOfBirth.Text = cRMLandOwnerEntity.DateOfBirth.ToStringDefault(); txtEmail.Text = cRMLandOwnerEntity.Email.ToString(); txtBusinessDetails.Text = cRMLandOwnerEntity.BusinessDetails.ToString(); btnSubmit.Text = "Update"; btnAddNew.Visible = true; } }
Int64 ICRMLandOwnerFacade.Delete(CRMLandOwnerEntity cRMLandOwnerEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateCRMLandOwnerDataAccess().Delete(cRMLandOwnerEntity, filterExpression, option, reqTran)); }
Int64 ICRMLandOwnerFacade.Add(CRMLandOwnerEntity cRMLandOwnerEntity, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateCRMLandOwnerDataAccess().Add(cRMLandOwnerEntity, option, reqTran)); }
private Int64 UpdateTran(CRMLandOwnerEntity cRMLandOwnerEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CRMLandOwner_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, "@LandOwnerID", DbType.Int64, cRMLandOwnerEntity.LandOwnerID); db.AddInParameter(cmd, "@LandBasicInfoID", DbType.Int64, cRMLandOwnerEntity.LandBasicInfoID); db.AddInParameter(cmd, "@OwnerName", DbType.String, cRMLandOwnerEntity.OwnerName); db.AddInParameter(cmd, "@ImageUrl", DbType.String, cRMLandOwnerEntity.ImageUrl); db.AddInParameter(cmd, "@OwnPercentage", DbType.Decimal, cRMLandOwnerEntity.OwnPercentage); db.AddInParameter(cmd, "@MobileNo", DbType.String, cRMLandOwnerEntity.MobileNo); db.AddInParameter(cmd, "@LandPhone", DbType.String, cRMLandOwnerEntity.LandPhone); db.AddInParameter(cmd, "@PresentAddress", DbType.String, cRMLandOwnerEntity.PresentAddress); db.AddInParameter(cmd, "@FatherName", DbType.String, cRMLandOwnerEntity.FatherName); db.AddInParameter(cmd, "@MotherName", DbType.String, cRMLandOwnerEntity.MotherName); db.AddInParameter(cmd, "@SpouseName", DbType.String, cRMLandOwnerEntity.SpouseName); db.AddInParameter(cmd, "@DateOfBirth", DbType.DateTime, cRMLandOwnerEntity.DateOfBirth); db.AddInParameter(cmd, "@Email", DbType.String, cRMLandOwnerEntity.Email); db.AddInParameter(cmd, "@BusinessDetails", DbType.String, cRMLandOwnerEntity.BusinessDetails); 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); }
protected void btnAddNew_Click(object sender, EventArgs e) { _LandOwnerID = 0; _CRMLandOwnerEntity = new CRMLandOwnerEntity(); PrepareInitialView(); }
private CRMLandOwnerEntity BuildCRMLandOwnerEntity() { CRMLandOwnerEntity cRMLandOwnerEntity = CurrentCRMLandOwnerEntity; cRMLandOwnerEntity.LandBasicInfoID = CRMLandBasicInfoID; cRMLandOwnerEntity.OwnerName = txtOwnerName.Text.Trim(); String ImageUrlpath; if (fuImageUrl.HasFile == true && cRMLandOwnerEntity.ImageUrl.IsNotNullOrEmpty()) { if (File.Exists(Server.MapPath(cRMLandOwnerEntity.ImageUrl))) { File.Delete(Server.MapPath(cRMLandOwnerEntity.ImageUrl)); } ImageUrlpath = FileUploadConstants.CRM.LandOwner + Guid.NewGuid() + fuImageUrl.FileName; fuImageUrl.SaveAs(Server.MapPath(ImageUrlpath)); cRMLandOwnerEntity.ImageUrl = ImageUrlpath; } if (cRMLandOwnerEntity.ImageUrl.IsNotNullOrEmpty() && fuImageUrl.HasFile == false) { cRMLandOwnerEntity.ImageUrl = cRMLandOwnerEntity.ImageUrl; } if (fuImageUrl.HasFile == false && cRMLandOwnerEntity.ImageUrl.IsNullOrEmpty()) { cRMLandOwnerEntity.ImageUrl = null; } if (fuImageUrl.HasFile == true && cRMLandOwnerEntity.ImageUrl.IsNullOrEmpty()) { ImageUrlpath = FileUploadConstants.CRM.LandOwner + Guid.NewGuid() + fuImageUrl.FileName; fuImageUrl.SaveAs(Server.MapPath(ImageUrlpath)); cRMLandOwnerEntity.ImageUrl = ImageUrlpath; } if (!txtOwnPercentage.Text.Trim().IsNullOrEmpty()) { cRMLandOwnerEntity.OwnPercentage = Decimal.Parse(txtOwnPercentage.Text.Trim()); } else { cRMLandOwnerEntity.OwnPercentage = null; } cRMLandOwnerEntity.MobileNo = txtMobileNo.Text.Trim(); cRMLandOwnerEntity.LandPhone = txtLandPhone.Text.Trim(); cRMLandOwnerEntity.PresentAddress = txtPresentAddress.Text.Trim(); cRMLandOwnerEntity.FatherName = txtFatherName.Text.Trim(); cRMLandOwnerEntity.MotherName = txtMotherName.Text.Trim(); cRMLandOwnerEntity.SpouseName = txtSpouseName.Text.Trim(); if (txtDateOfBirth.Text.Trim().IsNotNullOrEmpty()) { cRMLandOwnerEntity.DateOfBirth = MiscUtil.ParseToDateTime(txtDateOfBirth.Text); } else { cRMLandOwnerEntity.DateOfBirth = null; } cRMLandOwnerEntity.Email = txtEmail.Text.Trim(); cRMLandOwnerEntity.BusinessDetails = txtBusinessDetails.Text.Trim(); return(cRMLandOwnerEntity); }