コード例 #1
0
        public JsonResult DelOtherData()
        {
            SystemMessages sysMsg = new SystemMessages();
            int id = 0;
            string dataId = Request["dataId"];
            string categoryName = Request["categoryName"];

            Int32.TryParse(dataId, out id);
            FieldCategory category = new FieldCategory(categoryName);

            using (TScope ts = new TScope())
            {
                try
                {
                    CostingOtherDetailData codd = new CostingOtherDetailData(category);

                    if (id > 0)
                    {
                        codd.Delete(id);
                    }
                }
                catch (Exception ex)
                {
                    ts.Rollback();
                    sysMsg.isPass = false;
                    sysMsg.Messages.Add("Error", ex.Message);
                }
            }

            var jsonResult = new
            {
                success = sysMsg.isPass,
                errMessage = sysMsg.MessageString
            };
            return Json(jsonResult);
        }
コード例 #2
0
        public JsonResult SaveOtherData()
        {
            SystemMessages sysMsg = new SystemMessages();
            int id = 0;
            string postData = Request["postData"];

            if (!String.IsNullOrWhiteSpace(postData))
            {
                System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                Dictionary<string, object> jsonData = jss.Deserialize<Dictionary<string, object>>(postData) as Dictionary<string, object>;

                string dataId = Convert.ToString(jsonData["dataId"]);
                Int32.TryParse(dataId, out id);
                FieldCategory category = new FieldCategory(Convert.ToString(jsonData["categoryName"]));
                Dictionary<string, object> data = jsonData["data"] as Dictionary<string, object>;

                using (TScope ts = new TScope())
                {
                    try
                    {
                        CostingOtherDetailData codd = new CostingOtherDetailData(category, data);
                        category.CheckDataType(data, sysMsg);
                        codd.CheckData(sysMsg);

                        if (sysMsg.isPass)
                        {
                            if (id > 0)
                            {
                                codd.Update(id);
                            }
                            else
                            {
                                id = codd.Add();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ts.Rollback();
                        sysMsg.isPass = false;
                        sysMsg.Messages.Add("Error", ex.Message);
                    }
                }
            }

            var jsonResult = new
            {
                DataId = id,
                success = sysMsg.isPass,
                errMessage = sysMsg.MessageString
            };
            return Json(jsonResult);
        }