public static bool TryGetAttribute(this IHasAttributes hasAttributes, string attributeTypeFullName, out ICommonAttribute foundCommonAttribute)
 {
     return((foundCommonAttribute = hasAttributes.GetAttribute(attributeTypeFullName)) != null);
 }
 public static bool TryGetAttribute(this IHasAttributes hasAttributes, IHasType attributeHasType, out ICommonAttribute foundCommonAttribute)
 {
     return((foundCommonAttribute = hasAttributes.GetAttribute(attributeHasType)) != null);
 }
 public static bool TryGetAttribute <TAttribute>(this IHasAttributes hasAttributes, out ICommonAttribute foundCommonAttribute) where TAttribute : Attribute
 {
     return((foundCommonAttribute = hasAttributes.GetAttribute <TAttribute>()) != null);
 }
Esempio n. 4
0
        private void toolView_Click(object sender, EventArgs e)
        {
            IEnumerator enumControl         = _componentContainer.GetEnumerator();
            DataView    dt                  = null;
            Dictionary <string, string> dic = new Dictionary <string, string>();
            SnDataSet   temp                = _solution.DataSetList[0] as SnDataSet;
            GridControl grd                 = null;

            while (enumControl.MoveNext())
            {
                ICommonAttribute commonAttribute = enumControl.Current as ICommonAttribute;
                if (commonAttribute != null)
                {
                    if (temp.DataSetName == commonAttribute.DataSetName)
                    {
                        dic.Add(commonAttribute.ParamName, commonAttribute.Value);
                    }
                }
            }
            var       enumGridControl = _componentContainer.GetEnumerator();
            Hashtable htControls      = new Hashtable();

            while (enumGridControl.MoveNext())
            {
                GridControl grid = enumGridControl.Current as GridControl;
                if (grid != null)
                {
                    List <string> filter = new List <string>();
                    DevExpress.XtraGrid.Views.Grid.GridView view = grid.Views[0] as DevExpress.XtraGrid.Views.Grid.GridView;

                    foreach (GridColumn gcc in view.SortedColumns)
                    {
                        filter.Add(gcc.FieldName + " " + (gcc.SortOrder == ColumnSortOrder.Descending ? "DESC" : ""));
                    }
                    DataView dv = grid.DataSource as DataView;
                    if (dv != null)
                    {
                        dv.Sort = string.Join(",", filter.ToArray());
                        dt      = dv;
                    }
                    grd = grid;
                    //break;
                }
                if (!enumGridControl.Current.GetType().Equals(typeof(Column)))
                {
                    Control ctl = (Control)enumGridControl.Current;
                    htControls.Add(ctl.Name, ctl.Text);
                }
            }
            if (dt == null)
            {
                MessageBox.Show("数据源没有数据");
            }
            else
            {
                if (string.IsNullOrEmpty(temp.ReportPath))
                {
                    if (grd != null)
                    {
                        if (PrintHelper.IsPrintingAvailable)
                        {
                            PrintHelper.ShowPreview(grd);
                        }
                        else
                        {
                            MessageBox.Show("打印组件库没有发现!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    Print(htControls, dic, dt, temp.ReportPath, false);
                }
            }
        }
Esempio n. 5
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;
                }
            }
        }
Esempio n. 6
0
 public FakeCommonAssemblyBuilder AddCommonAttribute(ICommonAttribute attribute)
 {
     commonAttributes.Add(attribute);
     return(this);
 }