Пример #1
0
 /// <summary>
 /// LookUp查询
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void LookUpSelfClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
 {
     try
     {
         string sql = "";
         //检测SQL设置
         if (SQL == null || SQL == "")
         {
             BWS.ERP.BaseControl.Public.SystemInfo("LookUp尚未设置SQL属性!", true);
             return;
         }
         if (IsSearchFormEdit)
         {
             if (EditFormName == null || EditFormName == "")
             {
                 BWS.ERP.BaseControl.Public.SystemInfo("LookUp尚未设置EditFormName属性!", true);
                 return;
             }
             if (EditFormID == 0)
             {
                 BWS.ERP.BaseControl.Public.SystemInfo("LookUp尚未设置EditFormID属性!", true);
                 return;
             }
         }
         if (LookUpBeforePost != null)
         {
             if (!LookUpBeforePost(sender, e))
             {
                 return;
             }
         }
         if (SearchFormFilter != "" && SearchFormFilter != null)
         {
             sql = "SELECT A.* FROM (" + SQL + ") A WHERE " + SearchFormFilter;
         }
         else
         {
             sql = SQL;
         }
         frmLookUpSearch frm = new frmLookUpSearch(sql, GridColumnText, GridDisplayField, SearchFormText, IsMultiSelect, IsSearchFormEdit, EditFormName, EditFormFilter, EditFormID);
         if (IsMultiSelect)
         {
             if (frm.ShowDialog() == DialogResult.OK)
             {
                 if (frm.ReturnData != null)
                 {
                     if (frm.ReturnData.Rows.Count > 0)
                     {
                         //选择的结果
                         _dt = frm.ReturnData;
                         if (LookUpAfterPost != null)
                         {
                             if (!LookUpAfterPost(sender, e))
                             {
                                 return;
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             if (frm.ShowDialog() == DialogResult.OK)
             {
                 if (frm.ReturnData != null)
                 {
                     if (frm.ReturnData.Rows.Count == 1)
                     {
                         //选择的结果
                         _dt = frm.ReturnData;
                         txtDisplayText.Focus();
                         txtValueText.Text = _dt.Rows[0][DataField].ToString();
                         //for (int i = 0; i < LAutoSetControl.ToArray().Length; i++)
                         //{
                         //    LAutoSetControl[i].Focus();
                         //    LAutoSetControl[i].Text = _dt.Rows[0][LAutoSetValueFields[i]].ToString();
                         //}
                         //for (int i = 0; i < LAutoSetFields.ToArray().Length; i++)
                         //{
                         //    gvTemp.Focus();
                         //    if (this.DataBindings[0].DataSource is System.Windows.Forms.BindingSource)
                         //    {
                         //        //先要设置控件绑定的值,在设置自动赋值的字段
                         //        ((System.Data.DataTable)(((System.Windows.Forms.BindingSource)(this.DataBindings[0].DataSource)).DataSource)).Rows[gvTemp.GetFocusedDataSourceRowIndex()][this.DataBindings[0].BindingMemberInfo.BindingField] = EditValue;
                         //        ((System.Data.DataTable)(((System.Windows.Forms.BindingSource)(this.DataBindings[0].DataSource)).DataSource)).Rows[gvTemp.GetFocusedDataSourceRowIndex()][LAutoSetFields[i]] = _dt.Rows[0][LAutoSetValueFields[i]];
                         //        //((System.Windows.Forms.BindingSource)(this.DataBindings[0].DataSource)).EndEdit();
                         //    }
                         //    else
                         //    {
                         //        ((DataSet)(this.DataBindings[0].DataSource)).Tables[0].Rows[gvTemp.GetFocusedDataSourceRowIndex()][this.DataBindings[0].BindingMemberInfo.BindingField] = EditValue;
                         //        ((DataSet)(this.DataBindings[0].DataSource)).Tables[0].Rows[gvTemp.GetFocusedDataSourceRowIndex()][LAutoSetFields[i]] = _dt.Rows[0][LAutoSetValueFields[i]];
                         //    }
                         //}
                         if (LookUpAfterPost != null)
                         {
                             if (!LookUpAfterPost(sender, e))
                             {
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }
Пример #2
0
        /// <summary>
        /// LookUp查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void LookUpSelfClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                string sql = "";
                //检测SQL设置
                if (SQL == null || SQL == "")
                {
                    BWS.ERP.BaseControl.Public.SystemInfo("LookUp尚未设置SQL属性!", true);
                    return;
                }
                if (IsSearchFormEdit)
                {
                    if (EditFormName == null || EditFormName == "")
                    {
                        BWS.ERP.BaseControl.Public.SystemInfo("LookUp尚未设置EditFormName属性!", true);
                        return;
                    }
                    if (EditFormID == 0)
                    {
                        BWS.ERP.BaseControl.Public.SystemInfo("LookUp尚未设置EditFormID属性!", true);
                        return;
                    }

                }
                if (LookUpBeforePost != null)
                {
                    if (!LookUpBeforePost(sender, e))
                    {
                        return;
                    }
                }
                if (SearchFormFilter != "" && SearchFormFilter != null)
                {
                    sql = "SELECT A.* FROM (" + SQL + ") A WHERE " + SearchFormFilter;
                }
                else
                {
                    sql = SQL;
                }
                frmLookUpSearch frm = new frmLookUpSearch(sql, GridColumnText, GridDisplayField, SearchFormText, IsMultiSelect, IsSearchFormEdit, EditFormName, EditFormFilter, EditFormID);
                if (IsMultiSelect)
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        if (frm.ReturnData != null)
                        {
                            if (frm.ReturnData.Rows.Count > 0)
                            {
                                //选择的结果
                                _dt = frm.ReturnData;
                                if (LookUpAfterPost != null)
                                {
                                    if (!LookUpAfterPost(sender, e))
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        if (frm.ReturnData != null)
                        {
                            if (frm.ReturnData.Rows.Count == 1)
                            {
                                //选择的结果
                                _dt = frm.ReturnData;
                                txtDisplayText.Focus();
                                txtValueText.Text = _dt.Rows[0][DataField].ToString();
                                //for (int i = 0; i < LAutoSetControl.ToArray().Length; i++)
                                //{
                                //    LAutoSetControl[i].Focus();
                                //    LAutoSetControl[i].Text = _dt.Rows[0][LAutoSetValueFields[i]].ToString();
                                //}
                                //for (int i = 0; i < LAutoSetFields.ToArray().Length; i++)
                                //{
                                //    gvTemp.Focus();
                                //    if (this.DataBindings[0].DataSource is System.Windows.Forms.BindingSource)
                                //    {
                                //        //先要设置控件绑定的值,在设置自动赋值的字段
                                //        ((System.Data.DataTable)(((System.Windows.Forms.BindingSource)(this.DataBindings[0].DataSource)).DataSource)).Rows[gvTemp.GetFocusedDataSourceRowIndex()][this.DataBindings[0].BindingMemberInfo.BindingField] = EditValue;
                                //        ((System.Data.DataTable)(((System.Windows.Forms.BindingSource)(this.DataBindings[0].DataSource)).DataSource)).Rows[gvTemp.GetFocusedDataSourceRowIndex()][LAutoSetFields[i]] = _dt.Rows[0][LAutoSetValueFields[i]];
                                //        //((System.Windows.Forms.BindingSource)(this.DataBindings[0].DataSource)).EndEdit();
                                //    }
                                //    else
                                //    {
                                //        ((DataSet)(this.DataBindings[0].DataSource)).Tables[0].Rows[gvTemp.GetFocusedDataSourceRowIndex()][this.DataBindings[0].BindingMemberInfo.BindingField] = EditValue;
                                //        ((DataSet)(this.DataBindings[0].DataSource)).Tables[0].Rows[gvTemp.GetFocusedDataSourceRowIndex()][LAutoSetFields[i]] = _dt.Rows[0][LAutoSetValueFields[i]];
                                //    }
                                //}
                                if (LookUpAfterPost != null)
                                {
                                    if (!LookUpAfterPost(sender, e))
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {

            }
        }