コード例 #1
0
        public static string GetButtonById(int Id)
        {
            string str = string.Empty;

            try
            {
                IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                tbButton          temp        = new tbButton();
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                List <tbButton>   templist    = myDbContext.tbButton.Where(p => p.Id == Id).ToList();
                if (templist != null && templist.Count > 0)
                {
                    temp = templist[0];
                    str  = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                    str  = ResponseHelper.ResponseMsg("1", "取数成功", str);
                }
                else
                {
                    str = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                    str = ResponseHelper.ResponseMsg("-1", "部门不存在", str);
                }
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
コード例 #2
0
        public static string AddButton(string Deptstr)
        {
            string str = string.Empty;

            try
            {
                tbButton tb = JsonConvert.DeserializeObject <tbButton>(Deptstr);

                tbButton newtb = new tbButton()
                {
                    Name        = tb.Name,
                    CreateBy    = tb.CreateBy,
                    CreateTime  = DateTime.Now,
                    Code        = tb.Code,
                    Description = tb.Description,
                    Icon        = tb.Icon,

                    Sort       = tb.Sort,
                    UpdateBy   = tb.CreateBy,
                    UpdateTime = DateTime.Now
                };
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int DataCount = myDbContext.tbButton.Where(p => p.Name == tb.Name && p.Id != tb.Id).Count <tbButton>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("按钮名:{0}重复,请重新输入", tb.Name));
                }
                DataCount = myDbContext.tbButton.Where(p => p.Code == tb.Code && p.Id != tb.Id).Count <tbButton>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("按钮代码:{0}重复,请重新输入", tb.Code));
                }

                myDbContext.tbButton.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
コード例 #3
0
        public static string UpdateButton(string Buttonstr)
        {
            string str = string.Empty;

            try
            {
                tbButton          tb          = JsonConvert.DeserializeObject <tbButton>(Buttonstr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbButton          data        = myDbContext.tbButton.Where(p => p.Id == tb.Id).FirstOrDefault();
                data.Code        = tb.Code;
                data.Description = tb.Description;
                data.Icon        = tb.Icon;

                data.Sort       = tb.Sort;
                data.UpdateBy   = tb.UpdateBy;
                data.UpdateTime = DateTime.Now;


                int DataCount = myDbContext.tbButton.Where(p => p.Name == data.Name && p.Id != data.Id).Count <tbButton>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("按钮名:{0}重复,请重新输入", data.Name));
                }
                DataCount = myDbContext.tbButton.Where(p => p.Code == data.Code && p.Id != data.Id).Count <tbButton>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("按钮代码:{0}重复,请重新输入", data.Code));
                }

                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }