private void dataList_DoubleClick(object sender, EventArgs e) { if (this.dataList.SelectedItems != null && dataList.SelectedItems.Count > 0) { SnDataSet dataset = (SnDataSet)dataList.SelectedItems[0].Tag; FormDataSource form = new FormDataSource(); form.UseType = dataset.DataSetType.GetHashCode(); form.DataSetID = dataset.DataSetID; form.DataSetChineseName = dataset.DataSetName; form.ReportPath = dataset.ReportPath; if (form.ShowDialog() == DialogResult.OK) { bool hasPage = false; foreach (ListViewItem item in dataList.Items) { if (item.SubItems[2].Text == "Page") { hasPage = false; break; } } if (hasPage && ((DataSetType)form.UseType).ToString() == "Page") { MessageBox.Show("每一个数据集合只能有一个用查询的Page数据集!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } dataset.DataSetID = form.DataSetID; dataset.DataSetName = form.DataSetChineseName; dataset.DataSetType = (DataSetType)form.UseType; dataset.ReportPath = form.ReportPath; } } }
private void menuDataSource_Click(object sender, EventArgs e) { if (_viewContentCollection.Count > 0) { FormQueryData form = new FormQueryData(); form.Solution = SolutionInstance.GetInstance().Solution; if (form.ShowDialog() == DialogResult.OK) { if (ActiveViewContent != null) { FormContent fc = (FormContent)ActiveViewContent; fc.Text = SolutionInstance.GetInstance().Solution.SolutionName + "*"; fc.IsDirty = true; if (SolutionInstance.GetInstance().Solution.DataSetList.Count == 0) { return; } SnDataSet ds = SolutionInstance.GetInstance().Solution.DataSetList[0] as SnDataSet; foreach (IComponent ctrl in fc.ViewContent.Host.Container.Components) { if (ctrl is ParamTextBox || ctrl is ParamComboBox || ctrl is ParamDateTimePicker || ctrl is ParamRadioButton || ctrl is Search) { (ctrl as ICommonAttribute).DataSetName = ds.DataSetID + "-" + ds.DataSetName; } } } } } else { MessageBox.Show("请先定义查询方案!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void dataList_SelectedIndexChanged(object sender, EventArgs e) { if (dataList.SelectedItems.Count != 1) { return; } _currDataSet = (SnDataSet)(this.Solution.DataSetList[dataList.SelectedItems[0].Index]); this.RefreshSQL(); this.RefreshParams(); this.RefreshColumns(); this.tab.SelectedIndex = 0; }
private void menuDelete_Click(object sender, EventArgs e) { if (dataList.SelectedItems.Count == 1) { for (int i = 0; i < this.Solution.DataSetList.Count; i++) { SnDataSet temp = (SnDataSet)this.Solution.DataSetList[i]; if (temp.DataSetID == dataList.SelectedItems[0].SubItems[0].Text) { this.Solution.DataSetList.Remove(dataList.SelectedItems[0].Tag); dataList.Items.Remove(dataList.SelectedItems[0]); } } } }
private void ShowDataList() { IEnumerator enumerator = this.Solution.DataSetList.GetEnumerator(); while (enumerator.MoveNext()) { SnDataSet temp = enumerator.Current as SnDataSet; ListViewItem item = dataList.Items.Add(temp.DataSetID); item.Tag = temp; item.SubItems.Add(temp.DataSetName); item.SubItems.Add(temp.DataSetType.ToString()); } if (this.Solution.DataSetList.Count > 0) { dataList.TopItem.Selected = true; } }
private void menuNew_Click(object sender, EventArgs e) { FormDataSource form = new FormDataSource(); form.UseType = 0; form.DataSetID = "dataSet" + (dataList.Items.Count + 1); form.DataSetChineseName = "数据集" + (dataList.Items.Count + 1); if (form.ShowDialog() == DialogResult.OK) { bool hasPage = false; foreach (ListViewItem item in dataList.Items) { if (item.SubItems[2].Text == "Page") { hasPage = false; break; } } if (hasPage && ((DataSetType)form.UseType).ToString() == "Page") { MessageBox.Show("每一个数据集合只能有一个用查询的Page数据集!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SnDataSet dataset = new SnDataSet(); dataset.DataSetID = form.DataSetID; dataset.DataSetName = form.DataSetChineseName; dataset.DataSetType = (DataSetType)form.UseType; dataset.ReportPath = form.ReportPath; dataset.DataType = "自定义"; _currDataSet = dataset; this.Solution.DataSetList.Add(dataset); ListViewItem listViewItem = dataList.Items.Add(dataset.DataSetID); listViewItem.Tag = dataset; listViewItem.SubItems.Add(dataset.DataSetName); listViewItem.SubItems.Add(dataset.DataSetType.ToString()); listViewItem.Selected = true; } }
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); } } }
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; } } }
private object CreateObject(XmlElement xmlElement, bool suspend) { Type type = GetTypeByName(xmlElement.Name); if (xmlElement.Attributes["value"] != null) { try { return(Convert.ChangeType(xmlElement.Attributes["value"].InnerText, type)); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (type == null) { return(null); } object newObj; if (type.FullName == "System.Windows.Forms.Form") { newObj = this.mainPanel; } else if (type.FullName == "System.Windows.Forms.DataGridView") { GridControl grdEntity = new GridControl(); grdEntity.Name = "grdEntity"; grdEntity.Dock = DockStyle.Fill; grdEntity.LookAndFeel.UseWindowsXPTheme = true; XmlNode nodeTmp = xmlElement.SelectSingleNode("DataMember"); if (nodeTmp != null) { grdEntity.Text = nodeTmp.Attributes["value"].Value; } GridView viewEntity = new GridView(); viewEntity.Appearance.GroupPanel.Options.UseBackColor = true; viewEntity.Appearance.GroupPanel.BackColor = Color.SkyBlue; viewEntity.Appearance.GroupPanel.BackColor2 = Color.White; viewEntity.Appearance.FocusedRow.Options.UseBackColor = true; viewEntity.Appearance.FocusedRow.BackColor = Color.FromArgb(51, 153, 255); viewEntity.Appearance.HideSelectionRow.Options.UseBackColor = true; viewEntity.Appearance.HideSelectionRow.BackColor = Color.FromArgb(51, 153, 255); viewEntity.Appearance.HideSelectionRow.Options.UseForeColor = true; viewEntity.Appearance.HideSelectionRow.ForeColor = Color.White; viewEntity.OptionsView.ColumnAutoWidth = false; //viewEntity.OptionsView.ShowGroupPanel = false; //viewEntity.OptionsCustomization.AllowFilter = false; viewEntity.GroupPanelText = "查询结果"; viewEntity.OptionsBehavior.Editable = false; viewEntity.GroupFooterShowMode = GroupFooterShowMode.VisibleIfExpanded; viewEntity.OptionsView.ShowDetailButtons = false; viewEntity.OptionsView.ShowFooter = true; viewEntity.FocusRectStyle = DrawFocusRectStyle.None; viewEntity.GridControl = grdEntity; viewEntity.Name = "GirdView"; viewEntity.OptionsSelection.EnableAppearanceFocusedCell = false; viewEntity.PaintStyleName = "WindowsXP"; viewEntity.RowHeight = 25; viewEntity.ColumnPanelRowHeight = 30; viewEntity.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways; GridGroupSummaryItem summaryItem; IEnumerator enumerator = _solution.DataSetList.GetEnumerator(); SnDataSet temp = null; while (enumerator.MoveNext()) { temp = enumerator.Current as SnDataSet; if (temp.DataSetID != grdEntity.Text && !string.IsNullOrEmpty(grdEntity.Text)) { continue; } for (int i = 0; i < temp.FieldsList.Count; i++) { GridColumn gridColumn = new GridColumn(); gridColumn.FieldName = temp.FieldsList[i].FieldName; gridColumn.Caption = temp.FieldsList[i].FieldChineseName; gridColumn.Width = temp.FieldsList[i].DisplayWidth > 0 ? temp.FieldsList[i].DisplayWidth : 90; if (!temp.FieldsList[i].ColumnVisible) { gridColumn.Visible = false; gridColumn.VisibleIndex = -1; } else { gridColumn.VisibleIndex = i; } switch (temp.FieldsList[i].CalcType) { case "Sum": summaryItem = new GridGroupSummaryItem(); summaryItem.FieldName = temp.FieldsList[i].FieldChineseName; summaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum; summaryItem.DisplayFormat = "合计:{0:0.00}"; summaryItem.ShowInGroupColumnFooter = gridColumn; viewEntity.GroupSummary.Add(summaryItem); gridColumn.SummaryItem.DisplayFormat = "合计:{0:0.00}"; gridColumn.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum; break; case "Average": summaryItem = new GridGroupSummaryItem(); summaryItem.FieldName = temp.FieldsList[i].FieldChineseName; summaryItem.SummaryType = DevExpress.Data.SummaryItemType.Average; summaryItem.DisplayFormat = "均值:{0:c2}"; summaryItem.ShowInGroupColumnFooter = gridColumn; viewEntity.GroupSummary.Add(summaryItem); gridColumn.SummaryItem.DisplayFormat = "均值:{0:c}"; gridColumn.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Average; break; case "Max": gridColumn.SummaryItem.DisplayFormat = "最大:{0:c}"; gridColumn.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Max; break; case "Min": gridColumn.SummaryItem.DisplayFormat = "最小:{0:c}"; gridColumn.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Min; break; case "Count": gridColumn.SummaryItem.DisplayFormat = "行数:{0:d}"; gridColumn.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count; break; default: gridColumn.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.None; break; } foreach (StyleFormat s in temp.FieldsList[i].StyleFormat) { DevExpress.XtraGrid.StyleFormatCondition styleFormatCondition = new DevExpress.XtraGrid.StyleFormatCondition(); styleFormatCondition.Column = gridColumn; styleFormatCondition.Appearance.Options.UseForeColor = true; styleFormatCondition.Appearance.Options.UseBackColor = true; styleFormatCondition.Appearance.BackColor = System.Drawing.Color.FromArgb(s.BackColorRed, s.BackColorGreen, s.BackColorBlue); styleFormatCondition.Appearance.ForeColor = System.Drawing.Color.FromArgb(s.ForeColorRed, s.ForeColorGreen, s.ForeColorBlue); styleFormatCondition.ApplyToRow = s.ApplyToRow; styleFormatCondition.Condition = s.Condition; if (s.Value1 != null) { styleFormatCondition.Value1 = s.Value1.ToString() != "<Null>" ? GetValueByTypeName(s.Type1, s.Value1) : "<Null>"; } if (s.Value2 != null) { styleFormatCondition.Value2 = s.Value2.ToString() != "<Null>" ? GetValueByTypeName(s.Type2, s.Value2) : "<Null>"; } viewEntity.FormatConditions.Add(styleFormatCondition); } switch (temp.FieldsList[i].FieldType.ToUpper()) { case "TIMESTAMP": case "DATETIME": gridColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime; break; case "DECIMAL": if (temp.FieldsList[i].DecimalDigits == 0 && temp.FieldsList[i].DecimalDigits > 6) { temp.FieldsList[i].DecimalDigits = 2; } string tempstr = "0."; for (int j = 0; j < temp.FieldsList[i].DecimalDigits; j++) { tempstr += "0"; } gridColumn.DisplayFormat.FormatString = tempstr; gridColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom; break; case "INT": gridColumn.DisplayFormat.FormatString = "0"; gridColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom; break; } viewEntity.Columns.Add(gridColumn); } if (File.Exists(FileName + grdEntity.Text + ".xml")) { viewEntity.RestoreLayoutFromXml(FileName + grdEntity.Text + ".xml"); } } grdEntity.MainView = viewEntity; newObj = grdEntity; _componentContainer.Add(newObj); } else { newObj = type.Assembly.CreateInstance(type.FullName); _componentContainer.Add(newObj); } string componentName = null; if (xmlElement["Name"] != null && xmlElement["Name"].Attributes["value"] != null) { componentName = xmlElement["Name"].Attributes["value"].InnerText; } bool hasSuspended = false; if (suspend && newObj is ContainerControl) { hasSuspended = true; ((Control)newObj).SuspendLayout(); } foreach (XmlNode subNode in xmlElement.ChildNodes) { if (subNode is XmlElement) { XmlElement subElement = (XmlElement)subNode; if (subElement.Attributes["value"] != null) { try { SetValue(newObj, subElement.Name, subElement.Attributes["value"].InnerText); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { PropertyInfo propertyInfo = newObj.GetType().GetProperty(subElement.Name); object pList = propertyInfo.GetValue(newObj, null); if (pList is IList) { foreach (XmlNode node in subElement.ChildNodes) { if (node is XmlElement) { XmlElement cNode = node as XmlElement; object collectionObj = CreateObject(cNode, false); if (collectionObj != null) { try { ((IList)pList).Add(collectionObj); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } } } } if (_acceptButton != null && newObj is Form) { ((Form)newObj).AcceptButton = (IButtonControl)Container.Components[_acceptButton]; _acceptButton = null; } if (_cancelButton != null && newObj is Form) { ((Form)newObj).CancelButton = (IButtonControl)Container.Components[_cancelButton]; _cancelButton = null; } if (hasSuspended) { ((Control)newObj).ResumeLayout(false); } return(newObj); }