ab56a9bcf7
SVN-Revision: r240
281 lines
10 KiB
C#
281 lines
10 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 数据分析方案类
|
|
/// </summary>
|
|
public class GridSiftProjectModel
|
|
{
|
|
/// <summary>
|
|
/// 主键
|
|
/// </summary>
|
|
private int id;
|
|
/// <summary>
|
|
/// 方案名称
|
|
/// </summary>
|
|
private string name;
|
|
/// <summary>
|
|
/// 模块编号
|
|
/// </summary>
|
|
private string moduleId;
|
|
/// <summary>
|
|
/// 操作人id
|
|
/// </summary>
|
|
private int operatorid;
|
|
/// <summary>
|
|
/// 是否为公共方案,1为是
|
|
/// </summary>
|
|
private int isPub;
|
|
/// <summary>
|
|
/// 查询列 json数组字符串
|
|
/// </summary>
|
|
private string querys;
|
|
/// <summary>
|
|
/// 显示列,以英文逗号隔开的字段名
|
|
/// </summary>
|
|
private string cols;
|
|
/// <summary>
|
|
/// 分组列,以英文逗号隔开的字段名
|
|
/// </summary>
|
|
private string groups;
|
|
/// <summary>
|
|
/// 指标列 json数组字符串
|
|
/// </summary>
|
|
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;
|
|
}
|
|
/// <summary>
|
|
/// 方案新增
|
|
/// </summary>
|
|
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;
|
|
}
|
|
/// <summary>
|
|
/// 方案保存
|
|
/// </summary>
|
|
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);
|
|
}
|
|
/// <summary>
|
|
/// 方案删除
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 主键id
|
|
/// </summary>
|
|
public int Id
|
|
{
|
|
get { return id; }
|
|
set { id = value; }
|
|
}
|
|
/// <summary>
|
|
/// 方案名称
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get { return name; }
|
|
set { name = value; }
|
|
}
|
|
/// <summary>
|
|
/// 模块id
|
|
/// </summary>
|
|
public string ModuleId
|
|
{
|
|
get { return moduleId; }
|
|
set { moduleId = value; }
|
|
}
|
|
/// <summary>
|
|
/// 操作人id
|
|
/// </summary>
|
|
public int OperatorId
|
|
{
|
|
get { return operatorid; }
|
|
set { operatorid = value; }
|
|
}
|
|
/// <summary>
|
|
/// 是否为公共方案
|
|
/// </summary>
|
|
public bool IsPub
|
|
{
|
|
get { return "1".Equals(isPub + ""); }
|
|
set { isPub = value ? 1 : 0; }
|
|
}
|
|
/// <summary>
|
|
/// 指标列数组
|
|
/// </summary>
|
|
public List<QueryModel> Querys
|
|
{
|
|
get
|
|
{
|
|
List<QueryModel> DataBody = new List<QueryModel>();
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(querys))
|
|
{
|
|
DataBody = JsonConvert.DeserializeObject<List<QueryModel>>(querys);//解析数据体
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return DataBody;
|
|
}
|
|
set
|
|
{
|
|
querys = JsonConvert.SerializeObject(value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 操作列名称数组
|
|
/// </summary>
|
|
public List<string> Cols
|
|
{
|
|
get
|
|
{
|
|
return !string.IsNullOrEmpty(cols) ? cols.TrimEnd(',').Split(',').ToList() : new List<string>();
|
|
}
|
|
set
|
|
{
|
|
string setValue = "";
|
|
foreach (string item in value)
|
|
{
|
|
setValue += string.Format("{0},", item);
|
|
}
|
|
cols = setValue.TrimEnd(',');
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 分组列名称数组
|
|
/// </summary>
|
|
public List<string> Groups
|
|
{
|
|
get
|
|
{
|
|
return !string.IsNullOrEmpty(groups) ? groups.TrimEnd(',').Split(',').ToList() : new List<string>();
|
|
}
|
|
set
|
|
{
|
|
string setValue = "";
|
|
foreach (string item in value)
|
|
{
|
|
setValue += string.Format("{0},", item);
|
|
}
|
|
groups = setValue.TrimEnd(',');
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 指标列数组
|
|
/// </summary>
|
|
public List<TargetModel> Targets
|
|
{
|
|
get
|
|
{
|
|
List<TargetModel> DataBody = new List<TargetModel>();
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(targets))
|
|
{
|
|
DataBody = JsonConvert.DeserializeObject<List<TargetModel>>(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; }
|
|
}
|
|
}
|