256 lines
11 KiB
C#
256 lines
11 KiB
C#
using DevComponents.AdvTree;
|
|
using NaiBa.Util.Helper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace TemuKJD.KJDForms.ShopForms
|
|
{
|
|
public partial class FreightTemplateNotSendAreaForm : BaseForms.LRBaseForm
|
|
{
|
|
|
|
public FreightTemplateNotSendAreaForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void FreightTemplateNotSendAreaForm_Load(object sender, EventArgs e)
|
|
{
|
|
textBox1.Text = string.Join("、", FreightTemplateForm.AreaNotSendDict.Values);
|
|
|
|
Task.Run(() =>
|
|
{
|
|
for (int i = 0; i < FreightTemplateForm.LstAddress.Count; i++)
|
|
{
|
|
var province = FreightTemplateForm.LstAddress[i];
|
|
if (province.sub_districts == null || province.sub_districts.Count == 0)
|
|
{
|
|
var provinceTemp = FreightTemplateForm.GetAddress(province.code.ToString());
|
|
if (provinceTemp == null)
|
|
return;
|
|
else
|
|
province = provinceTemp;
|
|
}
|
|
|
|
var nodeProvince = new Node() { Text = province.name, Name = "p" + province.code, CheckBoxThreeState = true, CheckBoxVisible = true };
|
|
if (FreightTemplateForm.AreaNotSendDict.Keys.Any(k => k.EndsWith(nodeProvince.Name)))
|
|
nodeProvince.CheckState = CheckState.Checked;
|
|
else if (FreightTemplateForm.AreaNotSendDict.Keys.Any(k => k.Contains(nodeProvince.Name)))
|
|
nodeProvince.CheckState = CheckState.Indeterminate;
|
|
this.advTree1.Nodes.Add(nodeProvince);
|
|
if (province.sub_districts != null && province.sub_districts.Count > 0)
|
|
{
|
|
foreach (var city in province.sub_districts)
|
|
{
|
|
var nodeCity = new Node() { Text = city.name, Name = "c" + city.code, CheckBoxThreeState = true, CheckBoxVisible = true };
|
|
if (nodeProvince.CheckState == CheckState.Checked)
|
|
nodeCity.CheckState = CheckState.Checked;
|
|
else if (FreightTemplateForm.AreaNotSendDict.Keys.Any(k => k.EndsWith(nodeCity.Name)))
|
|
nodeCity.CheckState = CheckState.Checked;
|
|
else if (FreightTemplateForm.AreaNotSendDict.Keys.Any(k => k.Contains(nodeCity.Name)))
|
|
nodeCity.CheckState = CheckState.Indeterminate;
|
|
nodeProvince.Nodes.Add(nodeCity);
|
|
if (city.sub_districts != null && city.sub_districts.Count > 0)
|
|
{
|
|
foreach (var district in city.sub_districts)
|
|
{
|
|
var nodeDistrict = new Node() { Text = district.name, Name = "d" + district.code, CheckBoxThreeState = true, CheckBoxVisible = true };
|
|
if (nodeCity.CheckState == CheckState.Checked)
|
|
nodeDistrict.CheckState = CheckState.Checked;
|
|
else if (FreightTemplateForm.AreaNotSendDict.Keys.Any(k => k.EndsWith(nodeDistrict.Name)))
|
|
nodeDistrict.CheckState = CheckState.Checked;
|
|
else if (FreightTemplateForm.AreaNotSendDict.Keys.Any(k => k.Contains(nodeDistrict.Name)))
|
|
nodeDistrict.CheckState = CheckState.Indeterminate;
|
|
nodeCity.Nodes.Add(nodeDistrict);
|
|
if (district.sub_districts != null && district.sub_districts.Count > 0)
|
|
{
|
|
foreach (var town in district.sub_districts)
|
|
{
|
|
var nodeTown = new Node() { Text = town.name, Name = "t" + town.code, CheckBoxThreeState = true, CheckBoxVisible = true };
|
|
if (nodeDistrict.CheckState == CheckState.Checked)
|
|
nodeTown.CheckState = CheckState.Checked;
|
|
else if (FreightTemplateForm.AreaNotSendDict.Keys.Any(k => k.EndsWith(nodeTown.Name)))
|
|
nodeTown.CheckState = CheckState.Checked;
|
|
nodeDistrict.Nodes.Add(nodeTown);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
advTree1.AfterCheck += AdvTree1_AfterCheck;
|
|
});
|
|
}
|
|
|
|
private void AdvTree1_AfterCheck(object sender, AdvTreeCellEventArgs e)
|
|
{
|
|
this.advTree1.AfterCheck -= AdvTree1_AfterCheck;
|
|
var node = e.Cell.Parent;
|
|
if (node.CheckState == CheckState.Checked)
|
|
{
|
|
CheckAllChildNodes(node, true);
|
|
SelectParent(node);
|
|
}
|
|
else if (node.CheckState == CheckState.Unchecked)
|
|
{
|
|
CheckAllChildNodes(node, false);
|
|
CancelParent(node);
|
|
}
|
|
else
|
|
{
|
|
node.CheckState = CheckState.Unchecked;
|
|
CheckAllChildNodes(node, false);
|
|
CancelParent(node);
|
|
}
|
|
GetArea();
|
|
this.advTree1.AfterCheck += AdvTree1_AfterCheck;
|
|
}
|
|
|
|
|
|
#region 判断同级节点是否全部选中,从第一个节点开始
|
|
private bool IsAllChecked(Node tn)
|
|
{
|
|
if (tn.CheckState != CheckState.Checked)
|
|
{
|
|
return false;
|
|
}
|
|
if (tn.NextNode == null)
|
|
{
|
|
return true;
|
|
}
|
|
return IsAllChecked(tn.NextNode);
|
|
}
|
|
#endregion
|
|
|
|
#region 判断同级节点是否全未选中,从第一个节点开始
|
|
private bool IsAllUnChecked(Node tn)
|
|
{
|
|
if (tn.CheckState != CheckState.Unchecked)
|
|
{
|
|
return false;
|
|
}
|
|
if (tn.NextNode == null)
|
|
{
|
|
return true;
|
|
}
|
|
return IsAllUnChecked(tn.NextNode);
|
|
}
|
|
#endregion
|
|
|
|
#region 如果该节点选中,则其子节点全部选中,反之亦然
|
|
private void CheckAllChildNodes(Node tn, bool Checked)
|
|
{
|
|
if (tn.CheckState == CheckState.Checked || tn.CheckState == CheckState.Unchecked)
|
|
{
|
|
foreach (Node tnChild in tn.Nodes)
|
|
{
|
|
tnChild.CheckState = tn.CheckState;
|
|
if (tnChild.Nodes.Count > 0)
|
|
{
|
|
CheckAllChildNodes(tnChild, Checked);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 如过该节点选中,则其父节点依次选中
|
|
private void SelectParent(Node tn)
|
|
{
|
|
if (tn.Parent != null)
|
|
{
|
|
if (tn.CheckState == CheckState.Indeterminate)
|
|
tn.Parent.CheckState = CheckState.Indeterminate;
|
|
else if (IsAllChecked(tn.Parent.Nodes[0]))
|
|
tn.Parent.CheckState = CheckState.Checked;
|
|
else
|
|
tn.Parent.CheckState = CheckState.Indeterminate;
|
|
|
|
SelectParent(tn.Parent);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 如果该节点没有选中,且同级节点全未选中,则取消父节点
|
|
private void CancelParent(Node tn)
|
|
{
|
|
if (tn.Parent != null)
|
|
{
|
|
if (tn.CheckState == CheckState.Indeterminate)
|
|
tn.Parent.CheckState = CheckState.Indeterminate;
|
|
else if (IsAllUnChecked(tn.Parent.Nodes[0]))
|
|
tn.Parent.CheckState = CheckState.Unchecked;
|
|
else
|
|
tn.Parent.CheckState = CheckState.Indeterminate;
|
|
|
|
CancelParent(tn.Parent);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
ConfigHelper.SaveConfig("not_send_address", FreightTemplateForm.AreaNotSendDict);
|
|
this.Close();
|
|
}
|
|
|
|
private void GetArea()
|
|
{
|
|
FreightTemplateForm.AreaNotSendDict.Clear();
|
|
|
|
foreach (Node provinceNode in this.advTree1.Nodes)
|
|
{
|
|
if (provinceNode.CheckState == CheckState.Checked)
|
|
{
|
|
FreightTemplateForm.AreaNotSendDict[provinceNode.Name] = provinceNode.Text;
|
|
}
|
|
else if (provinceNode.CheckState == CheckState.Indeterminate)
|
|
{
|
|
foreach (Node cityNode in provinceNode.Nodes)
|
|
{
|
|
if (cityNode.CheckState == CheckState.Checked)
|
|
{
|
|
FreightTemplateForm.AreaNotSendDict[provinceNode.Name + cityNode.Name] = provinceNode.Text + cityNode.Text;
|
|
}
|
|
else if (cityNode.CheckState == CheckState.Indeterminate)
|
|
{
|
|
foreach (Node districtNode in cityNode.Nodes)
|
|
{
|
|
if (districtNode.CheckState == CheckState.Checked)
|
|
{
|
|
FreightTemplateForm.AreaNotSendDict[provinceNode.Name + cityNode.Name + districtNode.Name] = provinceNode.Text + cityNode.Text + districtNode.Text;
|
|
}
|
|
else if (provinceNode.CheckState == CheckState.Indeterminate)
|
|
{
|
|
foreach (Node townNode in districtNode.Nodes)
|
|
{
|
|
if (townNode.CheckState == CheckState.Checked)
|
|
{
|
|
FreightTemplateForm.AreaNotSendDict[provinceNode.Name + cityNode.Name + districtNode.Name + townNode.Name] =
|
|
provinceNode.Text + cityNode.Text + districtNode.Text + townNode.Text;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
textBox1.Text = string.Join("、", FreightTemplateForm.AreaNotSendDict.Values);
|
|
}
|
|
}
|
|
}
|