Esempio n. 1
0
 private void buttonDeleteParam_Click(object sender, EventArgs e)
 {
     if (propertyGrid1.SelectedGridItem != null)
     {
         int n = -1;
         for (int i = 0; i < RetParameters.Length; i++)
         {
             if (RetParameters[i] == propertyGrid1.SelectedGridItem.Value)
             {
                 n = i;
                 break;
             }
         }
         if (n >= 0)
         {
             if (RetParameters.Length <= 1)
             {
                 RetParameters = new ExecParameter[] { };
             }
             else
             {
                 ExecParameter[] a = new ExecParameter[RetParameters.Length - 1];
                 for (int i = 0; i < RetParameters.Length; i++)
                 {
                     if (i < n)
                     {
                         a[i] = RetParameters[i];
                     }
                     else if (i > n)
                     {
                         a[i - 1] = RetParameters[i];
                     }
                 }
                 RetParameters = a;
             }
             propertyGrid1.SelectedObject = RetParameters;
             propertyGrid1.Refresh();
         }
     }
 }
Esempio n. 2
0
        private void buttonAddParam_Click(object sender, EventArgs e)
        {
            int n = RetParameters.Length;

            ExecParameter[] rets = new ExecParameter[n + 1];
            RetParameters.CopyTo(rets, 0);
            rets[n]           = new ExecParameter();
            rets[n].Direction = ParameterDirection.Input;
            rets[n].DataSize  = 50;
            rets[n].Type      = System.Data.OleDb.OleDbType.VarWChar;
            int    k  = 1;
            string nm = "param1";

            while (true)
            {
                bool bFound = false;
                for (int j = 0; j < n; j++)
                {
                    if (string.Compare(nm, RetParameters[j].Name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        k++;
                        nm     = string.Format(CultureInfo.InvariantCulture, "param{0}", k);
                        bFound = true;
                        break;
                    }
                }
                if (!bFound)
                {
                    break;
                }
            }
            rets[n].Name  = nm;
            RetParameters = rets;
            propertyGrid1.SelectedObject = RetParameters;
            propertyGrid1.Refresh();
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             DatabaseExecuter der = context.Instance as DatabaseExecuter;
             if (der != null)
             {
                 string          sText = der.ExecutionCommand.SQL;
                 ExecParameter[] ps    = new ExecParameter[der.ExecutionCommand.ParamCount];
                 for (int i = 0; i < der.ExecutionCommand.ParamCount; i++)
                 {
                     ExecParameter p = new ExecParameter();
                     p.Name      = der.ExecutionCommand.Param_Name[i];
                     p.Type      = der.ExecutionCommand.Param_OleDbType[i];
                     p.DataSize  = der.Param_DataSize[i];
                     p.Direction = der.Param_Directions[i];
                     ps[i]       = p;
                 }
                 DialogDbCommand dlg = new DialogDbCommand();
                 dlg.LoadData(sText, der.IsStoredProc, ps);
                 if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                 {
                     SQLNoneQuery sq = new SQLNoneQuery();
                     sq.CommandType = enmNonQueryType.StoredProcedure;
                     sq.SQL         = dlg.RetSQL;
                     ps             = dlg.RetParameters;
                     string[]             names = new string[dlg.RetParameters.Length];
                     OleDbType[]          types = new OleDbType[dlg.RetParameters.Length];
                     int[]                sizes = new int[dlg.RetParameters.Length];
                     ParameterDirection[] pds   = new ParameterDirection[dlg.RetParameters.Length];
                     //
                     for (int i = 0; i < dlg.RetParameters.Length; i++)
                     {
                         names[i] = dlg.RetParameters[i].Name;
                         types[i] = dlg.RetParameters[i].Type;
                         sizes[i] = dlg.RetParameters[i].DataSize;
                         pds[i]   = dlg.RetParameters[i].Direction;
                     }
                     //
                     sq.Param_Name        = names;
                     sq.Param_OleDbType   = types;
                     der.ExecutionCommand = sq;
                     DbParameterList pl = new DbParameterList(sq.Parameters);
                     der.SetParameterList(pl);
                     der.Param_DataSize   = sizes;
                     der.Param_Directions = pds;
                     if (dlg.IsStoredProc)
                     {
                         sq.CommandType = enmNonQueryType.StoredProcedure;
                     }
                     else
                     {
                         sq.CommandType = enmNonQueryType.Script;
                     }
                     value = sq;
                 }
             }
         }
     }
     return(value);
 }