Пример #1
0
        public JsonResult TableDesignSave(string data, int id = 0)
        {
            JavaScriptSerializer js      = new JavaScriptSerializer(); //实例化一个能够序列化数据的类
            TableDesignModel     myModel = js.Deserialize <TableDesignModel>(data);
            ScadaTableRowsModel  model   = new ScadaTableRowsModel();

            model.Id              = 0;
            model.TableId         = id;
            model.CreateTime      = DateTime.Now;
            model.CreateUserId    = Operator.UserId;
            model.UpdateTime      = DateTime.Now;
            model.UpdateUserId    = Operator.UserId;
            model.FieldBackColors = js.Serialize(myModel.backcolor);
            model.FieldColors     = js.Serialize(myModel.fontcolor);
            model.FieldFontSizes  = js.Serialize(myModel.fontsize);
            model.FieldWeights    = js.Serialize(myModel.fontweight);
            model.FieldIOPaths    = js.Serialize(myModel.data);
            var rowModes = TableRowService.GetByWhere("where TableId=" + id);
            var result   = "保存失败";

            if (rowModes.Count() > 0)
            {
                var TableModel = TableService.GetById(id);
                if (TableModel != null)
                {
                    TableModel.ColimnWidths = myModel.columnwidth;
                    TableModel.ColumnTitles = myModel.columntitle;
                    TableService.UpdateById(TableModel);
                }
                model.Id = rowModes.First().Id;
                result   = TableRowService.UpdateById(model) ? "保存设计成功" : "保存失败";
            }
            else
            {
                var TableModel = TableService.GetById(id);
                if (TableModel != null)
                {
                    TableModel.ColimnWidths = myModel.columnwidth;
                    TableModel.ColumnTitles = myModel.columntitle;
                    TableService.UpdateById(TableModel);
                    model.Id      = 0;
                    model.TableId = TableModel.Id;
                    result        = TableRowService.Insert(model) ? "保存设计成功" : "保存失败";
                }
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }