using System; using System.Data; using OakLeaf.MM.Main.Business; using OakLeaf.MM.Main.Data; using OakLeaf.MM.Main; namespace Apps4u.WinApp.Business.Company { /// <summary> /// Main Company business object /// </summary> public class Company : OakLeaf.MM.Main.Business.mmBusinessObject { public Company() { /// /// Required for Windows.Forms Class Composition Designer support /// this.TableName = "company"; this.PrimaryKey = "companyID"; this.DatabaseKey = mmAppBase.AppSettingsMgr.GetSetting("SecurityDatabaseKey"); this.DescriptionFields = new string[] {"CompanyUserID","CompanyName"}; this.RetrieveAutoIncrementPK = true; } public DataSet GetAllCompanies() { return this.GetDataSet("GetAllCompanies", "Company", this.DatabaseKey, CommandType.StoredProcedure); } //****-> //****-> public DataSet CheckIfCompanyUserIdExists(string CompanyUserID) { // Get a reference to the data access object mmDataAccessBase dao = this.GetDataAccessObject(); // Create and configure two parameter objects IDbDataParameter sqlparCompanyUserID = dao.CreateParameter("@CompanyUserID",CompanyUserID); return this.GetDataSet("CheckIfCompanyUserIDExists","CompanyExists",this.DatabaseKey,CommandType.StoredProcedure,sqlparCompanyUserID); } //****-> //****-> /// <summary> /// Creates a business rule object /// </summary> /// <returns>Reference to the business rule object</returns> protected override mmBusinessRule CreateBusinessRuleObject() { return new CompanyRules(this); } } }
using System; using System.Data; using OakLeaf.MM.Main; using OakLeaf.MM.Main.Business; namespace Apps4u.WinApp.Business.Company { /// <summary> /// Summary description for CompanyRules. /// </summary> public class CompanyRules : OakLeaf.MM.Main.Business.mmBusinessRule { //public DataSet ds; //****-> public Company oCompany; //****-> public CompanyRules(ImmBusinessRuleHost hostObject) : base(hostObject) { } /// <summary> /// Checks business rules against the specified DataTable /// </summary> /// <param name="ds">DataSet</param> /// <param name="tableName">Table Name</param> /// <returns>Logical true if rules passed, otherwise false</returns> public override bool CheckRulesHook(DataSet ds, string tableName) { if (ds != null) { string CompanyUserIdEmpty; DataRow dr = this.DataRow; CompanyUserIdEmpty = this.ValidateEmptyCompanyUserID(dr["CompanyUserID"].ToString()); this.ValidateEmptyCompanyName(dr["companyname"].ToString()); // if the company user id has been filled in the we will // run this process otherwise no point was server time. if (mmString.Empty(CompanyUserIdEmpty)) { this.ValidateCompanyUserIDExists(dr["CompanyUserID"].ToString()); } } return this.ErrorProviderBrokenRuleCount == 0; } /// <summary> /// Validate the Company User Defined ID /// </summary> /// <param name="CompanyUserID"></param> /// <returns>Empty Message or Failed Message</returns> public string ValidateEmptyCompanyUserID(string CompanyUserID) { string Message = null; if (mmString.Empty(CompanyUserID)) { Message = "The Company User Id Field must have a value"; this.AddErrorProviderBrokenRule("CompanyUserID",Message); } return Message; } /// <summary> /// Validate the Company Name /// </summary> /// <param name="CompanyName"></param> /// <returns>Empty Message or Failed Message</returns> public string ValidateEmptyCompanyName(string CompanyName) { string Message = null; if (mmString.Empty(CompanyName)) { Message = "The Company Name Field must have a value"; this.AddErrorProviderBrokenRule("CompanyName",Message); } return Message; } /// <summary> /// Validate the Company User Defined ID does not exist in the database /// </summary> /// <param name="CompanyUserID"></param> /// <returns>Empty Message or Failed Message</returns> public string ValidateCompanyUserIDExists(string CompanyUserID) { string Message = null; DataSet ds = null; //****-> ds = this.oCompany.CheckIfCompanyUserIdExists(CompanyUserID); //****-> if (int.Parse(ds.Tables["CompanyExists"].Rows[0].ToString()) != 0) { Message = "The Company User ID already exists in the database please selct another Company User ID"; this.AddErrorProviderBrokenRule("Company User ID",Message); } return Message; } } }