KeePass.Ecas.EcasUtil.DataGridViewToParameters C# (CSharp) Method

DataGridViewToParameters() public static method

public static DataGridViewToParameters ( System.Windows.Forms.DataGridView dg, IEcasObject objOut, IEcasParameterized eTypeInfo ) : void
dg System.Windows.Forms.DataGridView
objOut IEcasObject
eTypeInfo IEcasParameterized
return void
        public static void DataGridViewToParameters(DataGridView dg, IEcasObject objOut,
            IEcasParameterized eTypeInfo)
        {
            if(dg == null) throw new ArgumentNullException("dg");
            if(objOut == null) throw new ArgumentNullException("objOut");
            // if(vParamDesc == null) throw new ArgumentNullException("vParamDesc");
            // if(dg.Rows.Count != vParamDesc.Length) { Debug.Assert(false); return; }

            objOut.Parameters.Clear();

            bool bTypeInfoValid = ((eTypeInfo != null) && (eTypeInfo.Parameters.Length ==
                dg.Rows.Count));

            for(int i = 0; i < dg.RowCount; ++i)
            {
                DataGridViewCell c = dg.Rows[i].Cells[1];
                object oValue = c.Value;
                string strValue = ((oValue != null) ? oValue.ToString() : string.Empty);

                if(bTypeInfoValid && (eTypeInfo.Parameters[i].EnumValues != null) &&
                    (c is DataGridViewComboBoxCell))
                {
                    objOut.Parameters.Add(eTypeInfo.Parameters[i].EnumValues.GetItemID(
                        strValue, 0).ToString());
                }
                else objOut.Parameters.Add(strValue);
            }
        }

Usage Example

コード例 #1
0
ファイル: EcasUtil.cs プロジェクト: vallades/KeePass2.x
        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);
        }