/// <summary> /// Update record by using the table's primary key. /// </summary> /// <param name="database"></param> /// <param name="data">Data which to update.</param> /// <param name="oldLANG_CD">Old Key #1</param> /// <param name="oldMENU_SUB_CD">Old Key #2</param> /// <returns></returns> public int UpdateWithPK(Database database, MenuSubLangDTO data, NZString oldLANG_CD, NZString oldMENU_SUB_CD) { Database db = UseDatabase(database); StringBuilder sb = new StringBuilder(); #region SQL Statement sb.AppendLine(" UPDATE " + data.TableName); sb.AppendLine(" SET "); sb.AppendLine(" " + MenuSubLangDTO.eColumns.LANG_CD + "=:LANG_CD"); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.MENU_SUB_CD + "=:MENU_SUB_CD"); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.MENU_SUB_DESC + "=:MENU_SUB_DESC"); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.UPD_BY + "=:UPD_BY"); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.UPD_DATE + "=GETDATE()"); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.UPD_MACHINE + "=:UPD_MACHINE"); sb.AppendLine(" WHERE "); sb.AppendLine(" " + MenuSubLangDTO.eColumns.LANG_CD + "=:oldLANG_CD"); sb.AppendLine(" AND " + MenuSubLangDTO.eColumns.MENU_SUB_CD + "=:oldMenuSubLang"); #endregion DataRequest req = new DataRequest(sb.ToString()); #region Parameters req.Parameters.Add("LANG_CD", DataType.VarChar, data.LANG_CD.Value); req.Parameters.Add("MENU_SUB_CD", DataType.VarChar, data.MENU_SUB_CD.Value); req.Parameters.Add("MENU_SUB_DESC", DataType.NVarChar, data.MENU_SUB_DESC.Value); req.Parameters.Add("UPD_BY", DataType.NVarChar, data.UPD_BY.Value); req.Parameters.Add("UPD_MACHINE", DataType.NVarChar, data.UPD_MACHINE.Value); req.Parameters.Add("oldLANG_CD", DataType.VarChar, oldLANG_CD.Value); req.Parameters.Add("oldMENU_SUB_CD", DataType.VarChar, oldMENU_SUB_CD.Value); #endregion return(db.ExecuteNonQuery(req)); }
/// <summary> /// Save new menu sub. /// </summary> /// <param name="menuSubCD"></param> /// <param name="menuSubName"></param> /// <exception cref="EVOFramework.ValidateException"><c>ValidateException</c>.</exception> /// <exception cref="EVOFramework.BusinessException"><c>BusinessException</c>.</exception> public void SaveNewMenuSubDescription(NZString menuSubCD, NZString menuSubName) { MenuSubValidator validator = new MenuSubValidator(); validator.ValidateBeforeSaveAdd(menuSubCD, menuSubName); Database database = CommonLib.Common.CurrentDatabase; try { database.KeepConnection = true; database.BeginTransaction(); ILangDAO daoLang = DAOFactory.CreateLangDAO(database); IMenuSubDAO daoMenuSub = DAOFactory.CreateMenuSubDAO(database); IMenuSubLangDAO daoMenuSubLang = DAOFactory.CreateMenuSubLangDAO(database); //== Add menu sub master. MenuSubDTO dtoMenuSub = new MenuSubDTO(); dtoMenuSub.MENU_SUB_CD = menuSubCD; dtoMenuSub.MENU_SUB_NAME = menuSubName; dtoMenuSub.IMAGE_CD.Value = null; dtoMenuSub.CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD; dtoMenuSub.UPD_BY = CommonLib.Common.CurrentUserInfomation.UserCD; dtoMenuSub.CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine; dtoMenuSub.UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine; daoMenuSub.AddNew(null, dtoMenuSub); //== Add menu sub on each language. List <LangDTO> langs = daoLang.LoadAll(null); for (int i = 0; i < langs.Count; i++) { MenuSubLangDTO dtoMenuSubLang = new MenuSubLangDTO(); dtoMenuSubLang.MENU_SUB_CD = menuSubCD; dtoMenuSubLang.LANG_CD = langs[i].LANG_CD; dtoMenuSubLang.MENU_SUB_DESC = menuSubName; dtoMenuSubLang.CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD; dtoMenuSubLang.UPD_BY = CommonLib.Common.CurrentUserInfomation.UserCD; dtoMenuSubLang.CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine; dtoMenuSubLang.UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine; daoMenuSubLang.AddNewOrUpdate(null, dtoMenuSubLang); } database.Commit(); } catch { database.Rollback(); throw; } finally { if (database.DBConnectionState == ConnectionState.Open) { database.Close(); } } }
/// <summary> /// Check exist before manipulate data. If found record will update data. Otherwise insert new data. /// </summary> /// <param name="database"></param> /// <param name="data"></param> /// <returns></returns> public int AddNewOrUpdate(Database database, MenuSubLangDTO data) { Database db = UseDatabase(database); if (Exist(database, data.LANG_CD, data.MENU_SUB_CD)) { return(UpdateWithoutPK(db, data)); } return(AddNew(db, data)); }
public void SaveMenuSubDescription(NZString menuSubCD, NZString langCD, NZString description) { IMenuSubLangDAO daoSubMenuLang = DAOFactory.CreateMenuSubLangDAO(CommonLib.Common.CurrentDatabase); MenuSubLangDTO dtoMenuSubLang = new MenuSubLangDTO(); dtoMenuSubLang.MENU_SUB_CD = menuSubCD; dtoMenuSubLang.LANG_CD = langCD; dtoMenuSubLang.MENU_SUB_DESC = description; dtoMenuSubLang.CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD; dtoMenuSubLang.UPD_BY = CommonLib.Common.CurrentUserInfomation.UserCD; dtoMenuSubLang.CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine; dtoMenuSubLang.UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine; daoSubMenuLang.AddNewOrUpdate(null, dtoMenuSubLang); }
/// <summary> /// Insert new record into database. /// </summary> /// <param name="database"></param> /// <param name="data"></param> /// <returns></returns> public int AddNew(Database database, MenuSubLangDTO data) { Database db = UseDatabase(database); StringBuilder sb = new StringBuilder(); #region SQL Statement sb.AppendLine(" INSERT INTO " + data.TableName + "("); sb.AppendLine(" " + MenuSubLangDTO.eColumns.LANG_CD); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.MENU_SUB_CD); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.MENU_SUB_DESC); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.CRT_BY); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.CRT_DATE); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.CRT_MACHINE); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.UPD_BY); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.UPD_DATE); sb.AppendLine(" ," + MenuSubLangDTO.eColumns.UPD_MACHINE); sb.AppendLine(") VALUES("); sb.AppendLine(" :LANG_CD"); sb.AppendLine(" ,:MENU_SUB_CD"); sb.AppendLine(" ,:MENU_SUB_DESC"); sb.AppendLine(" ,:CRT_BY"); sb.AppendLine(" ,GETDATE()"); sb.AppendLine(" ,:CRT_MACHINE"); sb.AppendLine(" ,:UPD_BY"); sb.AppendLine(" ,GETDATE()"); sb.AppendLine(" ,:UPD_MACHINE"); sb.AppendLine(" )"); #endregion DataRequest req = new DataRequest(sb.ToString()); #region Parameters req.Parameters.Add("LANG_CD", DataType.VarChar, data.LANG_CD.Value); req.Parameters.Add("MENU_SUB_CD", DataType.VarChar, data.MENU_SUB_CD.Value); req.Parameters.Add("MENU_SUB_DESC", DataType.NVarChar, data.MENU_SUB_DESC.Value); req.Parameters.Add("CRT_BY", DataType.NVarChar, data.CRT_BY.Value); req.Parameters.Add("CRT_MACHINE", DataType.NVarChar, data.CRT_MACHINE.Value); req.Parameters.Add("UPD_BY", DataType.NVarChar, data.UPD_BY.Value); req.Parameters.Add("UPD_MACHINE", DataType.NVarChar, data.UPD_MACHINE.Value); #endregion return(db.ExecuteNonQuery(req)); }