Beispiel #1
0
 protected override void BindDataControl(IDataControl control, object dataSource, string dataMember)
 {
     if (control is CheckBox)
     {
         ((CheckBox)control).DataBindings.Add("Checked", dataSource, control.LinkProperty);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 从数据集DataSet填充数据到数据控件上面,DataSet中的表名称必须和数据控件的LinkObject匹配(不区分大小写)
        /// </summary>
        /// <param name="Controls">要填充的窗体控件集和</param>
        /// <param name="dsSource">提供属于源的数据集</param>
        public void AutoSelectIBForm(ControlCollection Controls, DataSet dsSource)
        {
            List <IDataControl> IBControls = new List <IDataControl>();

            findIBControls(IBControls, Controls);

            foreach (DataTable dt in dsSource.Tables)
            {
                string tableName = dt.TableName;
                foreach (object obj in IBControls)
                {
                    IDataControl ibCtr = obj as  IDataControl;
                    if (string.Compare(ibCtr.LinkObject, tableName, true) == 0)
                    {
                        for (int i = 0; i < dt.Columns.Count; i++)
                        {
                            if (string.Compare(dt.Columns[i].ColumnName, ibCtr.LinkProperty, true) == 0)
                            {
                                ibCtr.SetValue(dt.Rows[0][i]);
                                break;
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public static void ReadOnlyControls(IDisplayManager dm, string[] controlsName, bool readOnly, Control parentControl, Dictionary <string, Label> labels)
        {
            if (labels == null)
            {
                labels = new Dictionary <string, Label>();
                SearchLabels(parentControl, labels);
            }
            foreach (string i in controlsName)
            {
                IDataControl dc = dm.DataControls[i];
                if (dc != null)
                {
                    dc.ReadOnly = readOnly;
                    if (readOnly)
                    {
                        dc.SelectedDataValue = null;
                    }
                }

                if (labels.ContainsKey(i))
                {
                    labels[i].ForeColor = readOnly ? System.Drawing.SystemColors.GrayText : System.Drawing.SystemColors.ControlText;
                }
                else
                {
                    throw new ArgumentException("There is no Label " + i);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cm"></param>
        /// <param name="infos"></param>
        protected void Initialize(IControlManager cm, IList <GridColumnInfo> infos)
        {
            m_cm = cm;
            if (infos != null)
            {
                foreach (GridColumnInfo info in infos)
                {
                    if (string.IsNullOrEmpty(info.DataControlType))
                    {
                        continue;
                    }

                    IDataControl dc = ControlFactory.GetDataControl(info, cm.DisplayManager.Name);
                    if (dc != null)
                    {
                        //m_dcc.Add(dc);
                        m_cm.DisplayManager.DataControls.Add(dc);

                        Control c = dc as Control;

                        this.flowLayoutPanel1.Controls.Add(c);
                    }
                }

                ArchiveDetailForm.SetDataControlDefaultValues(m_cm);
            }

            m_closeOk = false;
        }
        public void Process()
        {
            nextRecord();

            while (!ProcessReportPage())
            {
                nextPage();
            }
            for (int i = 0; i < Report.Pages.Count; i++)
            {
                foreach (var item in Report.Pages[i].Controls)
                {
                    if (item is IDataControl)
                    {
                        IDataControl dc = item as IDataControl;
                        if (dc.FieldName == "#NumberOfPages")
                        {
                            dc.Text = Report.Pages.Count.ToString();
                        }
                    }
                }
            }
            if (source != null)
            {
                source.Reset();
            }

            onAfterReportProcess();
        }
Beispiel #6
0
        public void FillData(object objData, ICollection controls, bool isEntityClass)
        {
            if (!isEntityClass)
            {
                return;
            }
            //处理实体对象
            Type   type = objData.GetType();
            Object obj  = type.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);

            foreach (object control in controls)
            {
                if (control is IDataControl)
                {
                    IDataControl brainControl = control as IDataControl;
                    if (brainControl.LinkObject == obj.GetType().Name)
                    {
                        object DataObj = type.InvokeMember(brainControl.LinkProperty, BindingFlags.GetProperty, null, objData, null);
                        if (DataObj == null && (brainControl.SysTypeCode == TypeCode.DateTime))
                        {
                            brainControl.SetValue(DBNull.Value);
                            continue;
                        }
                        brainControl.SetValue(DataObj);
                    }
                }
            }
        }
Beispiel #7
0
        private void ClearControl(Control c, object o)
        {
            IDataControl d = c as IDataControl;

            if (d != null && TableInfo.Columns[d.FieldName] != null)
            {
                d.Value = null;
            }
        }
        /// <summary>
        /// Adds control into form(input parameters - different references to one object)
        /// </summary>
        public void AddControl(IDataControl control)
        {
            //if (!IsPostBack)
            //{

                form1.Controls.Add((Control)control);
                ControlsCollection.Add(control);
            //}
        }
Beispiel #9
0
        void dc_ReadOnlyChanged(object sender, EventArgs e)
        {
            IDataControl dc = sender as IDataControl;

            if (dc.ReadOnly)
            {
                m_cm.ControlCheckExceptionProcess.ShowError(dc, null);
            }
        }
Beispiel #10
0
        private void FillControl(Control c, object o)
        {
            IDataControl d = c as IDataControl;

            if (d != null && TableInfo.Columns[d.FieldName] != null)
            {
                d.Value = dataRecord[d.FieldName];
            }
        }
Beispiel #11
0
        private void SaveControl(Control c, object o)
        {
            IDataControl d = c as IDataControl;

            if (d != null && TableInfo.Columns[d.FieldName] != null && !TableInfo.Columns[d.FieldName].IsIdentity)
            {
                dataRecord[d.FieldName] = d.Value;
            }
            //Unicorn.Web.WebUtility.ShowMessageBox("اطلاعات با موفقيت ذخيره شد", Page);
        }
 /// <summary>
 /// ���ؼ�ֵ�Ƿ���ϱ�׼
 /// </summary>
 /// <returns></returns>
 /// <exception cref="ControlCheckException">�ؼ�ֵ�����ϱ�׼</exception>
 public override bool CheckControlValue(IDataControl dc)
 {
     if (m_helper != null)
     {
         return ControlManager.CheckControlValue(this, m_helper, dc);
     }
     else
     {
         return base.CheckControlValue(dc);
     }
 }
 /// <summary>
 /// 检查控件值是否符合标准
 /// </summary>
 /// <returns></returns>
 /// <exception cref="ControlCheckException">控件值不符合标准</exception>
 public override bool CheckControlValue(IDataControl dc)
 {
     if (m_helper != null)
     {
         return(CheckControlValue(this, m_helper, dc));
     }
     else
     {
         return(base.CheckControlValue(dc));
     }
 }
Beispiel #14
0
        public static void 车辆_车主驾驶员_对应(object sender, SelectedDataValueChangedEventArgs e)
        {
            if (e.DataControlName == "车辆编号")
            {
                IDisplayManager dm = sender as IDisplayManager;

                IDataControl dc = e.Container as IDataControl;
                if (dc != null)
                {
                    if (dc.SelectedDataValue != null)
                    {
                        车辆 cl = EntityBufferCollection.Instance.Get <车辆>(dc.SelectedDataValue);
                        if (cl != null)
                        {
                            if (dm.DataControls["车主编号"] != null && dm.DataControls["车主编号"].SelectedDataValue == null)
                            {
                                dm.DataControls["车主编号"].SelectedDataValue = cl.车主编号;
                            }
                            if (dm.DataControls["承运人编号"] != null && dm.DataControls["承运人编号"].SelectedDataValue == null)
                            {
                                dm.DataControls["承运人编号"].SelectedDataValue = cl.车主编号;
                            }
                            if (dm.DataControls["驾驶员编号"] != null && dm.DataControls["驾驶员编号"].SelectedDataValue == null)
                            {
                                dm.DataControls["驾驶员编号"].SelectedDataValue = cl.默认驾驶员编号;
                            }
                        }
                    }
                }
                else
                {
                    Xceed.Grid.Cell cell = e.Container as Xceed.Grid.Cell;
                    if (cell.Value != null)
                    {
                        车辆 cl = EntityBufferCollection.Instance.Get <车辆>(cell.Value);
                        if (cl != null)
                        {
                            if (cell.ParentRow.Cells["车主编号"] != null && cell.ParentRow.Cells["车主编号"].Value == null)
                            {
                                cell.ParentRow.Cells["车主编号"].Value = cl.车主编号;
                            }
                            if (cell.ParentRow.Cells["承运人编号"] != null && cell.ParentRow.Cells["承运人编号"].Value == null)
                            {
                                cell.ParentRow.Cells["承运人编号"].Value = cl.车主编号;
                            }
                            if (cell.ParentRow.Cells["驾驶员编号"] != null && cell.ParentRow.Cells["驾驶员编号"].Value == null)
                            {
                                cell.ParentRow.Cells["驾驶员编号"].Value = cl.默认驾驶员编号;
                            }
                        }
                    }
                }
            }
        }
Beispiel #15
0
        //void dc_SelectedDataValueChanged(object sender, EventArgs e)
        //{
        //    IDataControl dc = sender as IDataControl;
        //    m_cm.CheckControlValue(dc);
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="dataControlName"></param>
        public void RemoveValidation(string dataControlName)
        {
            IDataControl dc = m_cm.DisplayManager.DataControls[dataControlName];

            Control vc = GetControl(dc);

            if (vc != null)
            {
                this.validationProvider1.SetValidationExpression(vc, null);
                this.validationProvider1.SetValidationError(vc, string.Empty);
            }
        }
 internal static void GetSubControls(Dictionary <string, IDataControl> dict, Control parent)
 {
     foreach (Control child in parent.Controls)
     {
         IDataControl dc = child as IDataControl;
         if (dc != null)
         {
             dict[dc.Name] = dc;
         }
         GetSubControls(dict, child);
     }
 }
Beispiel #17
0
        private static IDataControl GetDataControl(IDisplayManager dm, string gridName, string gridColumnName, bool includeLabel = false)
        {
            if (gridName == null)
            {
                throw new ArgumentNullException("gridName");
            }

            IList <GridColumnInfo> infos = ADInfoBll.Instance.GetGridColumnInfos(gridName);
            string infoName = gridName + "_" + gridColumnName;

            foreach (GridColumnInfo info in infos)
            {
                if (info.GridColumnName == gridColumnName ||
                    info.Name == infoName)
                {
                    IDataControl dc = null;
                    if (dm != null)
                    {
                        if (includeLabel)
                        {
                            dc = ControlFactory.GetDataControl(info, dm.Name);
                        }
                        else
                        {
                            dc = ControlFactory.GetDataControlWrapper(info, dm.Name);
                        }
                        dm.DataControls.Add(dc);
                    }
                    else
                    {
                        if (includeLabel)
                        {
                            dc = ControlFactory.GetDataControl(info, info.GridName);
                        }
                        else
                        {
                            dc = ControlFactory.GetDataControlWrapper(info, info.GridName);
                        }
                    }

                    dc.ReadOnly = true;

                    //dc.AvailableChanged += new EventHandler((sender, e) =>
                    //    {
                    //        IDataControl dcc = sender as IDataControl;
                    //        (dcc as Control).Visible = dcc.Available;
                    //    });
                    return(dc);
                }
            }
            return(null);
        }
Beispiel #18
0
        private void InputBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (InputBoxKeyPress != null)
            {
                InputBoxKeyPress(sender, e);
            }
            else
            {
                if (e.KeyChar == (char)System.Windows.Forms.Keys.Enter)
                {
                    Control c = sender as Control;
                    if (c == null)
                    {
                        return;
                    }

                    IDataControl control = c.Parent as IDataControl;

                    int now = base.Count - 1;
                    for (int i = 0; i < base.Count; ++i)
                    {
                        if (control == base[i] as IDataControl)
                        {
                            now = i;
                            break;
                        }
                    }

                    do
                    {
                        now++;
                        if (now == base.Count)
                        {
                            System.Windows.Forms.SendKeys.Send("{TAB}");
                            break;
                        }

                        c = base[now] as System.Windows.Forms.Control;

                        if (c != null && c.TabStop)
                        {
                            c.Focus();
                        }
                    } while (c == null || !c.ContainsFocus || base[now].ReadOnly);

                    //control.FindForm().SelectNextControl(control, true, true, true, true);

                    e.Handled = true;
                }
            }
        }
        internal void CreateDataControls()
        {
            InternalCreateDataControls(base.DisplayManager, base.ControlManager, this.GridName, this, this.toolTip1);

            var dm = this.DisplayManager;

            m_dataControlsBuffer = new IDataControl[dm.DataControls.Count];
            dm.DataControls.CopyTo(m_dataControlsBuffer, 0);

            if (DataControlsCreated != null)
            {
                DataControlsCreated(this, System.EventArgs.Empty);
            }
        }
Beispiel #20
0
        private LabeledDataControl AddDataControl(IDesignerHost h, GridColumnInfo info)
        {
            //IDataControl dc = ControlFactory.GetDataControl(columnInfo);
            //Control control = dc as Control;
            //if (control == null)
            //{
            //    throw new ArgumentException("IDataControl should be System.Windows.Forms.Control!");
            //}
            //m_parentForm.Controls.Add(control);

            Control ic = null;

            foreach (string s in ControlsName.DataControlsTypeName)
            {
                if (s.LastIndexOf(info.DataControlType, StringComparison.OrdinalIgnoreCase) != -1)
                {
                    ic = (Control)h.CreateComponent(Feng.Utils.ReflectionHelper.GetTypeFromName(s));
                    break;
                }
            }

            if (ic == null)
            {
                throw new InvalidOperationException("Invalid ControlType of " + info.DataControlType);
            }
            LabeledDataControl control = (LabeledDataControl)h.CreateComponent(typeof(LabeledDataControl));

            MyLabel lbl = (MyLabel)h.CreateComponent(typeof(MyLabel));

            lbl.Text = info.Caption;

            control.Controls.Add(lbl);
            control.Controls.Add(ic);
            control.Label   = lbl;
            control.Control = ic;

            IDataControl dc = control as IDataControl;

            dc.Caption      = info.Caption;
            dc.PropertyName = info.PropertyName;
            dc.Navigator    = info.Navigator;
            //dc.Index = info.SeqNo;
            dc.Name = info.GridColumnName;

            control.ResetLayout();

            m_parentForm.Controls.Add(control);

            return(control);
        }
Beispiel #21
0
 protected void AutoSelectIBFormInner(List <IDataControl> IBControls, IEntity entity)
 {
     foreach (object obj in IBControls)
     {
         IDataControl ibCtr = obj as IDataControl;
         foreach (string key in entity.PropertyNames)
         {
             if (string.Compare(key, ibCtr.LinkProperty, true) == 0)
             {
                 ibCtr.SetValue(entity.PropertyList(key));
                 break;
             }
         }
     }
 }
Beispiel #22
0
        internal static Tuple <string, object> GetDataCellValue(string s2, Xceed.Grid.Cell cell)
        {
            string s1 = s2;
            // maybe there is '.'
            int    idx = s1.IndexOf('_');
            string dataControlName, propertyName;

            if (idx == -1)
            {
                dataControlName = s1;
                propertyName    = null;
            }
            else
            {
                dataControlName = s1.Substring(0, idx);
                propertyName    = s1.Substring(idx + 1);
            }

            object o = null;

            if (cell.ParentRow.Cells[dataControlName] != null)
            {
                o = cell.ParentRow.Cells[dataControlName].Value;
            }
            else
            {
                // 如果未找到Cell,则找父级DataControl
                IDisplayManagerContainer form = cell.GridControl.FindForm() as IDisplayManagerContainer;
                if (form != null)
                {
                    IDataControl parentDc = form.DisplayManager.DataControls[dataControlName];
                    o = parentDc.SelectedDataValue;
                }
            }

            if (!string.IsNullOrEmpty(propertyName))
            {
                propertyName = propertyName.Replace('_', '.');
                o            = EntityScript.GetPropertyValue(o, propertyName);
            }

            //if (o == null)
            //{
            //    throw new ArgumentException("there is no column or datacontrol with name " + s1 + "!");
            //}

            return(new Tuple <string, object>(dataControlName, o));
        }
Beispiel #23
0
 public void FillData(DataTable dtTmp, ICollection controls)
 {
     //处理DataTable
     foreach (object control in controls)
     {
         if (control is IDataControl)
         {
             IDataControl brainControl = control as IDataControl;
             if (dtTmp.TableName == brainControl.LinkObject &&
                 dtTmp.Columns.Contains(brainControl.LinkProperty))
             {
                 brainControl.SetValue(dtTmp.Rows[0][brainControl.LinkProperty]);
             }
         }
     }
 }
Beispiel #24
0
        public void CollectData(object objData, ICollection controls, bool isEntityClass)
        {
            if (!isEntityClass)
            {
                return;
            }
            //处理实体对象
            Type   type = objData.GetType();
            object obj  = type.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);

            foreach (object control in controls)
            {
                if (control is IDataControl)
                {
                    //情况单独处理
                    IDataControl brainControl = control as IDataControl;
                    if (brainControl.IsValid)
                    {
                        //string cao = obj.GetType().Name;
                        if (brainControl.LinkObject == obj.GetType().Name&& brainControl.LinkProperty != "")
                        {
                            object oValue = brainControl.GetValue();
                            //add 2008.7.22
                            if (brainControl.SysTypeCode != TypeCode.String && (oValue == null || oValue.ToString() == ""))
                            {
                                continue;
                            }

                            //EditFlag 邓太华 2006.9.17 处理 System.DBNull.Value 情况
                            if (oValue == System.DBNull.Value)
                            {
                                type.InvokeMember(brainControl.LinkProperty, BindingFlags.SetProperty, Type.DefaultBinder, objData, new object[] { null });
                                continue;
                            }

                            type.InvokeMember(brainControl.LinkProperty, BindingFlags.SetProperty, Type.DefaultBinder, objData, new object[] { Convert.ChangeType(oValue, brainControl.SysTypeCode) });
                        }
                    }
                    else
                    {
                        throw new Exception("绑定到属性字段[" + brainControl.LinkProperty + "]前未通过服务器验证!");
                    }
                }
            }
        }
Beispiel #25
0
        internal string ValidateControl(string dataControlName)
        {
            IDataControl dc = m_cm.DisplayManager.DataControls[dataControlName];
            Control      vc = GetControl(dc);

            if (vc != null)
            {
                bool b = this.validationProvider1.Validate(vc, false, false);
                if (!b)
                {
                    string error = this.validationProvider1.GetValidationError(vc);
                    this.validationProvider1.SetValidationError(vc, string.Empty);
                    return(error);
                }
            }

            return(null);
        }
Beispiel #26
0
        /// <summary>
        /// 从实体类填充数据到页面控件
        /// </summary>
        /// <param name="Controls"></param>
        /// <param name="entity"></param>
        public void AutoSelectIBForm(ControlCollection Controls, IEntity entity)
        {
            List <IDataControl> IBControls = new List <IDataControl>();

            findIBControls(IBControls, Controls);

            foreach (object obj in IBControls)
            {
                IDataControl ibCtr = obj as  IDataControl;
                foreach (string key in entity.PropertyNames)
                {
                    if (string.Compare(key, ibCtr.LinkProperty, true) == 0)
                    {
                        ibCtr.SetValue(entity.PropertyList(key));
                        break;
                    }
                }
            }
        }
Beispiel #27
0
        private Control GetControl(IDataControl dc)
        {
            Control        vc  = null;
            IWindowControl ldc = dc as IWindowControl;

            if (ldc != null)
            {
                vc = ldc.Control;
            }
            else
            {
                Control c = dc as Control;
                if (c != null)
                {
                    vc = c;
                }
            }
            return(vc);
        }
        /// <summary>
        /// 将对象数据填充到数据控件上,要求falg=true,否则请使用另外的2个重载
        /// </summary>
        /// <param name="objData">数据对象,可以是实体类</param>
        /// <param name="controls">数据控件</param>
        /// <param name="flag">标记</param>
        public void FillData(object objData, ICollection controls, bool flag)
        {
            if (!flag)
            {
                return;
            }
            //处理实体对象
            Type       type   = objData.GetType();
            EntityBase entity = objData as EntityBase;

            //Object obj = type.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);
            string typeName = type.Name;

            foreach (object control in controls)
            {
                if (control is IDataControl)
                {
                    IDataControl brainControl = control as IDataControl;
                    if (brainControl.LinkObject == typeName && !string.IsNullOrEmpty(brainControl.LinkProperty))  // obj.GetType().Name
                    {
                        if (entity != null)
                        {
                            object oValue = entity[brainControl.LinkProperty];
                            if (oValue != null || brainControl.SysTypeCode == TypeCode.String)
                            {
                                brainControl.SetValue(oValue);
                                continue;
                            }
                        }
                        //不是PDF.NET实体类的实体属性,采用反射获得值
                        object DataObj = type.InvokeMember(brainControl.LinkProperty, BindingFlags.GetProperty, null, objData, null);
                        if (DataObj == null && (brainControl.SysTypeCode == TypeCode.DateTime))
                        {
                            brainControl.SetValue(DBNull.Value);
                            continue;
                        }
                        brainControl.SetValue(DataObj);
                    }
                }
            }
        }
Beispiel #29
0
        protected bool AutoUpdateIBFormDataInner(List <IBCommand> ibCommandList, IDataControl guidControl)
        {
            object guidObj = guidControl.GetValue();

            if (guidObj == null || guidObj.ToString() == "")
            {
                throw new Exception("GUID 主键或字符型主键列更新数据不能为空!");
            }
            if (guidControl.ReadOnly)
            {
                throw new Exception("GUID 主键或字符型主键列更新数据时不能设置为只读!");
            }
            if (!guidControl.PrimaryKey)
            {
                throw new Exception("GUID 主键或字符型主键列更新数据时必须设置PrimaryKey属性!");
            }

            string guidText = guidObj.ToString();

            int result = 0;

            foreach (IBCommand command in ibCommandList)
            {
                if (command.TableName == guidControl.LinkObject)
                {
                    string sql      = "SELECT [" + guidControl.LinkProperty + "] FROM [" + guidControl.LinkObject + "] WHERE [" + guidControl.LinkProperty + "] = '" + guidText + "'";
                    object guidInDb = DAO.ExecuteScalar(sql);
                    if (guidInDb != null && guidInDb.ToString() == guidText)
                    {
                        //在数据库中有该记录
                        result = DAO.ExecuteNonQuery(command.UpdateCommand, CommandType.Text, command.Parameters);
                    }
                    else
                    {
                        result = DAO.ExecuteNonQuery(command.InsertCommand, CommandType.Text, command.Parameters);
                    }
                    return(result > 0);
                }
            }
            return(false);
        }
Beispiel #30
0
        private void ShowDrowDown(PropertyInfo value)
        {
            try
            {
                if (this.wSrv == null)
                {
                    this.wSrv = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                }

                IDataControl dataControl = this.context.Instance as IDataControl;
                if (dataControl.DBContext == null)
                {
                    throw new Exception("Please select DBContext first!");
                }

                if (list == null)
                {
                    list           = new ListBox();
                    list.Height    = 300;
                    list.Width     = 200;
                    list.Click    += new EventHandler(list_Click);
                    list.GotFocus += List_GotFocus;
                }

                list.BorderStyle = System.Windows.Forms.BorderStyle.None;

                var properties = ((Type)dataControl.DBContext.Value).GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(m => m.Name).Where(m => m.PropertyType.IsGenericType || m.PropertyType.IsArray || m.PropertyType.HasElementType).ToArray();

                list.DisplayMember = "Name";
                list.DataSource    = properties;

                _tosetValue = (value == null ? null : properties.FirstOrDefault(m => m.Name == value.Name));
                //if (value != null)
                //    list.SelectedItem = properties.FirstOrDefault(m => m.Name == value.Name);
                wSrv.DropDownControl(list);
            }
            catch (Exception ex2)
            {
                throw (ex2);
            }
        }
Beispiel #31
0
        void 任务预备案_SelectedDataValueChanged(object sender, EventArgs e)
        {
            IDataControl dc = sender as IDataControl;

            if (dc.Name == "装货地编号")
            {
                if (m_cm.DisplayManager.DataControls["装货地详细地址"].SelectedDataValue == null)
                {
                    m_cm.DisplayManager.DataControls["装货地详细地址"].SelectedDataValue =
                        Feng.NameValueMappingCollection.Instance.FindColumn2FromColumn1("人员单位_装卸货地", "编号", "全称", dc.SelectedDataValue);
                }
            }
            else if (dc.Name == "卸货地编号")
            {
                if (m_cm.DisplayManager.DataControls["卸货地详细地址"].SelectedDataValue == null)
                {
                    m_cm.DisplayManager.DataControls["卸货地详细地址"].SelectedDataValue =
                        Feng.NameValueMappingCollection.Instance.FindColumn2FromColumn1("人员单位_装卸货地", "编号", "全称", dc.SelectedDataValue);
                }
            }
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorService = null;

            if (context != null && context.Instance != null && provider != null)
            {
                editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (editorService != null)
                {
                    IDataControl         control = (IDataControl)context.Instance;
                    PropertySelectorForm dlg     = new PropertySelectorForm(control);
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        value = dlg.PropertyName;
                        return(value);
                    }
                }
            }

            return(value);
        }
Beispiel #33
0
        /// <summary>
        /// 自动更新含有GUID主键的窗体数据,注该GUID控件必须设置PrimaryKey属性
        /// </summary>
        /// <param name="Controls">控件集合</param>
        /// <param name="guidControl">Gudi控件</param>
        /// <returns>更新是否成功</returns>
        public bool  AutoUpdateIBFormData(ControlCollection Controls,  IDataControl guidControl)
        {
            object  guidObj=guidControl.GetValue();
            if (guidObj == null || guidObj.ToString() == "")
                throw new Exception("GUID 主键列更新数据不能为空!");
            if (guidControl.ReadOnly  )
                throw new Exception("GUID 主键列更新数据时不能设置为只读!");
            if (!guidControl.PrimaryKey )
                throw new Exception("GUID 主键列更新数据时必须设置PrimaryKey属性!");

            string guidText = guidObj.ToString();
            List<IBCommand> ibCommandList = GetIBFormData(Controls);
            int result = 0;
            foreach (IBCommand command in ibCommandList)
            {
                if (command.TableName == guidControl.LinkObject)
                {
                    string sql = "select " + guidControl.LinkProperty + " from " + guidControl.LinkObject + " where " + guidControl.LinkProperty + "='" + guidText + "'";
                    object guidInDb = DAO.ExecuteScalar(sql);
                    if (guidInDb != null && guidInDb.ToString() == guidText)
                    {
                        //在数据库中有该记录
                        result = DAO.ExecuteNonQuery(command.UpdateCommand);
                    }
                    else
                    {
                        result = DAO.ExecuteNonQuery(command.InsertCommand );
                    }
                    return result>0 ;
                }

            }
            return false;
        }
 private Control GetControl(IDataControl dc)
 {
     Control vc = null;
     IWindowControl ldc = dc as IWindowControl;
     if (ldc != null)
     {
         vc = ldc.Control;
     }
     else
     {
         Control c = dc as Control;
         if (c != null)
         {
             vc = c;
         }
     }
     return vc;
 }
        internal static bool CheckControlValue(IControlManager cm, ValidationHelper helper, IDataControl dc)
        {
            bool ret = true;
            if (!dc.ReadOnly)
            {
                string errMsg = helper.ValidateControl(dc.Name);
                cm.ControlCheckExceptionProcess.ShowError(dc, errMsg);

                if (!string.IsNullOrEmpty(errMsg))
                {
                    ret = false;
                }
            }
            return ret;
        }
 /// <summary>
 /// Adds control into form(input parameters - different references to one object)
 /// </summary>
 public void AddControl(IDataControl dataControl)
 {
     var controlReference = (Control)dataControl;
     UserControls.Add(controlReference);
     DataControls.Add(dataControl);
     controlReference.Validating += ControlValidating;
 }
 private void ControlValidate(IDataControl control)
 {
     try
     {
         control.ValidateItem();
         errorProvider.SetError((Control)control, string.Empty);
     }
     catch (ValidationException exception)
     {
         errorProvider.SetError((Control)control, exception.Message);
     }
 }
 /// <summary>
 /// ����ȽϿؼ�
 /// </summary>
 /// <param name="dc"></param>
 /// <param name="notNull"></param>
 /// <param name="op"></param>
 protected void AddDataControl(IDataControl dc, bool notNull, Operators op)
 {
     //m_dataControlGroup.Add(dc);
     m_ht.Add(dc, op);
     dc.NotNull = notNull;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <returns></returns>
        public virtual bool CheckControlValue(IDataControl dc)
        {
            var cm = this;

            bool ret = true;
            if (!dc.ReadOnly)
            {
                try
                {
                    string errMsg = null;
                    if (dc.NotNull && dc.SelectedDataValue == null)
                    {
                        errMsg = "请输入" + dc.Caption + "!";
                        ret = false;
                    }
                    cm.ControlCheckExceptionProcess.ShowError(dc, errMsg);
                }
                catch (ControlCheckException ex)
                {

                    cm.ControlCheckExceptionProcess.ShowError(ex.InvalidDataControl, ex.Message);
                }
            }
            return ret;
        }
        private static void ReloadNvFromDataControl(EventProcessInfo eventProcessInfo, IDisplayManager dm, IDataControl dc, string changedDataControlName)
        {
            string[] columns = eventProcessInfo.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string s in columns)
            {
                IDataControl idc = dm.DataControls[s];
                if (idc == null)
                {
                    throw new ArgumentException("there is no IDataControl with name " + s + " in eventProcess's SelectedDataValueChanged!");
                }

                //object saveValue = idc.SelectedDataValue;
                GridColumnInfo iInfo = idc.Tag as GridColumnInfo;

                switch (iInfo.CellEditorManager)
                {
                    case "Combo":
                    case "MultiCombo":
                    case "FreeCombo":
                        {
                            // NameValueMapping
                            NameValueMapping nv = NameValueMappingCollection.Instance[iInfo.CellEditorManagerParam];

                            // will throw 集合已改变Exception
                            List<string> ls = new List<string>();
                            foreach (KeyValuePair<string, object> kvp in nv.Params)
                            {
                                ls.Add(kvp.Key.Substring(1));
                            }
                            if (!ls.Contains(changedDataControlName))
                                continue;

                            object savedValue = idc.SelectedDataValue;
                            idc.SelectedDataValue = null;
                            foreach (string key in ls)
                            {
                                object o = GetDataControlValue(key, dm).Item2;

                                nv.Params["@" + key] = o == null ? System.DBNull.Value : o;
                            }
                            NameValueMappingCollection.Instance.Reload(dm.Name, iInfo.CellEditorManagerParam);
                            nv.ResetParams();

                            idc.SelectedDataValue = savedValue;
                        }
                        break;
                    case "ObjectPicker":
                        {
                            object savedValue = idc.SelectedDataValue;
                            idc.SelectedDataValue = null;

                            Feng.Windows.Forms.MyObjectPicker op = (idc as Feng.Windows.Forms.IWindowControl).Control as Feng.Windows.Forms.MyObjectPicker;
                            string exp = (string)ParamCreatorHelper.TryGetParam(iInfo.CellEditorManagerParamFilter);
                            exp = EntityHelper.ReplaceEntity(exp, new EntityHelper.GetReplaceValue(delegate(string paramName)
                            {
                                return GetDataControlValue(paramName, dm).Item2;
                            }));
                            op.DropDownControl.DisplayManager.SearchManager.LoadData(SearchExpression.Parse(exp), null);

                            idc.SelectedDataValue = savedValue;
                        }
                        break;
                    default:
                        throw new ArgumentException("EventProcess's SelectedDataValueChanged CellEditorManagerType is not support!");
                }

                //idc.SelectedDataValue = saveValue;
            }
        }
        /// <summary>
        /// ����ؼ���
        /// ����Enter�¼���������ʵ������Ϣ�����ı�����󳤶�
        /// </summary>
        /// <param name="item"></param>
        public override void Add(IDataControl item)
        {
            if (this.Contains(item))
                return;

            base.Add(item);

            IWindowControl windowControl = item as IWindowControl;

            if (windowControl != null && windowControl.Control != null)
            {
                // ȷ��Index
                if (m_bKeyPressEvent)
                {
                    windowControl.Control.KeyPress += new System.Windows.Forms.KeyPressEventHandler(InputBox_KeyPress);
                    //if (item.Index != -1)
                    //{
                    //    windowControl.Control.TabIndex = item.Index;
                    //}
                }
            }

            //// δָ��Index������1
            //if (item.Index == -1 || m_items.ContainsKey(item.Control.TabIndex)))
            //{
            //    if (dc.Control != null && dc.Control.TabStop && !m_items.ContainsKey(dc.Control.TabIndex))
            //    {
            //        dc.Index = dc.Control.TabIndex;
            //    }
            //    else
            //    {
            //        int delta = 1;
            //        if (dc.Control == null)
            //        {
            //            delta = 100;
            //        }

            //        if (m_items.Count > 0)
            //        {
            //            dc.Index = m_items.Values[m_items.Count - 1].Index + delta;
            //        }
            //        else
            //        {
            //            dc.Index = 0 + delta;
            //        }
            //    }
            //}

            // ����Entity����
            if (base.ParentManager != null && base.ParentManager.EntityInfo != null)
            {
                if (!string.IsNullOrEmpty(item.Name)
                    && base.ParentManager.EntityInfo.IdName != item.Name)
                {
                    if (string.IsNullOrEmpty(item.Navigator) && !string.IsNullOrEmpty(item.PropertyName))
                    {
                        var attr = base.ParentManager.EntityInfo.GetPropertMetadata(item.PropertyName);
                        if (attr != null)
                        {
                            TextBox txt = windowControl.Control as TextBox;
                            if (txt != null)
                            {
                                if (attr.Length != -1)
                                {
                                    txt.MaxLength = attr.Length;
                                }
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// ����ȽϿؼ�(�Ƚ�Ĭ��Ϊ���)
 /// </summary>
 /// <param name="dc"></param>
 /// <param name="allowNull"></param>
 protected void AddDataControl(IDataControl dc, bool allowNull)
 {
     AddDataControl(dc, allowNull, Operators.Equal);
 }