Exemplo n.º 1
0
        public static string UpdateParameter(string Parameterstr)
        {
            string str = string.Empty;

            try
            {
                tbParameter       tb          = JsonConvert.DeserializeObject <tbParameter>(Parameterstr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbParameter       data        = myDbContext.tbParameter.Where(p => p.id == tb.id).FirstOrDefault();
                if (data != null)
                {
                    int DataCount = myDbContext.tbParameter.Where(p => p.Code == tb.Code && p.id != tb.id).Count <tbParameter>();
                    if (DataCount > 0)
                    {
                        throw new Exception(string.Format("Code:{0}重复,请重新输入", data.Code));
                    }
                    string[] keys = { "id" };
                    ObjectHelper.CopyValueNotKey(tb, data, keys);
                }
                else
                {
                    throw new Exception(string.Format("Key:{0}找不到相关数据", tb.id));
                }


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

            return(str);
        }
Exemplo n.º 2
0
        public static string GetParameterById(int Id)
        {
            string str = string.Empty;

            try
            {
                IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                tbParameter        temp        = new tbParameter();
                AchieveDBEntities  myDbContext = new AchieveDBEntities();
                List <tbParameter> templist    = myDbContext.tbParameter.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);
        }
Exemplo n.º 3
0
        public static string AddParameter(string Parameterstr)
        {
            string str = string.Empty;

            try
            {
                tbParameter tb = JsonConvert.DeserializeObject <tbParameter>(Parameterstr);
                tb.CreateTime = DateTime.Now;
                tb.UpdateTime = DateTime.Now;
                string[]    keys  = { "id" };
                tbParameter newtb = new tbParameter();
                ObjectHelper.CopyValueNotKey(tb, newtb, keys);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int DataCount = myDbContext.tbParameter.Where(p => p.Code == tb.Code).Count <tbParameter>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("Code:{0}重复,请重新输入", tb.Code));
                }
                myDbContext.tbParameter.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }