using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using System.Collections; using Lskj.Core; namespace Lskj.Control.SiftColControl { /// /// 数据分析方案类 /// public class GridSiftProjectModel { /// /// 主键 /// private int id; /// /// 方案名称 /// private string name; /// /// 模块编号 /// private string moduleId; /// /// 操作人id /// private int operatorid; /// /// 是否为公共方案,1为是 /// private int isPub; /// /// 查询列 json数组字符串 /// private string querys; /// /// 显示列,以英文逗号隔开的字段名 /// private string cols; /// /// 分组列,以英文逗号隔开的字段名 /// private string groups; /// /// 指标列 json数组字符串 /// private string targets; public GridSiftProjectModel(DataRow row) { this.id = row.Table.Columns.Contains("id") && !string.IsNullOrEmpty(row["id"] + "") ? Convert.ToInt32(row["id"] + "") : 0; this.name = row.Table.Columns.Contains("name") && !string.IsNullOrEmpty(row["name"] + "") ? row["name"] + "" : ""; this.moduleId = row.Table.Columns.Contains("moduleId") && !string.IsNullOrEmpty(row["moduleId"] + "") ? row["moduleId"] + "" : ""; this.operatorid = row.Table.Columns.Contains("operatorid") && !string.IsNullOrEmpty(row["operatorid"] + "") ? Convert.ToInt32(row["operatorid"] + "") : 0; this.isPub = row.Table.Columns.Contains("isPub") && !string.IsNullOrEmpty(row["isPub"] + "") ? Convert.ToInt32(row["isPub"] + "") : 0; this.querys = row.Table.Columns.Contains("querys") && !string.IsNullOrEmpty(row["querys"] + "") ? row["querys"] + "" : ""; this.cols = row.Table.Columns.Contains("cols") && !string.IsNullOrEmpty(row["cols"] + "") ? row["cols"] + "" : ""; this.groups = row.Table.Columns.Contains("groups") && !string.IsNullOrEmpty(row["groups"] + "") ? row["groups"] + "" : ""; this.targets = row.Table.Columns.Contains("targets") && !string.IsNullOrEmpty(row["targets"] + "") ? row["targets"] + "" : ""; } public GridSiftProjectModel(string primarykey) { DataTable projectTab = SqlHelper.ExecuteDataTable(string.Format("select * from p_SysModuleSchemeTab where id = '{0}'", primarykey)); if (projectTab != null && projectTab.Rows.Count > 0) { DataRow row = projectTab.Rows[0]; this.id = row.Table.Columns.Contains("id") && !string.IsNullOrEmpty(row["id"] + "") ? Convert.ToInt32(row["id"] + "") : 0; this.name = row.Table.Columns.Contains("name") && !string.IsNullOrEmpty(row["name"] + "") ? row["name"] + "" : ""; this.moduleId = row.Table.Columns.Contains("moduleId") && !string.IsNullOrEmpty(row["moduleId"] + "") ? row["moduleId"] + "" : ""; this.operatorid = row.Table.Columns.Contains("operatorid") && !string.IsNullOrEmpty(row["operatorid"] + "") ? Convert.ToInt32(row["operatorid"] + "") : 0; this.isPub = row.Table.Columns.Contains("isPub") && !string.IsNullOrEmpty(row["isPub"] + "") ? Convert.ToInt32(row["isPub"] + "") : 0; this.querys = row.Table.Columns.Contains("querys") && !string.IsNullOrEmpty(row["querys"] + "") ? row["querys"] + "" : ""; this.cols = row.Table.Columns.Contains("cols") && !string.IsNullOrEmpty(row["cols"] + "") ? row["cols"] + "" : ""; this.groups = row.Table.Columns.Contains("groups") && !string.IsNullOrEmpty(row["groups"] + "") ? row["groups"] + "" : ""; this.targets = row.Table.Columns.Contains("targets") && !string.IsNullOrEmpty(row["targets"] + "") ? row["targets"] + "" : ""; } } public GridSiftProjectModel() { } public Hashtable GetProjectHashTable() { Hashtable hashTable = new Hashtable(); hashTable.Add("id", this.id); hashTable.Add("name", this.name); hashTable.Add("moduleid", this.moduleId); hashTable.Add("operatorid", this.operatorid); hashTable.Add("isPub", this.isPub); hashTable.Add("querys", this.querys); hashTable.Add("cols", this.cols); hashTable.Add("groups", this.groups); hashTable.Add("targets", this.targets); return hashTable; } /// /// 方案新增 /// public static GridSiftProjectModel Add(string _name, string _moduleId, int _operatorid, int _isPub) { string addSqlStr = "insert into p_SysModuleSchemeTab (name,moduleId,operatorid,isPub) values ('{0}','{1}','{2}','{3}')"; addSqlStr = string.Format(addSqlStr, _name.Replace("'", "''"), _moduleId, _operatorid, _isPub); SqlHelper.ExecuteNonQuery(addSqlStr); string autogrowvalue = SqlHelper.ExecuteScalar(string.Format("select ident_current('{0}')", "p_SysModuleSchemeTab")) + ""; GridSiftProjectModel projectModel = new GridSiftProjectModel(autogrowvalue); return projectModel; } /// /// 方案保存 /// public void Save() { string saveSqlStr = "update p_SysModuleSchemeTab set {0} where id = '{1}'"; Hashtable projectTab = GetProjectHashTable(); string updateKeyValues = ""; foreach (string key in projectTab.Keys) { if (key.Equals("id")) continue; updateKeyValues += string.Format("{0}='{1}',", key, (projectTab[key] + "").Replace("'", "''")); } saveSqlStr = string.Format(saveSqlStr, updateKeyValues.TrimEnd(','), this.Id); SqlHelper.ExecuteNonQuery(saveSqlStr); } /// /// 方案删除 /// public void Delete() { if (!string.IsNullOrEmpty(this.Id + "")) { string deleteSqlStr = "delete p_SysModuleSchemeTab where id = '{0}'"; deleteSqlStr = string.Format(deleteSqlStr, this.Id + ""); SqlHelper.ExecuteNonQuery(deleteSqlStr); } } /// /// 主键id /// public int Id { get { return id; } set { id = value; } } /// /// 方案名称 /// public string Name { get { return name; } set { name = value; } } /// /// 模块id /// public string ModuleId { get { return moduleId; } set { moduleId = value; } } /// /// 操作人id /// public int OperatorId { get { return operatorid; } set { operatorid = value; } } /// /// 是否为公共方案 /// public bool IsPub { get { return "1".Equals(isPub + ""); } set { isPub = value ? 1 : 0; } } /// /// 指标列数组 /// public List Querys { get { List DataBody = new List(); try { if (!string.IsNullOrEmpty(querys)) { DataBody = JsonConvert.DeserializeObject>(querys);//解析数据体 } } catch (Exception) { } return DataBody; } set { querys = JsonConvert.SerializeObject(value); } } /// /// 操作列名称数组 /// public List Cols { get { return !string.IsNullOrEmpty(cols) ? cols.TrimEnd(',').Split(',').ToList() : new List(); } set { string setValue = ""; foreach (string item in value) { setValue += string.Format("{0},", item); } cols = setValue.TrimEnd(','); } } /// /// 分组列名称数组 /// public List Groups { get { return !string.IsNullOrEmpty(groups) ? groups.TrimEnd(',').Split(',').ToList() : new List(); } set { string setValue = ""; foreach (string item in value) { setValue += string.Format("{0},", item); } groups = setValue.TrimEnd(','); } } /// /// 指标列数组 /// public List Targets { get { List DataBody = new List(); try { if (!string.IsNullOrEmpty(targets)) { DataBody = JsonConvert.DeserializeObject>(targets);//解析数据体 } } catch (Exception) { } return DataBody; } set { targets = JsonConvert.SerializeObject(value); } } } public class QueryModel { public string name { get; set; } public string oper { get; set; } public string val { get; set; } } public class TargetModel { public string name { get; set; } public string oper { get; set; } } }