private BDOperatorEntity BuildBDOperatorEntity() { BDOperatorEntity bDOperatorEntity = CurrentBDOperatorEntity; bDOperatorEntity.OperatorCode = txtOperatorCode.Text.Trim(); bDOperatorEntity.OperatorName = txtOperatorName.Text.Trim(); bDOperatorEntity.Relationship = txtRelationship.Text.Trim(); bDOperatorEntity.Phone = txtPhone.Text.Trim(); bDOperatorEntity.MobileNo = txtMobileNo.Text.Trim(); bDOperatorEntity.Fax = txtFax.Text.Trim(); bDOperatorEntity.Email = txtEmail.Text.Trim(); bDOperatorEntity.WebLink = txtWebLink.Text.Trim(); bDOperatorEntity.CreateDate = System.DateTime.Now; bDOperatorEntity.Remarks = txtRemarks.Text.Trim(); bDOperatorEntity.Reason = txtReason.Text.Trim(); if (ddlOperatorStatusID.Items.Count > 0) { if (ddlOperatorStatusID.SelectedValue == "0") { } else { bDOperatorEntity.OperatorStatusID = Int64.Parse(ddlOperatorStatusID.SelectedValue); } } bDOperatorEntity.IsRemoved = chkIsRemoved.Checked; return(bDOperatorEntity); }
Int64 IBDOperatorDataAccess.Delete(BDOperatorEntity bDOperatorEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Delete(bDOperatorEntity, filterExpression, option); break; } case TransactionRequired.Yes: { retValues = DeleteTran(bDOperatorEntity, filterExpression, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private void PrepareEditView() { BDOperatorEntity bDOperatorEntity = CurrentBDOperatorEntity; if (!bDOperatorEntity.IsNew) { txtOperatorCode.Text = bDOperatorEntity.OperatorCode.ToString(); txtOperatorName.Text = bDOperatorEntity.OperatorName.ToString(); txtRelationship.Text = bDOperatorEntity.Relationship.ToString(); txtPhone.Text = bDOperatorEntity.Phone.ToString(); txtMobileNo.Text = bDOperatorEntity.MobileNo.ToString(); txtFax.Text = bDOperatorEntity.Fax.ToString(); txtEmail.Text = bDOperatorEntity.Email.ToString(); txtWebLink.Text = bDOperatorEntity.WebLink.ToString(); txtRemarks.Text = bDOperatorEntity.Remarks.ToString(); txtReason.Text = bDOperatorEntity.Reason.ToString(); if (ddlOperatorStatusID.Items.Count > 0 && bDOperatorEntity.OperatorStatusID != null) { ddlOperatorStatusID.SelectedValue = bDOperatorEntity.OperatorStatusID.ToString(); } chkIsRemoved.Checked = bDOperatorEntity.IsRemoved; btnSubmit.Text = "Update"; btnAddNew.Visible = true; } }
Int64 IBDOperatorDataAccess.Add(BDOperatorEntity bDOperatorEntity, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Add(bDOperatorEntity, option); break; } case TransactionRequired.Yes: { retValues = AddTran(bDOperatorEntity, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private void SaveBDOperatorEntity() { if (IsValid) { try { BDOperatorEntity bDOperatorEntity = BuildBDOperatorEntity(); Int64 result = -1; if (bDOperatorEntity.IsNew) { result = FCCBDOperator.GetFacadeCreate().Add(bDOperatorEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(BDOperatorEntity.FLD_NAME_OperatorID, bDOperatorEntity.OperatorID.ToString(), SQLMatchType.Equal); result = FCCBDOperator.GetFacadeCreate().Update(bDOperatorEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } if (result > 0) { _OperatorID = 0; _BDOperatorEntity = new BDOperatorEntity(); PrepareInitialView(); BindBDOperatorList(); if (bDOperatorEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Operator Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "Operator Information has been updated successfully.", false); } } else { if (bDOperatorEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add Operator Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update Operator Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
private Int64 Update(BDOperatorEntity bDOperatorEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.BDOperator_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); Database.AddInParameter(cmd, "@OperatorID", DbType.Int64, bDOperatorEntity.OperatorID); Database.AddInParameter(cmd, "@OperatorCode", DbType.String, bDOperatorEntity.OperatorCode); Database.AddInParameter(cmd, "@OperatorName", DbType.String, bDOperatorEntity.OperatorName); Database.AddInParameter(cmd, "@Relationship", DbType.String, bDOperatorEntity.Relationship); Database.AddInParameter(cmd, "@Phone", DbType.String, bDOperatorEntity.Phone); Database.AddInParameter(cmd, "@MobileNo", DbType.String, bDOperatorEntity.MobileNo); Database.AddInParameter(cmd, "@Fax", DbType.String, bDOperatorEntity.Fax); Database.AddInParameter(cmd, "@Email", DbType.String, bDOperatorEntity.Email); Database.AddInParameter(cmd, "@WebLink", DbType.String, bDOperatorEntity.WebLink); Database.AddInParameter(cmd, "@CreateDate", DbType.DateTime, bDOperatorEntity.CreateDate); Database.AddInParameter(cmd, "@Remarks", DbType.String, bDOperatorEntity.Remarks); Database.AddInParameter(cmd, "@Reason", DbType.String, bDOperatorEntity.Reason); Database.AddInParameter(cmd, "@OperatorStatusID", DbType.Int64, bDOperatorEntity.OperatorStatusID); Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, bDOperatorEntity.IsRemoved); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("BDOperatorEntity already exists. Please specify another BDOperatorEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("BDOperatorEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("BDOperatorEntity already exists. Please specify another BDOperatorEntity."); } } } } return(returnCode); }
protected void lvBDOperator_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; BDOperatorEntity ent = (BDOperatorEntity)dataItem.DataItem; HyperLink hypOperatorName = (HyperLink)e.Item.FindControl("hypOperatorName"); hypOperatorName.NavigateUrl = UrlHelper.BuildSecureUrl("~/BD/BDOperatorEditor.aspx", string.Empty, UrlConstants.OVERVIEW_OPERATOR_ID, ent.OperatorID.ToString()).ToString(); } }
protected void lvBDOperator_ItemCommand(object sender, ListViewCommandEventArgs e) { Int64 OperatorID; Int64.TryParse(e.CommandArgument.ToString(), out OperatorID); if (OperatorID > 0) { if (string.Equals(e.CommandName, "EditItem")) { _OperatorID = OperatorID; PrepareEditView(); cpeEditor.Collapsed = false; cpeEditor.ClientState = "false"; } else if (string.Equals(e.CommandName, "DeleteItem")) { try { Int64 result = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(BDOperatorEntity.FLD_NAME_OperatorID, OperatorID.ToString(), SQLMatchType.Equal); BDOperatorEntity bDOperatorEntity = new BDOperatorEntity(); result = FCCBDOperator.GetFacadeCreate().Delete(bDOperatorEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No); if (result == 0) { _OperatorID = 0; _BDOperatorEntity = new BDOperatorEntity(); PrepareInitialView(); BindBDOperatorList(); MiscUtil.ShowMessage(lblMessage, "Operator has been successfully deleted.", true); } else { MiscUtil.ShowMessage(lblMessage, "Failed to delete Operator.", true); } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } } }
private Int64 DeleteTran(BDOperatorEntity bDOperatorEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.BDOperator_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(BDOperatorEntity bDOperatorEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.BDOperator_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("BDOperatorEntity already exists. Please specify another BDOperatorEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("BDOperatorEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("BDOperatorEntity already exists. Please specify another BDOperatorEntity."); } } } } return(returnCode); }
protected void btnAddNew_Click(object sender, EventArgs e) { _OperatorID = 0; _BDOperatorEntity = new BDOperatorEntity(); PrepareInitialView(); }
private Int64 UpdateTran(BDOperatorEntity bDOperatorEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.BDOperator_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, "@OperatorID", DbType.Int64, bDOperatorEntity.OperatorID); db.AddInParameter(cmd, "@OperatorCode", DbType.String, bDOperatorEntity.OperatorCode); db.AddInParameter(cmd, "@OperatorName", DbType.String, bDOperatorEntity.OperatorName); db.AddInParameter(cmd, "@Relationship", DbType.String, bDOperatorEntity.Relationship); db.AddInParameter(cmd, "@Phone", DbType.String, bDOperatorEntity.Phone); db.AddInParameter(cmd, "@MobileNo", DbType.String, bDOperatorEntity.MobileNo); db.AddInParameter(cmd, "@Fax", DbType.String, bDOperatorEntity.Fax); db.AddInParameter(cmd, "@Email", DbType.String, bDOperatorEntity.Email); db.AddInParameter(cmd, "@WebLink", DbType.String, bDOperatorEntity.WebLink); db.AddInParameter(cmd, "@CreateDate", DbType.DateTime, bDOperatorEntity.CreateDate); db.AddInParameter(cmd, "@Remarks", DbType.String, bDOperatorEntity.Remarks); db.AddInParameter(cmd, "@Reason", DbType.String, bDOperatorEntity.Reason); db.AddInParameter(cmd, "@OperatorStatusID", DbType.Int64, bDOperatorEntity.OperatorStatusID); db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, bDOperatorEntity.IsRemoved); 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 IBDOperatorFacade.Delete(BDOperatorEntity bDOperatorEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateBDOperatorDataAccess().Delete(bDOperatorEntity, filterExpression, option, reqTran)); }
Int64 IBDOperatorFacade.Add(BDOperatorEntity bDOperatorEntity, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateBDOperatorDataAccess().Add(bDOperatorEntity, option, reqTran)); }