public static ParametersToDataGridView ( System.Windows.Forms.DataGridView dg, IEcasParameterized p, IEcasObject objDefaults ) : void | ||
dg | System.Windows.Forms.DataGridView | |
p | IEcasParameterized | |
objDefaults | IEcasObject | |
Résultat | void |
public static void ParametersToDataGridView(DataGridView dg,
IEcasParameterized p, IEcasObject objDefaults)
{
if(dg == null) throw new ArgumentNullException("dg");
if(p == null) throw new ArgumentNullException("p");
if(p.Parameters == null) throw new ArgumentException();
if(objDefaults == null) throw new ArgumentNullException("objDefaults");
if(objDefaults.Parameters == null) throw new ArgumentException();
dg.Rows.Clear();
dg.Columns.Clear();
Color clrBack = dg.DefaultCellStyle.BackColor;
Color clrValueBack = dg.DefaultCellStyle.BackColor;
if(clrValueBack.GetBrightness() >= 0.5)
clrValueBack = UIUtil.DarkenColor(clrValueBack, 0.075);
else clrValueBack = UIUtil.LightenColor(clrValueBack, 0.075);
dg.ColumnHeadersVisible = false;
dg.RowHeadersVisible = false;
dg.GridColor = clrBack;
dg.BackgroundColor = clrBack;
dg.DefaultCellStyle.SelectionBackColor = clrBack;
dg.DefaultCellStyle.SelectionForeColor = dg.DefaultCellStyle.ForeColor;
dg.EditMode = DataGridViewEditMode.EditOnEnter;
dg.AllowDrop = false;
dg.AllowUserToAddRows = false;
dg.AllowUserToDeleteRows = false;
dg.AllowUserToOrderColumns = false;
dg.AllowUserToResizeColumns = false;
dg.AllowUserToResizeRows = false;
int nWidth = (dg.ClientSize.Width - UIUtil.GetVScrollBarWidth());
dg.Columns.Add("Name", KPRes.FieldName);
dg.Columns.Add("Value", KPRes.FieldValue);
dg.Columns[0].Width = (nWidth / 2);
dg.Columns[1].Width = (nWidth / 2);
for(int i = 0; i < p.Parameters.Length; ++i)
{
EcasParameter ep = p.Parameters[i];
dg.Rows.Add();
DataGridViewRow row = dg.Rows[dg.Rows.Count - 1];
DataGridViewCellCollection cc = row.Cells;
Debug.Assert(cc.Count == 2);
cc[0].Value = ep.Name;
cc[0].ReadOnly = true;
string strParam = EcasUtil.GetParamString(objDefaults.Parameters, i);
DataGridViewCell c = null;
switch(ep.Type)
{
case EcasValueType.String:
c = new DataGridViewTextBoxCell();
c.Value = strParam;
break;
case EcasValueType.Bool:
c = new DataGridViewCheckBoxCell(false);
(c as DataGridViewCheckBoxCell).Value =
StrUtil.StringToBool(strParam);
break;
case EcasValueType.EnumStrings:
DataGridViewComboBoxCell cmb = new DataGridViewComboBoxCell();
cmb.Sorted = false;
cmb.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
int iFound = -1;
for(int e = 0; e < ep.EnumValues.ItemCount; ++e)
{
EcasEnumItem eei = ep.EnumValues.Items[e];
cmb.Items.Add(eei.Name);
if(eei.ID.ToString() == strParam) iFound = e;
}
if(iFound >= 0) cmb.Value = ep.EnumValues.Items[iFound].Name;
else if(ep.EnumValues.ItemCount > 0) cmb.Value = ep.EnumValues.Items[0].Name;
else { Debug.Assert(false); }
c = cmb;
break;
case EcasValueType.Int64:
c = new DataGridViewTextBoxCell();
c.Value = FilterTypeI64(strParam);
break;
case EcasValueType.UInt64:
c = new DataGridViewTextBoxCell();
c.Value = FilterTypeU64(strParam);
break;
default:
Debug.Assert(false);
break;
}
if(c != null) cc[1] = c;
cc[1].ReadOnly = false;
cc[1].Style.BackColor = clrValueBack;
cc[1].Style.SelectionBackColor = clrValueBack;
}
}
public static bool UpdateDialog(EcasObjectType objType, ComboBox cmbTypes, DataGridView dgvParams, IEcasObject o, bool bGuiToInternal, EcasTypeDxMode dxType) { bool bResult = true; try { if (bGuiToInternal) { IEcasParameterized eTypeInfo = null; if (dxType == EcasTypeDxMode.Selection) { string strSel = (cmbTypes.SelectedItem as string); if (!string.IsNullOrEmpty(strSel)) { if (objType == EcasObjectType.Event) { eTypeInfo = Program.EcasPool.FindEvent(strSel); o.Type = eTypeInfo.Type; } else if (objType == EcasObjectType.Condition) { eTypeInfo = Program.EcasPool.FindCondition(strSel); o.Type = eTypeInfo.Type; } else if (objType == EcasObjectType.Action) { eTypeInfo = Program.EcasPool.FindAction(strSel); o.Type = eTypeInfo.Type; } else { Debug.Assert(false); } } } else if (dxType == EcasTypeDxMode.ParamsTag) { IEcasParameterized p = (dgvParams.Tag as IEcasParameterized); if ((p != null) && (p.Type != null)) { eTypeInfo = p; o.Type = eTypeInfo.Type; } else { Debug.Assert(false); } } EcasUtil.DataGridViewToParameters(dgvParams, o, eTypeInfo); } else // Internal to GUI { if (dxType == EcasTypeDxMode.Selection) { if (o.Type.Equals(PwUuid.Zero)) { cmbTypes.SelectedIndex = 0; } else { int i = -1; if (objType == EcasObjectType.Event) { i = cmbTypes.FindString(Program.EcasPool.FindEvent(o.Type).Name); } else if (objType == EcasObjectType.Condition) { i = cmbTypes.FindString(Program.EcasPool.FindCondition(o.Type).Name); } else if (objType == EcasObjectType.Action) { i = cmbTypes.FindString(Program.EcasPool.FindAction(o.Type).Name); } else { Debug.Assert(false); } if (i >= 0) { cmbTypes.SelectedIndex = i; } else { Debug.Assert(false); } } } else { Debug.Assert(dxType != EcasTypeDxMode.ParamsTag); } IEcasParameterized t = null; if (objType == EcasObjectType.Event) { t = Program.EcasPool.FindEvent(cmbTypes.SelectedItem as string); } else if (objType == EcasObjectType.Condition) { t = Program.EcasPool.FindCondition(cmbTypes.SelectedItem as string); } else if (objType == EcasObjectType.Action) { t = Program.EcasPool.FindAction(cmbTypes.SelectedItem as string); } else { Debug.Assert(false); } if (t != null) { EcasUtil.ParametersToDataGridView(dgvParams, t, o); } } } catch (Exception e) { MessageService.ShowWarning(e); bResult = false; } return(bResult); }