private Int64 AddTran(ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.ACItemGroupAccountMap_SET"; Database db = DatabaseFactory.CreateDatabase(); using (DbCommand cmd = db.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option, db); AddOutputParameter(cmd, db); AddNullPrimaryKeyParameter(cmd, "ItemGroupAccountMapID", db); db.AddInParameter(cmd, "@ItemCategoryID", DbType.Int64, aCItemGroupAccountMapEntity.ItemCategoryID); db.AddInParameter(cmd, "@DimensionID", DbType.Int64, aCItemGroupAccountMapEntity.DimensionID); db.AddInParameter(cmd, "@SalesAccountID", DbType.Int64, aCItemGroupAccountMapEntity.SalesAccountID); db.AddInParameter(cmd, "@InventoryAccountID", DbType.Int64, aCItemGroupAccountMapEntity.InventoryAccountID); db.AddInParameter(cmd, "@COGSAccountID", DbType.Int64, aCItemGroupAccountMapEntity.COGSAccountID); db.AddInParameter(cmd, "@InventoryAdjustmentsAccountID", DbType.Int64, aCItemGroupAccountMapEntity.InventoryAdjustmentsAccountID); db.AddInParameter(cmd, "@AssetType", DbType.String, aCItemGroupAccountMapEntity.AssetType); db.AddInParameter(cmd, "@PurchaseDate", DbType.DateTime, aCItemGroupAccountMapEntity.PurchaseDate); db.AddInParameter(cmd, "@PurchasePrice", DbType.Decimal, aCItemGroupAccountMapEntity.PurchasePrice); db.AddInParameter(cmd, "@DepreciationRate", DbType.Decimal, aCItemGroupAccountMapEntity.DepreciationRate); db.AddInParameter(cmd, "@DepreciationMethodID", DbType.Int64, aCItemGroupAccountMapEntity.DepreciationMethodID); db.AddInParameter(cmd, "@DepreciationAccountID", DbType.Int64, aCItemGroupAccountMapEntity.DepreciationAccountID); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { returnCode = db.ExecuteNonQuery(cmd, transaction); returnCode = GetReturnCodeFromParameter(cmd, db); 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 IACItemGroupAccountMapDataAccess.Add(ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Add(aCItemGroupAccountMapEntity, option); break; } case TransactionRequired.Yes: { retValues = AddTran(aCItemGroupAccountMapEntity, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private void PrepareEditView() { ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity = CurrentACItemGroupAccountMapEntity; if (!aCItemGroupAccountMapEntity.IsNew) { if (ddlItemCategoryID.Items.Count > 0 && aCItemGroupAccountMapEntity.ItemCategoryID != null) { ddlItemCategoryID.SelectedValue = aCItemGroupAccountMapEntity.ItemCategoryID.ToString(); } if (ddlDimensionID.Items.Count > 0 && aCItemGroupAccountMapEntity.DimensionID != null) { ddlDimensionID.SelectedValue = aCItemGroupAccountMapEntity.DimensionID.ToString(); } if (ddlSalesAccountID.Items.Count > 0 && aCItemGroupAccountMapEntity.SalesAccountID != null) { ddlSalesAccountID.SelectedValue = aCItemGroupAccountMapEntity.SalesAccountID.ToString(); } if (ddlInventoryAccountID.Items.Count > 0 && aCItemGroupAccountMapEntity.InventoryAccountID != null) { ddlInventoryAccountID.SelectedValue = aCItemGroupAccountMapEntity.InventoryAccountID.ToString(); } if (ddlCOGSAccountID.Items.Count > 0 && aCItemGroupAccountMapEntity.COGSAccountID != null) { ddlCOGSAccountID.SelectedValue = aCItemGroupAccountMapEntity.COGSAccountID.ToString(); } if (ddlInventoryAdjustmentsAccountID.Items.Count > 0 && aCItemGroupAccountMapEntity.InventoryAdjustmentsAccountID != null) { ddlInventoryAdjustmentsAccountID.SelectedValue = aCItemGroupAccountMapEntity.InventoryAdjustmentsAccountID.ToString(); } txtAssetType.Text = aCItemGroupAccountMapEntity.AssetType.ToString(); txtPurchaseDate.Text = aCItemGroupAccountMapEntity.PurchaseDate.ToStringDefault(); txtPurchasePrice.Text = aCItemGroupAccountMapEntity.PurchasePrice.ToString(); txtDepreciationRate.Text = aCItemGroupAccountMapEntity.DepreciationRate.ToString(); if (ddlDepreciationMethodID.Items.Count > 0 && aCItemGroupAccountMapEntity.DepreciationMethodID != null) { ddlDepreciationMethodID.SelectedValue = aCItemGroupAccountMapEntity.DepreciationMethodID.ToString(); } if (ddlDepreciationAccountID.Items.Count > 0 && aCItemGroupAccountMapEntity.DepreciationAccountID != null) { ddlDepreciationAccountID.SelectedValue = aCItemGroupAccountMapEntity.DepreciationAccountID.ToString(); } btnSubmit.Text = "Update"; btnAddNew.Visible = true; } }
private void SaveACItemGroupAccountMapEntity() { if (IsValid) { try { ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity = BuildACItemGroupAccountMapEntity(); Int64 result = -1; if (aCItemGroupAccountMapEntity.IsNew) { result = FCCACItemGroupAccountMap.GetFacadeCreate().Add(aCItemGroupAccountMapEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(ACItemGroupAccountMapEntity.FLD_NAME_ItemGroupAccountMapID, aCItemGroupAccountMapEntity.ItemGroupAccountMapID.ToString(), SQLMatchType.Equal); result = FCCACItemGroupAccountMap.GetFacadeCreate().Update(aCItemGroupAccountMapEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } if (result > 0) { _ItemGroupAccountMapID = 0; _ACItemGroupAccountMapEntity = new ACItemGroupAccountMapEntity(); PrepareInitialView(); BindACItemGroupAccountMapList(); if (aCItemGroupAccountMapEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "A CItem Group Account Map Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "A CItem Group Account Map Information has been updated successfully.", false); } } else { if (aCItemGroupAccountMapEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add A CItem Group Account Map Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update A CItem Group Account Map Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
private Int64 Update(ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.ACItemGroupAccountMap_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); Database.AddInParameter(cmd, "@ItemGroupAccountMapID", DbType.Int64, aCItemGroupAccountMapEntity.ItemGroupAccountMapID); Database.AddInParameter(cmd, "@ItemCategoryID", DbType.Int64, aCItemGroupAccountMapEntity.ItemCategoryID); Database.AddInParameter(cmd, "@DimensionID", DbType.Int64, aCItemGroupAccountMapEntity.DimensionID); Database.AddInParameter(cmd, "@SalesAccountID", DbType.Int64, aCItemGroupAccountMapEntity.SalesAccountID); Database.AddInParameter(cmd, "@InventoryAccountID", DbType.Int64, aCItemGroupAccountMapEntity.InventoryAccountID); Database.AddInParameter(cmd, "@COGSAccountID", DbType.Int64, aCItemGroupAccountMapEntity.COGSAccountID); Database.AddInParameter(cmd, "@InventoryAdjustmentsAccountID", DbType.Int64, aCItemGroupAccountMapEntity.InventoryAdjustmentsAccountID); Database.AddInParameter(cmd, "@AssetType", DbType.String, aCItemGroupAccountMapEntity.AssetType); Database.AddInParameter(cmd, "@PurchaseDate", DbType.DateTime, aCItemGroupAccountMapEntity.PurchaseDate); Database.AddInParameter(cmd, "@PurchasePrice", DbType.Decimal, aCItemGroupAccountMapEntity.PurchasePrice); Database.AddInParameter(cmd, "@DepreciationRate", DbType.Decimal, aCItemGroupAccountMapEntity.DepreciationRate); Database.AddInParameter(cmd, "@DepreciationMethodID", DbType.Int64, aCItemGroupAccountMapEntity.DepreciationMethodID); Database.AddInParameter(cmd, "@DepreciationAccountID", DbType.Int64, aCItemGroupAccountMapEntity.DepreciationAccountID); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("ACItemGroupAccountMapEntity already exists. Please specify another ACItemGroupAccountMapEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("ACItemGroupAccountMapEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("ACItemGroupAccountMapEntity already exists. Please specify another ACItemGroupAccountMapEntity."); } } } } return(returnCode); }
protected void lvACItemGroupAccountMap_ItemCommand(object sender, ListViewCommandEventArgs e) { Int64 ItemGroupAccountMapID; Int64.TryParse(e.CommandArgument.ToString(), out ItemGroupAccountMapID); if (ItemGroupAccountMapID > 0) { if (string.Equals(e.CommandName, "EditItem")) { _ItemGroupAccountMapID = ItemGroupAccountMapID; PrepareEditView(); cpeEditor.Collapsed = false; cpeEditor.ClientState = "false"; } else if (string.Equals(e.CommandName, "DeleteItem")) { try { Int64 result = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(ACItemGroupAccountMapEntity.FLD_NAME_ItemGroupAccountMapID, ItemGroupAccountMapID.ToString(), SQLMatchType.Equal); ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity = new ACItemGroupAccountMapEntity(); result = FCCACItemGroupAccountMap.GetFacadeCreate().Delete(aCItemGroupAccountMapEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No); if (result == 0) { _ItemGroupAccountMapID = 0; _ACItemGroupAccountMapEntity = new ACItemGroupAccountMapEntity(); PrepareInitialView(); BindACItemGroupAccountMapList(); MiscUtil.ShowMessage(lblMessage, "A CItem Group Account Map has been successfully deleted.", true); } else { MiscUtil.ShowMessage(lblMessage, "Failed to delete A CItem Group Account Map.", true); } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } } }
private Int64 DeleteTran(ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.ACItemGroupAccountMap_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(ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.ACItemGroupAccountMap_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("ACItemGroupAccountMapEntity already exists. Please specify another ACItemGroupAccountMapEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("ACItemGroupAccountMapEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("ACItemGroupAccountMapEntity already exists. Please specify another ACItemGroupAccountMapEntity."); } } } } return(returnCode); }
protected void btnAddNew_Click(object sender, EventArgs e) { _ItemGroupAccountMapID = 0; _ACItemGroupAccountMapEntity = new ACItemGroupAccountMapEntity(); PrepareInitialView(); }
private ACItemGroupAccountMapEntity BuildACItemGroupAccountMapEntity() { ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity = CurrentACItemGroupAccountMapEntity; if (ddlItemCategoryID.Items.Count > 0) { if (ddlItemCategoryID.SelectedValue == "0") { } else { aCItemGroupAccountMapEntity.ItemCategoryID = Int64.Parse(ddlItemCategoryID.SelectedValue); } } if (ddlDimensionID.Items.Count > 0) { if (ddlDimensionID.SelectedValue == "0") { aCItemGroupAccountMapEntity.DimensionID = null; } else { aCItemGroupAccountMapEntity.DimensionID = Int64.Parse(ddlDimensionID.SelectedValue); } } if (ddlSalesAccountID.Items.Count > 0) { if (ddlSalesAccountID.SelectedValue == "0") { aCItemGroupAccountMapEntity.SalesAccountID = null; } else { aCItemGroupAccountMapEntity.SalesAccountID = Int64.Parse(ddlSalesAccountID.SelectedValue); } } if (ddlInventoryAccountID.Items.Count > 0) { if (ddlInventoryAccountID.SelectedValue == "0") { aCItemGroupAccountMapEntity.InventoryAccountID = null; } else { aCItemGroupAccountMapEntity.InventoryAccountID = Int64.Parse(ddlInventoryAccountID.SelectedValue); } } if (ddlCOGSAccountID.Items.Count > 0) { if (ddlCOGSAccountID.SelectedValue == "0") { aCItemGroupAccountMapEntity.COGSAccountID = null; } else { aCItemGroupAccountMapEntity.COGSAccountID = Int64.Parse(ddlCOGSAccountID.SelectedValue); } } if (ddlInventoryAdjustmentsAccountID.Items.Count > 0) { if (ddlInventoryAdjustmentsAccountID.SelectedValue == "0") { aCItemGroupAccountMapEntity.InventoryAdjustmentsAccountID = null; } else { aCItemGroupAccountMapEntity.InventoryAdjustmentsAccountID = Int64.Parse(ddlInventoryAdjustmentsAccountID.SelectedValue); } } aCItemGroupAccountMapEntity.AssetType = txtAssetType.Text.Trim(); if (txtPurchaseDate.Text.Trim().IsNotNullOrEmpty()) { aCItemGroupAccountMapEntity.PurchaseDate = MiscUtil.ParseToDateTime(txtPurchaseDate.Text); } else { aCItemGroupAccountMapEntity.PurchaseDate = null; } if (!txtPurchasePrice.Text.Trim().IsNullOrEmpty()) { aCItemGroupAccountMapEntity.PurchasePrice = Decimal.Parse(txtPurchasePrice.Text.Trim()); } else { aCItemGroupAccountMapEntity.PurchasePrice = null; } if (!txtDepreciationRate.Text.Trim().IsNullOrEmpty()) { aCItemGroupAccountMapEntity.DepreciationRate = Decimal.Parse(txtDepreciationRate.Text.Trim()); } else { aCItemGroupAccountMapEntity.DepreciationRate = null; } if (ddlDepreciationMethodID.Items.Count > 0) { if (ddlDepreciationMethodID.SelectedValue == "0") { aCItemGroupAccountMapEntity.DepreciationMethodID = null; } else { aCItemGroupAccountMapEntity.DepreciationMethodID = Int64.Parse(ddlDepreciationMethodID.SelectedValue); } } if (ddlDepreciationAccountID.Items.Count > 0) { if (ddlDepreciationAccountID.SelectedValue == "0") { aCItemGroupAccountMapEntity.DepreciationAccountID = null; } else { aCItemGroupAccountMapEntity.DepreciationAccountID = Int64.Parse(ddlDepreciationAccountID.SelectedValue); } } return(aCItemGroupAccountMapEntity); }
Int64 IACItemGroupAccountMapFacade.Delete(ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateACItemGroupAccountMapDataAccess().Delete(aCItemGroupAccountMapEntity, filterExpression, option, reqTran)); }
Int64 IACItemGroupAccountMapFacade.Add(ACItemGroupAccountMapEntity aCItemGroupAccountMapEntity, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateACItemGroupAccountMapDataAccess().Add(aCItemGroupAccountMapEntity, option, reqTran)); }