Example #1
0
        /// <summary>
        /// Add new menu to database and return id
        /// </summary>
        /// <param name="menu">SysMenuEntry object</param>
        /// <param name="roleId">Role ID</param>
        /// <returns>New ID</returns>
        public int AddAndReturnID(Sys_Menu_Entry menu, int roleId)
        {
            const string METHOD_NAME = THIS + ".AddAndReturnID()";

            try
            {
                using (var trans = new TransactionScope())
                {
                    PCSDataContext dataContext = new PCSDataContext(Utils.Instance.ConnectionString);
                    dataContext.Sys_Menu_Entries.InsertOnSubmit(menu);

                    // update button caption
                    var subMenus = dataContext.Sys_Menu_Entries.Where(
                        m => m.Parent_Shortcut == menu.Parent_Shortcut && m.Button_Caption > menu.Button_Caption).OrderBy(
                        m => m.Button_Caption).ToList();
                    subMenus.ForEach(m => m.Button_Caption = m.Button_Caption + 1);

                    // save new menu
                    menu.Button_Caption += 1;
                    // submit changes
                    dataContext.SubmitChanges();

                    // create right for new menu
                    var right = new Sys_Right
                    {
                        Menu_EntryID = menu.Menu_EntryID,
                        Permission   = 1,
                        RoleID       = roleId
                    };
                    dataContext.Sys_Rights.InsertOnSubmit(right);

                    dataContext.SubmitChanges();
                    trans.Complete();
                    return(menu.Menu_EntryID);
                }
            }
            catch (SqlException ex)
            {
                if (ex.Errors.Count > 1)
                {
                    if (ex.Number == ErrorCode.SQLDUPLICATE_UNIQUE_KEYCODE)
                    {
                        throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
                    }
                    throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
                }
                throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
            }
        }
Example #2
0
        public void UpdateTrans(Sys_Menu_Entry menu, int roleId)
        {
            const string METHOD_NAME = THIS + ".Delete()";

            try
            {
                using (var trans = new TransactionScope())
                {
                    PCSDataContext dataContext = new PCSDataContext(Utils.Instance.ConnectionString);
                    var            current     = dataContext.Sys_Menu_Entries.SingleOrDefault(m => m.Menu_EntryID == menu.Menu_EntryID);
                    if (current != null)
                    {
                        current.Text_Caption_EN_US  = menu.Text_Caption_EN_US;
                        current.Text_Caption_JA_JP  = menu.Text_Caption_JA_JP;
                        current.Text_Caption_VI_VN  = menu.Text_Caption_VI_VN;
                        current.Text_CaptionDefault = menu.Text_CaptionDefault;
                        current.Prefix      = menu.Prefix;
                        current.TransFormat = menu.TransFormat;
                    }
                    else
                    {
                        dataContext.Sys_Menu_Entries.InsertOnSubmit(menu);
                        // create right for new menu
                        var right = new Sys_Right
                        {
                            Menu_EntryID = menu.Menu_EntryID,
                            Permission   = 1,
                            RoleID       = roleId
                        };
                        dataContext.Sys_Rights.InsertOnSubmit(right);
                    }

                    dataContext.SubmitChanges();
                    trans.Complete();
                }
            }
            catch (SqlException ex)
            {
                if (ex.Errors.Count > 1)
                {
                    if (ex.Number == ErrorCode.SQLDUPLICATE_UNIQUE_KEYCODE)
                    {
                        throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
                    }
                    throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
                }
                throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
            }
        }
Example #3
0
        /// <summary>
        /// Update into Database
        /// </summary>
        public void Update(Sys_Menu_Entry menu, int roleId)
        {
            const string METHOD_NAME = THIS + ".Delete()";

            try
            {
                using (var trans = new TransactionScope())
                {
                    PCSDataContext dataContext = new PCSDataContext(Utils.Instance.ConnectionString);
                    var            current     = dataContext.Sys_Menu_Entries.SingleOrDefault(m => m.Menu_EntryID == menu.Menu_EntryID);
                    if (current != null)
                    {
                        current.Button_Caption                = menu.Button_Caption;
                        current.CollapsedImage                = menu.CollapsedImage;
                        current.Description                   = menu.Description;
                        current.ExpandedImage                 = menu.ExpandedImage;
                        current.FormLoad                      = menu.FormLoad;
                        current.IsTransaction                 = menu.IsTransaction;
                        current.IsUserCreated                 = menu.IsUserCreated;
                        current.Parent_Child                  = menu.Parent_Child;
                        current.Parent_Shortcut               = menu.Parent_Shortcut;
                        current.Prefix                        = menu.Prefix;
                        current.ReportID                      = menu.ReportID;
                        current.Shortcut                      = menu.Shortcut;
                        current.TableName                     = menu.TableName;
                        current.Text_Caption_EN_US            = menu.Text_Caption_EN_US;
                        current.Text_Caption_JA_JP            = menu.Text_Caption_JA_JP;
                        current.Text_Caption_VI_VN            = menu.Text_Caption_VI_VN;
                        current.Text_Caption_Language_Default = menu.Text_Caption_Language_Default;
                        current.Text_CaptionDefault           = menu.Text_CaptionDefault;
                        current.TransFormat                   = menu.TransFormat;
                        current.TransNoFieldName              = menu.TransNoFieldName;
                        current.Type = menu.Type;
                    }
                    else
                    {
                        dataContext.Sys_Menu_Entries.InsertOnSubmit(menu);
                        // create right for new menu
                        var right = new Sys_Right
                        {
                            Menu_EntryID = menu.Menu_EntryID,
                            Permission   = 1,
                            RoleID       = roleId
                        };
                        dataContext.Sys_Rights.InsertOnSubmit(right);
                    }

                    dataContext.SubmitChanges();
                    trans.Complete();
                }
            }
            catch (SqlException ex)
            {
                if (ex.Errors.Count > 1)
                {
                    if (ex.Number == ErrorCode.SQLDUPLICATE_UNIQUE_KEYCODE)
                    {
                        throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
                    }
                    throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
                }
                throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
            }
        }