using System using System Collections Generic using System ComponentMo

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Certificates.Models;
using Certificates.Classes;
namespace Certificates.Views.DropDowns
{
public partial class CountriesDropDown : C1.Win.C1Input.DropDownForm
{
public CountriesDropDown()
{
InitializeComponent();
}
public event EventHandler<OnSelectedChangeEventArgs> OnSelectedChange;
public Dictionary<int, string> selected = new Dictionary<int, string>();
private void CountriesDropDown_Load(object sender, EventArgs e)
{
CountriesModel model = new CountriesModel();
Dictionary<string, object> filtres = new Dictionary<string, object>();
filtres.Add("_Name", null);
filtres.Add("_ID", null);
DataTable dt = model.GetList(filtres);
DataColumn col = new DataColumn("checked");
col.DefaultValue = false;
dt.Columns.Add(col);
MasterTGrid.SetDataBinding(dt, "", true);
SetCheckedAll(true);
}
private void MasterTGrid_AfterColEdit(object sender, C1.Win.C1TrueDBGrid.ColEventArgs e)
{
if (e == null || e.Column.DataColumn.DataField == "checked")
{
for (int i = 0; i < MasterTGrid.RowCount; i++)
{
int id = Convert.ToInt32(MasterTGrid[i, "ID"]);
string val = MasterTGrid[i, "Code"].ToString();
if (GetBoolRowValue(MasterTGrid[i, "checked"]))
{
if (!selected.ContainsKey(id))
{
selected.Add(id, val);
}
}
else
{
if (selected.ContainsKey(id))
{
selected.Remove(id);
}
}
}
if (OnSelectedChange != null)
{
OnSelectedChange(this, new OnSelectedChangeEventArgs(selected.Keys.ToList<int>(),
selected.Count==((DataTable)MasterTGrid.DataSource).Rows.Count?"Все":DicToString(selected)));
}
}
}
private string DicToString(Dictionary<int, string> dic)
{
string res = "";
foreach (KeyValuePair<int, string> kv in dic)
{
if (kv.Value != "")
{
if (res == "") res = kv.Value;
else res += "," + kv.Value;
}
}
return res;
}
private void SetCheckedAll(bool? value)
{
for (int i = 0; i < MasterTGrid.RowCount; i++)
{
if (value != null)
MasterTGrid[i, "checked"] = value;
else
MasterTGrid[i, "checked"] = !GetBoolRowValue(MasterTGrid[i, "checked"]);
MasterTGrid_AfterColEdit(this, null);
}
}
private bool GetBoolRowValue(object val)
{
return Convert.ToInt32(val.ToString() == "False" ? 0 : val.ToString() == "True" ? 1 : val) == 1 ? true : false;
}
private void SelectAll_Click(object sender, C1.Win.C1Command.ClickEventArgs e)
{
SetCheckedAll(true);
}
private void UnselectAll_Click(object sender, C1.Win.C1Command.ClickEventArgs e)
{
SetCheckedAll(false);
}
private void Inverce_Click(object sender, C1.Win.C1Command.ClickEventArgs e)
{
SetCheckedAll(null);
}
}
}