Пример #1
0
        public ActionResult DesignTable(int Id = 0)
        {
            var            rowModel   = TableRowService.GetByWhere("where TableId=" + Id);
            var            tableUsers = TableUserRoleService.GetByWhere("where TableId=" + Id);
            var            tableModel = TableService.GetById(Id);
            TableEditModel model      = new TableEditModel();

            model.TableId = Id;
            model.Title   = tableModel != null ? tableModel.Title : "";
            model.RowNum  = tableModel != null ? tableModel.RowNum : 100;

            var AllUsers = UserService.GetAll();

            model.AllUserJson = JsonConvert.SerializeObject(AllUsers);//获取当前的所有用户
            List <UserModel> privatemodels = new List <UserModel>();

            foreach (var item in tableUsers)
            {
                var whereItems = AllUsers.Where(x => x.Id == item.UserId);
                if (whereItems.Count() > 0)
                {
                    var extItem = whereItems.First();
                    privatemodels.Add(extItem);
                }
            }
            model.PrivateUserJson = JsonConvert.SerializeObject(privatemodels); //获取当前的所有用户
                                                                                //获取表的列宽度
            List <string> fontwidthmodels = new List <string>();

            if (tableModel != null && !string.IsNullOrWhiteSpace(tableModel.ColimnWidths))
            {
                fontwidthmodels = tableModel.ColimnWidths.Split(',').ToList();
            }
            else
            {
                for (int i = 0; i < 26; i++)
                {
                    fontwidthmodels.Add("120");
                }
            }

            model.colwidthmodels = JsonConvert.SerializeObject(fontwidthmodels);
            //获取列标题
            //获取表的列宽度
            List <string> columntitlemodels = new List <string>();

            if (tableModel != null && !string.IsNullOrWhiteSpace(tableModel.ColumnTitles))
            {
                columntitlemodels = tableModel.ColumnTitles.Split(',').ToList();
            }
            else
            {
                for (int i = 0; i < 26; i++)
                {
                    columntitlemodels.Add(ExcelConvert.ToName(i));
                }
            }
            model.coltitlesmodels = JsonConvert.SerializeObject(columntitlemodels);
            return(View(model));
        }
Пример #2
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));
        }
Пример #3
0
        public JsonResult GetExcelData(int id = 0)
        {
            var rowModes = TableRowService.GetByWhere("where TableId=" + id);
            List <ExcelModel>     models           = new List <ExcelModel>();
            List <List <string> > backcolormodels  = new List <List <string> >();
            List <List <string> > fontcolormodels  = new List <List <string> >();
            List <List <string> > fontsizemodels   = new List <List <string> >();
            List <List <string> > fontweightmodels = new List <List <string> >();



            for (int i = 0; i < 100; i++)
            {
                models.Add(new ExcelModel());
            }
            for (int i = 0; i < 100; i++)
            {
                List <string> row = new List <string>();
                for (int j = 0; j < 26; j++)
                {
                    row.Add("#ffffff");
                }
                backcolormodels.Add(row);
            }
            for (int i = 0; i < 100; i++)
            {
                List <string> row = new List <string>();
                for (int j = 0; j < 26; j++)
                {
                    row.Add("#000000");
                }
                fontcolormodels.Add(row);
            }
            for (int i = 0; i < 100; i++)
            {
                List <string> row = new List <string>();
                for (int j = 0; j < 26; j++)
                {
                    row.Add("120");
                }
                fontsizemodels.Add(row);
            }
            for (int i = 0; i < 100; i++)
            {
                List <string> row = new List <string>();
                for (int j = 0; j < 26; j++)
                {
                    row.Add("normal");
                }
                fontweightmodels.Add(row);
            }



            ScadaTableRowsModel rowmodel = null;

            if (rowModes.Count() > 0)
            {
                rowmodel = rowModes.First();
            }
            if (rowmodel != null)
            {
                try
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();   //实例化一个能够序列化数据的类

                    backcolormodels  = js.Deserialize <List <List <string> > >(rowmodel.FieldBackColors);
                    fontcolormodels  = js.Deserialize <List <List <string> > >(rowmodel.FieldColors);
                    fontsizemodels   = js.Deserialize <List <List <string> > >(rowmodel.FieldFontSizes);
                    models           = js.Deserialize <List <ExcelModel> >(rowmodel.FieldIOPaths);
                    fontweightmodels = js.Deserialize <List <List <string> > >(rowmodel.FieldWeights);
                }
                catch
                {
                }
            }



            var result = Pager.ExcelPaging(models, backcolormodels, fontcolormodels, fontsizemodels, fontweightmodels, null, 100);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public override ActionResult Index(int?id)
        {
            string para  = Request.QueryString["id"].Split('?')[0];
            string idstr = Request.QueryString["id"].Split('?')[1].Split('=')[1];

            base.Index(int.Parse(idstr));



            var            rowModel   = TableRowService.GetByWhere("where TableId=" + int.Parse(para)).First();
            var            tableUsers = TableUserRoleService.GetByWhere("where TableId=" + int.Parse(para));
            var            tableModel = TableService.GetById(int.Parse(para));
            TableRealModel model      = new TableRealModel();

            model.TableId = int.Parse(para);
            model.Title   = tableModel != null ? tableModel.Title : "";
            model.RowNum  = tableModel != null ? tableModel.RowNum : 100;

            var AllUsers = UserService.GetAll();

            model.AllUserJson = JsonConvert.SerializeObject(AllUsers);//获取当前的所有用户
            List <UserModel> privatemodels = new List <UserModel>();

            foreach (var item in tableUsers)
            {
                var whereItems = AllUsers.Where(x => x.Id == item.UserId);
                if (whereItems.Count() > 0)
                {
                    var extItem = whereItems.First();
                    privatemodels.Add(extItem);
                }
            }
            model.PrivateUserJson = JsonConvert.SerializeObject(privatemodels); //获取当前的所有用户
                                                                                //获取表的列宽度
            List <string> fontwidthmodels = new List <string>();

            if (tableModel != null && !string.IsNullOrWhiteSpace(tableModel.ColimnWidths))
            {
                fontwidthmodels = tableModel.ColimnWidths.Split(',').ToList();
            }
            else
            {
                for (int i = 0; i < 26; i++)
                {
                    fontwidthmodels.Add("120");
                }
            }

            model.colwidthmodels = JsonConvert.SerializeObject(fontwidthmodels);
            //获取列标题
            //获取表的列宽度
            List <string> columntitlemodels = new List <string>();

            if (tableModel != null && !string.IsNullOrWhiteSpace(tableModel.ColumnTitles))
            {
                columntitlemodels = tableModel.ColumnTitles.Split(',').ToList();
            }
            else
            {
                for (int i = 0; i < 26; i++)
                {
                    columntitlemodels.Add(ExcelConvert.ToName(i));
                }
            }
            model.coltitlesmodels = JsonConvert.SerializeObject(columntitlemodels);
            model.ScadaTable      = tableModel;
            model.FieldBackColors = rowModel.FieldBackColors;
            model.FieldColors     = rowModel.FieldColors;
            model.FieldFontSizes  = rowModel.FieldFontSizes;
            model.FieldIOPaths    = rowModel.FieldIOPaths;
            model.FieldWeights    = rowModel.FieldWeights;
            ///获取设备列表
            JavaScriptSerializer    js              = new JavaScriptSerializer(); //实例化一个能够序列化数据的类
            List <ExcelModel>       excelModels     = js.Deserialize <List <ExcelModel> >(rowModel.FieldIOPaths);
            List <DeviceGroupModel> deviceAllModels = DeviceGroupService.GetAll().ToList();
            List <DeviceGroupModel> deviceModels    = new List <DeviceGroupModel>();

            for (int i = 0; i < excelModels.Count; i++)
            {
                PropertyInfo[] properties = excelModels[i].GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
                if (properties.Length <= 0)
                {
                    continue;
                }
                foreach (PropertyInfo item in properties)
                {
                    string name  = item.Name;
                    object value = item.GetValue(excelModels[i], null);
                    if (value != null && value.ToString() != "")
                    {
                        if (value.ToString().Split('/').Length >= 8)
                        {
                            try
                            {
                                DeviceGroupModel groupDevice = new DeviceGroupModel();
                                groupDevice.GroupId      = int.Parse(value.ToString().Split('/')[1]);
                                groupDevice.IO_SERVER_ID = value.ToString().Split('/')[2];
                                groupDevice.IO_COMM_ID   = value.ToString().Split('/')[3];
                                groupDevice.IO_DEVICE_ID = value.ToString().Split('/')[4];
                                groupDevice.UpdateCycle  = int.Parse(value.ToString().Split('/')[6]);
                                groupDevice.CurrentIO    = value.ToString().Split('/')[5];//当前的iO
                                DeviceGroupModel exitItem = deviceAllModels.Find(x => x.IO_SERVER_ID == groupDevice.IO_SERVER_ID && x.IO_COMM_ID == groupDevice.IO_COMM_ID && x.IO_DEVICE_ID == groupDevice.IO_DEVICE_ID && x.GroupId == groupDevice.GroupId);
                                if (exitItem != null)
                                {
                                    if (!deviceModels.Exists(x => x.IO_SERVER_ID == groupDevice.IO_SERVER_ID && x.IO_COMM_ID == groupDevice.IO_COMM_ID && x.IO_DEVICE_ID == groupDevice.IO_DEVICE_ID && x.GroupId == groupDevice.GroupId))
                                    {
                                        exitItem.CurrentIO = groupDevice.CurrentIO;
                                        deviceModels.Add(exitItem);
                                    }
                                }
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }
                }
            }
            model.Devices     = deviceModels;
            model.JsonDevices = js.Serialize(deviceModels);
            return(View(model));
        }