public virtual void Open(string workSetName) { try { var sys_WorkSet = WorkSetList.Find(w => w.WorkSet_Name == workSetName); if (sys_WorkSet != null) { if (string.IsNullOrEmpty(sys_WorkSet.WorkSet_Trigger)) { if (sys_WorkSet.WorkSet_Control != null && sys_WorkSet.WorkSet_Control.GetType().Equals(typeof(GridControl))) { GridControl gd = (GridControl)sys_WorkSet.WorkSet_Control; if (gd != null) { List <MyParameter> QueryParameters = InitializeBind(sys_WorkSet.WorkSet_Id, true); SetSource(gd, BaseService.Open(sys_WorkSet.WorkSet_Name, QueryParameters)); } } if (sys_WorkSet.WorkSet_Control != null && sys_WorkSet.WorkSet_Control.GetType().Equals(typeof(ChartControl))) { ChartControl chart = (ChartControl)sys_WorkSet.WorkSet_Control; if (chart != null) { List <MyParameter> QueryParameters = InitializeBind(sys_WorkSet.WorkSet_Id, true); chart.DataSource = BaseService.Open(sys_WorkSet.WorkSet_Name, QueryParameters); } } } } } catch (Exception ex) { throw ex; } }
public virtual void Design() { try { if (FocusedChart() != null) { ChartControl chartControl = FocusedChart(); Sys_WorkSet sys_WorkSet = WorkSetList.Find(w => w.WorkSet_Grid == chartControl.Name); if (sys_WorkSet == null) { return; } List <MyParameter> mps = new List <MyParameter>(); mps = InitializeBind(sys_WorkSet.WorkSet_Id, true); DataTable dt = BaseService.Open(sys_WorkSet.WorkSet_Id, mps); chartControl.DataSource = dt; ChartDesigner chartDesigner = new ChartDesigner(chartControl); if (chartDesigner.ShowDialog().Equals(DialogResult.OK)) { MemoryStream memoryStream = new MemoryStream(); chartControl.SaveToStream(memoryStream); Sys_Chart sys_Chart = new Sys_Chart(); sys_Chart.Chart_Name = chartControl.Name; sys_Chart.Chart_Nick = chartControl.Name; sys_Chart.Chart_Bytes = memoryStream.ToArray(); sys_Chart.Chart_WorkSet = sys_WorkSet.WorkSet_Id; sys_Chart.IsEnabled = true; sys_Chart.IsDelete = false; BaseService.Execute("SystemChart_Save", sys_Chart); } } } catch (Exception ex) { throw ex; } }
/// <summary> /// 取得字段绑定的值 /// </summary> /// <param name="sys_Bind"></param> /// <returns></returns> private object InitializeParameter(Sys_Bind sys_Bind) { object val = null; //if (sys_Bind.Bind_Field.StartsWith("val:")) //{ // val = sys_Bind.Bind_Field.Remove(0, 4); //} object control = sys_Bind.Bind_Control; //没有绑定过控件 绑定Sys_Bind到相应控件 if (control == null) { if (sys_Bind.Bind_Field.IndexOf(".") > 0) { string gd = sys_Bind.Bind_Field.Substring(0, sys_Bind.Bind_Field.IndexOf(".")); Control[] bindControls = this.Controls.Find(gd, true); if (bindControls.Length > 0) { if (bindControls[0].GetType().Equals(typeof(GridControl))) { GridControl tgd = (GridControl)bindControls[0]; GridView tabv = (GridView)tgd.MainView; string col = sys_Bind.Bind_Field.Substring(sys_Bind.Bind_Field.IndexOf(".") + 1); sys_Bind.Bind_Control = tabv.Columns[col]; } } } else { //优先绑定Edit控件 Control[] bindControls = this.Controls.Find(sys_Bind.Bind_Field, true); if (bindControls.Length > 0) { sys_Bind.Bind_Control = bindControls[0]; } //如果没找到则绑定数据列 //判断传入的如果是Name 自动转为 Id Sys_WorkSet twk = WorkSetList.Find(w => w.WorkSet_Id.Equals(sys_Bind.Bind_WorkSet)); if (twk != null && twk.WorkSet_Control != null && sys_Bind.Bind_Control == null) { GridView gv = (GridView)((GridControl)twk.WorkSet_Control).MainView; sys_Bind.Bind_Control = gv.Columns[sys_Bind.Bind_Field]; } } control = sys_Bind.Bind_Control; } //绑定控件之后 if (control != null) { object obj = null; //如果控件存在 且不是表格列 则用反射获取控件的值 if (control.GetType() != typeof(GridColumn)) { //如果指定了属性则直接从属性里取 if (!string.IsNullOrEmpty(sys_Bind.Bind_Property)) { obj = GetValue((Control)control, sys_Bind.Bind_Property); } //否则取默认的EditValue 若为空再取Text else { obj = GetValue((Control)control, "EditValue"); if (obj == null) { obj = GetValue((Control)control, "Text"); } } } //如果控件存在且是表格列 则取单元格中值 else { GridColumn bgc = (GridColumn)control; if (bgc.View.FocusedRowHandle >= 0 || bgc.View.IsNewItemRow(bgc.View.FocusedRowHandle)) { obj = bgc.View.GetFocusedRowCellValue(bgc); } } //obj从DBNull转为null if (obj == DBNull.Value || string.IsNullOrEmpty(obj.ToStringEx())) { obj = null; } val = obj; } return(val); }
private void InitializeQuery() { try { if (this.QueryControl == null) { return; } this.QueryControl.DoubleClick += QueryAutoClear; this.QueryControl.Controls.Clear(); this.Width = 1024; this.QueryControl.Width = 1024; LayoutControl eLayoutControl = new LayoutControl(); eLayoutControl.BeginUpdate(); eLayoutControl.AllowCustomization = false; LayoutControlGroup eLayoutControlGroup = new LayoutControlGroup(); eLayoutControl.Dock = System.Windows.Forms.DockStyle.Fill; eLayoutControl.Location = new System.Drawing.Point(2, 21); eLayoutControl.Name = "eLayoutControl"; eLayoutControl.Root = eLayoutControlGroup; eLayoutControl.Size = new System.Drawing.Size(1000, 90); eLayoutControl.TabIndex = 0; eLayoutControl.Text = "QueryLayout"; eLayoutControlGroup.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.True; eLayoutControlGroup.GroupBordersVisible = false; eLayoutControlGroup.Location = new Point(0, 0); eLayoutControlGroup.Name = "eLayoutControlGroup"; eLayoutControlGroup.Size = new Size(1000, 90); eLayoutControlGroup.TextVisible = false; this.QueryControl.Controls.Add(eLayoutControl); List <BaseLayoutItem> baseLayoutItems = new List <BaseLayoutItem>(); List <string> baseControls = new List <string>(); int curLeft = 0; int curTop = 0; foreach (Sys_Bind sys_Bind in BindList.Where(b => b.Bind_Name.StartsWith("@") && !string.IsNullOrEmpty(b.Bind_Field) && !b.Bind_Field.Contains(".") && WorkSetList.Find(w => w.WorkSet_Id == b.Bind_WorkSet && (w.WorkSet_Type == (int)Sys_WorkSet_Type.Submit || w.WorkSet_Type == (int)Sys_WorkSet_Type.Grid || w.WorkSet_Type == (int)Sys_WorkSet_Type.Tree)) != null).OrderBy(b => b.Bind_Sort)) { if (baseControls.Contains(sys_Bind.Bind_Field)) { continue; } baseControls.Add(sys_Bind.Bind_Field); sys_Bind.Bind_Type = 0; //查询字段 //界面已有控件不再生成 Control[] Controls = this.Controls.Find(sys_Bind.Bind_Field, true); if (Controls.Length > 0) { if (!string.IsNullOrEmpty(sys_Bind.Bind_Popup)) { BaseEdit cBaseEdit = (BaseEdit)Controls[0]; InitializeBaseEdit(sys_Bind, cBaseEdit); } continue; } BaseEdit baseEdit = InitializeBaseEdit(sys_Bind, null); baseEdit.Name = sys_Bind.Bind_Field; if (!string.IsNullOrEmpty(sys_Bind.Bind_Default)) { object obj = sys_Bind.Bind_Default; if (obj.ToString().StartsWith("wk:")) { obj = BaseService.Get(obj.ToString().Replace("wk:", ""), null); } ReflectionHelper.SetProperty(baseEdit, string.IsNullOrEmpty(sys_Bind.Bind_Property) ? "EditValue" : sys_Bind.Bind_Property, obj); //baseEdit.EditValue = sys_Bind.Bind_Default; if (baseEdit.GetType().Equals(typeof(CheckEdit))) { CheckEdit chkEdit = (CheckEdit)baseEdit; chkEdit.Text = string.Empty; chkEdit.Checked = obj.ToBoolEx(); } } if (baseEdit.GetType().Equals(typeof(CheckedComboBoxEdit))) { CheckedComboBoxEdit chkComboBox = (CheckedComboBoxEdit)baseEdit; chkComboBox.RefreshEditValue(); } baseEdit.EnterMoveNextControl = true; baseEdit.Width = (int)Math.Round(eLayoutControlGroup.Width * (sys_Bind.Bind_Width / 100.00)); baseEdit.Properties.Appearance.Options.UseTextOptions = true; baseEdit.Properties.Appearance.TextOptions.HAlignment = (DevExpress.Utils.HorzAlignment)sys_Bind.Bind_TextAlignment; if (sys_Bind.Bind_ForeColor < 0) { baseEdit.ForeColor = Color.FromArgb(sys_Bind.Bind_ForeColor); } if (sys_Bind.Bind_BackColor < 0) { baseEdit.BackColor = Color.FromArgb(sys_Bind.Bind_BackColor); } if (sys_Bind.Bind_BorderColor < 0) { baseEdit.Properties.Appearance.Options.UseBorderColor = true; baseEdit.Properties.Appearance.BorderColor = Color.FromArgb(sys_Bind.Bind_BorderColor); baseEdit.BorderStyle = BorderStyles.Simple; } baseEdit.ToolTip = sys_Bind.Bind_ToolTip; baseEdit.ReadOnly = sys_Bind.Bind_ReadOnly; baseEdit.Visible = sys_Bind.Bind_Visible; baseEdit.GotFocus += Control_GotFocus; eLayoutControl.GotFocus += Control_GotFocus; LayoutControlItem eLayoutControlItem = new LayoutControlItem(); eLayoutControlItem.Location = new System.Drawing.Point(curLeft, curTop); curLeft += baseEdit.Width; if (curLeft >= eLayoutControlGroup.Width) { curLeft = 0; curTop += baseEdit.Height; } //eLayoutControlItem.Width = (int)Math.Round(eLayoutControl.Width * (sys_Bind.Bind_Width / 100.00)); eLayoutControlItem.AppearanceItemCaption.TextOptions.HAlignment = (DevExpress.Utils.HorzAlignment)sys_Bind.Bind_TitleAlignment; eLayoutControlItem.Name = "oli_" + sys_Bind.Bind_Name; eLayoutControlItem.Text = sys_Bind.Bind_Nick; eLayoutControlItem.Size = new Size(baseEdit.Width, baseEdit.Height); eLayoutControlItem.Control = baseEdit; eLayoutControlItem.Visibility = sys_Bind.Bind_Visible ? DevExpress.XtraLayout.Utils.LayoutVisibility.Always : DevExpress.XtraLayout.Utils.LayoutVisibility.Never; baseLayoutItems.Add(eLayoutControlItem); } if (curLeft < eLayoutControlGroup.Width && curLeft > 0) { EmptySpaceItem emptySpaceItem = new EmptySpaceItem(); emptySpaceItem.AllowHotTrack = false; emptySpaceItem.Location = new System.Drawing.Point(curLeft, curTop); emptySpaceItem.Name = "oli_Space"; emptySpaceItem.Size = new System.Drawing.Size(eLayoutControlGroup.Width - curLeft, 24); baseLayoutItems.Add(emptySpaceItem); } eLayoutControlGroup.Items.AddRange(baseLayoutItems.ToArray()); eLayoutControl.EndUpdate(); } catch (Exception ex) { SharedFunc.RaiseError(ex); } }