using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using Kingo.PluginServiceInterface;
using System.Collections.Generic;
using System.Data;
using System.Windows.Controls;
using System.Linq;
using System;
namespace Kingo.Plugin.SystemSetting.View.ViewSystemSetting
{
///
/// 系统设置-变更图斑检查规则设置 的交互逻辑
///
public partial class ViewBGRuleSetting : UserControl
{
public List FieldsTempData = null;
public ViewBGRuleSetting()
{
InitializeComponent();
BindData();
}
private void BindData()
{
string dbPath = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite";
IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
DataTable dataTable = rdbHelper.ExecuteDatatable("tab", " select ID,'地类图斑变更'||REPLACE(RuleName,'{1}','') RuleName,RuleType,RuleCode,BGLayerName,BGIsSelect from CheckingRule where BGLayerName NOTNULL ", true);
DataTable dataTablegroupby = rdbHelper.ExecuteDatatable("dataTablegroupby", " select RuleType,RuleType RuleName from CheckingRule where BGLayerName NOTNULL GROUP BY RuleType ", true);
FieldsTempData = new List();
var _ID = dataTable.Rows.Count + 1;
foreach (DataRow row in dataTablegroupby.Rows)
{
int isSelectCount = 0;
var RuleTypeTab = dataTable.Select($"RuleType = '{row["RuleType"].ToString()}'").ToList();
foreach (var item in RuleTypeTab)
{
if (Convert.ToBoolean(item["BGIsSelect"].ToString()) == true) isSelectCount++;
}
CheckingRule checkingRule = new CheckingRule()
{
ID = _ID,
PID = _ID,
RuleType = row["RuleType"].ToString(),
RuleName = row["RuleName"].ToString(),
BGIsSelect = isSelectCount == RuleTypeTab.Count
};
FieldsTempData.Add(checkingRule);
if (RuleTypeTab.Count > 0)
{
foreach (DataRow item in RuleTypeTab)
{
FieldsTempData.Add(new CheckingRule()
{
ID = Convert.ToInt32($"{checkingRule.ID}{item["ID"].ToString()}"),
PID = checkingRule.ID,
RuleName = item["RuleName"].ToString(),
RuleType = item["RuleType"].ToString(),
BGIsSelect = Convert.ToBoolean(item["BGIsSelect"].ToString()),
RuleCode = item["RuleCode"].ToString(),
});
}
}
_ID++;
}
treeList.ItemsSource = FieldsTempData;
rdbHelper.DisConnect();
}
private void View_CellValueChanged(object sender, DevExpress.Xpf.Grid.TreeList.TreeListCellValueChangedEventArgs e)
{
var checkingRule = e.Cell.Row as CheckingRule;
if (checkingRule != null)
{
string dbPath = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite";
IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
if (checkingRule.ID == checkingRule.PID)
{
rdbHelper.ExecuteNonQuery($"Update CheckingRule set BGIsSelect={e.Value} where RuleType='{checkingRule.RuleType}' ", CommandType.Text);
FieldsTempData.Where(x => x.RuleType == checkingRule.RuleType).ForEach(y => y.BGIsSelect = (bool)e.Value);
treeList.RefreshData();
}
else
{
rdbHelper.ExecuteNonQuery($"Update CheckingRule set BGIsSelect={e.Value} where RuleCode='{checkingRule.RuleCode}' ", CommandType.Text);
}
rdbHelper.DisConnect();
}
}
}
public class CheckingRule
{
public int ID { get; set; }
public int PID { get; set; }
public string RuleCode { get; set; }
public string LayerName { get; set; }
public string RuleType { get; set; }
public string RuleName { get; set; }
public string Requirement { get; set; }
public string ImplementSQL { get; set; }
public bool IsDelete { get; set; }
public string LayerName_AliasName { get; set; }
public bool BGIsSelect { get; set; }
public bool ZLIsSelect { get; set; }
}
}