Esempio n. 1
0
        public JsonResult DelData()
        {
            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
                {
                    CostingVersionDetail cvd = new CostingVersionDetail(category);

                    if (id > 0)
                    {
                        cvd.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);
        }
Esempio n. 2
0
        public JsonResult SaveData()
        {
            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>;

                if (id == 0)
                {
                    data["CreatorName"] = AccessControl.CurrentLogonUser.Name;
                    data["CreationTime"] = DateTime.Now;
                }

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

                        if (sysMsg.isPass)
                        {
                            if (id > 0)
                            {
                                cvd.Update(id);
                            }
                            else
                            {
                                id = cvd.Add();
                                CostingVersionDetail.CopyVersion(id);
                            }

                            if (Convert.ToString(data["Status"]) == "Active")
                            {
                                SetActiveToClose(id);
                                InsertCostRate(Convert.ToString(data["Version"]));
                            }
                        }
                    }
                    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);
        }