コード例 #1
0
        public void ExecMethod(string methodName, out string valueType, out object returnValue)
        {
            DataTable dtMethod = _dao.GetMethod(methodName);

            if (dtMethod.Rows.Count == 0)
            {
                valueType   = "";
                returnValue = "";
                return;
            }
            DataRow row = dtMethod.Rows[0];

            valueType   = row["VALUETYPE"].ToString();
            returnValue = "";
            switch (valueType)
            {
            case "字符":
            case "日期":
                if (row["METHODTYPE"].ToString() == "SYSTEM")
                {
                    switch (methodName)
                    {
                    case "GetOperatorID": returnValue = _operatorId; break;

                    case "GetOperator": returnValue = _operatorName; break;

                    case "GetOprOffice": returnValue = _operatorOffice; break;

                    case "Now": returnValue = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); break;

                    case "Date": returnValue = System.DateTime.Today.ToShortDateString(); break;
                    }
                }
                else
                {
                    DataTable dt;
                    try
                    {
                        dt = _dao.ExecSQL(row["DETAIL"].ToString());
                    }
                    catch
                    {
                        dt = null;
                    }
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            returnValue = dt.Rows[0][0].ToString();
                        }
                    }
                }
                break;

            case "数据集":
                try
                {
                    returnValue = _dao.ExecSQL(row["DETAIL"].ToString());
                }
                catch
                {
                    returnValue = null;
                }
                break;
            }
        }
コード例 #2
0
        private void ExeQuery()
        {
            string      sql        = string.Empty;
            IEnumerator enumerator = _solution.DataSetList.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SnDataSet temp = enumerator.Current as SnDataSet;

                switch (temp.DataSetType)
                {
                case DataSetType.Page:
                    #region Page
                    Hashtable htParam = new Hashtable();
                    sql = temp.SQLExpression;
                    IEnumerator enumControl = _componentContainer.GetEnumerator();
                    while (enumControl.MoveNext())
                    {
                        ICommonAttribute commonAttribute = enumControl.Current as ICommonAttribute;
                        if (commonAttribute != null && !string.IsNullOrEmpty(commonAttribute.ParamName))
                        {
                            if (commonAttribute.DataSetName == "所有数据集" ||
                                temp.DataSetID + "-" + temp.DataSetName == commonAttribute.DataSetName)
                            {
                                string paramName = commonAttribute.ParamName, paramType = commonAttribute.ParamType, value = commonAttribute.Value;
                                if (!htParam.ContainsKey(paramName))
                                {
                                    switch (paramType)
                                    {
                                    case "String":
                                        htParam.Add(paramName, value);
                                        break;

                                    case "Int":
                                        htParam.Add(paramName, Convert.ToInt32(value));
                                        break;

                                    case "Decimal":
                                        htParam.Add(paramName, Convert.ToDecimal(value));
                                        break;

                                    case "DateTime":
                                        htParam.Add(paramName, Convert.ToDateTime(value));
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    string strParam = "";
                    if (htParam != null)
                    {
                        foreach (DictionaryEntry de in htParam)
                        {
                            strParam += string.Format("{0}:{1}->{2}\r\n",
                                                      de.Value.GetType().Name, de.Key, de.Value);
                        }
                    }
                    WriteLog(sql + "\r\n" + strParam);
                    try
                    {
                        _masterDataSource = _dao.ExecSQL(sql, htParam);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "查询失败");
                        WriteLog(ex.Message);
                        return;
                    }
                    IEnumerator enumGridControl = _componentContainer.GetEnumerator();
                    while (enumGridControl.MoveNext())
                    {
                        GridControl grd = enumGridControl.Current as GridControl;
                        if (grd != null)
                        {
                            grd.BeginUpdate();
                            if (string.IsNullOrEmpty(grd.Text))
                            {
                                grd.DataSource = _masterDataSource.DefaultView;
                            }
                            else if (grd.Text == temp.DataSetID)
                            {
                                grd.DataSource = _masterDataSource.DefaultView;
                            }
                            //_currentRecordCount = _masterDataSource.Rows.Count;
                            grd.EndUpdate();
                            //toolMoreRow.Enabled = (_currentRecordCount != _maxRecordCount);
                            Size = new Size(Size.Width, Size.Height + 1);
                            Size = new Size(Size.Width, Size.Height - 1);
                        }
                    }
                    #endregion
                    break;

                case DataSetType.Proc:
                    #region Proc
                    //string procName = temp.DataSetName;
                    //enumControl = _componentContainer.GetEnumerator();

                    //Dictionary<string, object> dic = new Dictionary<string, object>();
                    //while (enumControl.MoveNext())
                    //{
                    //    ICommonAttribute commonAttribute = enumControl.Current as ICommonAttribute;

                    //    if (commonAttribute != null)
                    //    {
                    //        if (temp.DataSetID + "-" + temp.DataSetName == commonAttribute.DataSetName)
                    //        {
                    //            if (string.IsNullOrEmpty(commonAttribute.ProcParamName))
                    //                throw new Exception("存储过程参数名称不能为空");
                    //            Type t = Type.GetType("System." + commonAttribute.ProcParamType, false, true);

                    //            if (commonAttribute is SnControl.ParamComboBox)
                    //            {
                    //                SnControl.ParamComboBox combox = (commonAttribute as SnControl.ParamComboBox);
                    //                if (!string.IsNullOrEmpty(combox.ValueMember))
                    //                {
                    //                    dic.Add(commonAttribute.ProcParamName.ToUpper(), combox.SelectedValue);
                    //                    continue;
                    //                }
                    //            }
                    //            else if (commonAttribute is SnControl.ParamRadioButton)
                    //            {
                    //                SnControl.ParamRadioButton radioButton = (commonAttribute as SnControl.ParamRadioButton);
                    //                if (radioButton.Checked)
                    //                    dic.Add(commonAttribute.ProcParamName.ToUpper(), radioButton.Value);
                    //                continue;
                    //            }
                    //            else if (commonAttribute is SnControl.Search)
                    //            {
                    //                SnControl.Search search = (commonAttribute as SnControl.Search);
                    //                if (!string.IsNullOrEmpty(search.Value))
                    //                {
                    //                    dic.Add(commonAttribute.ProcParamName.ToUpper(), search.Value);
                    //                    continue;
                    //                }
                    //            }
                    //            if (t.Name == "String")
                    //            {
                    //                dic.Add(commonAttribute.ProcParamName.ToUpper(), commonAttribute.Text);
                    //            }
                    //            else
                    //            {
                    //                object value = null;
                    //                try
                    //                {
                    //                    if (commonAttribute.Text == string.Empty)
                    //                        value = t.IsValueType ? Activator.CreateInstance(t) : null;
                    //                    else
                    //                        value = t.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { commonAttribute.Text });
                    //                }
                    //                catch (Exception)
                    //                {
                    //                    throw new Exception("数据类型不匹配,请检查");
                    //                }
                    //                dic.Add(commonAttribute.ProcParamName.ToUpper(), value);
                    //            }
                    //        }
                    //    }
                    //}

                    //string strParam2 = "";
                    //foreach (var de in dic)
                    //{
                    //    strParam2 += string.Format("{0}<->{1}<->{2}\r\n",
                    //       de.Value.GetType().Name, de.Key, de.Value);
                    //}
                    //WriteLog(procName + "\r\n" + strParam2);
                    //_masterDataSource = _dao.ExecProc(procName, dic);

                    //enumGridControl = _componentContainer.GetEnumerator();

                    //while (enumGridControl.MoveNext())
                    //{
                    //    GridControl grd = enumGridControl.Current as GridControl;
                    //    if (grd != null)
                    //    {
                    //        grd.BeginUpdate();

                    //        grd.DataSource = _masterDataSource.DefaultView;

                    //        //_currentRecordCount = _masterDataSource.Rows.Count;

                    //        grd.EndUpdate();
                    //        //toolMoreRow.Enabled = (_currentRecordCount != _maxRecordCount);

                    //        Size = new Size(Size.Width, Size.Height + 1);
                    //        Size = new Size(Size.Width, Size.Height - 1);
                    //    }
                    //}
                    #endregion
                    break;
                }
            }
        }