예제 #1
0
        /// <summary>
        /// 模糊查找需要的记录,并把“客户名称”赋值给相应控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void CustName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Control control     = sender as Control;
                string  controlText = control.Text.Trim();
                if (controlText == "")
                {
                    return;
                }

                string strSql = "select CustID as 客户编码,CustName as 客户名称,PinYinCode as 助记符,communicateAddr as 通信地址, Degree as 客户等级 " +
                                "from T_CustomerInf where CustID like '%{0}%' or CustName like '%{0}%' or PinYinCode like '%{0}%'";
                strSql = string.Format(strSql, controlText);

                DataTable dt = (new SqlDBConnect()).Get_Dt(strSql);
                if (dt == null || dt.Rows.Count <= 0)
                {
                    MessageBox.Show("查找的信息不存在,请重新输入!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    control.Text = "";
                    return;
                }
                if (dt.Rows.Count == 1) //只查找到1条匹配记录,直接赋值
                {
                    control.Text = dt.Rows[0]["客户名称"].ToString().Trim();
                }
                else
                {
                    FilterInfoForm form = new FilterInfoForm(control, dt, "客户名称");
                    form.StartPosition = FormStartPosition.CenterScreen;
                    form.ShowDialog();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 模糊查找需要的记录,并把“用户编码”赋值给相应控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void UserId_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Control control     = sender as Control;
                string  controlText = control.Text.Trim();
                if (controlText == "")
                {
                    return;
                }

                string strSql = "select UserId as 用户编码,UserName as 用户名,UserNameZJM as 用户名助记码,OfficeTel as 办公电话, MobileTel as 移动电话 " +
                                "from T_Users where UserId like '%{0}%' or UserName like '%{0}%' or UserNameZJM like '%{0}%'";
                strSql = string.Format(strSql, controlText);

                DataTable dt = (new SqlDBConnect()).Get_Dt(strSql);
                if (dt == null || dt.Rows.Count <= 0)
                {
                    MessageBox.Show("查找的信息不存在,请重新输入!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    control.Text = "";
                    return;
                }
                if (dt.Rows.Count == 1) //只查找到1条匹配记录,直接赋值
                {
                    control.Text = dt.Rows[0]["用户编码"].ToString().Trim();
                }
                else
                {
                    FilterInfoForm form = new FilterInfoForm(control, dt, "用户编码");
                    form.StartPosition = FormStartPosition.CenterScreen;
                    form.ShowDialog();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 模糊查找需要的记录,并把“商品名称”赋值给相应控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void MatName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Control control     = sender as Control;
                string  controlText = control.Text.Trim();
                if (controlText == "")
                {
                    return;
                }

                string strSql = "select MatID 商品编号,MatName 商品名称,Specifications 型号规格,Units 计量单位 " +
                                "from T_MatInf where MatID like '%{0}%' or MatName like '%{0}%'";
                strSql = string.Format(strSql, controlText);

                DataTable dt = (new SqlDBConnect()).Get_Dt(strSql);
                if (dt == null || dt.Rows.Count <= 0)
                {
                    MessageBox.Show("查找的信息不存在,请重新输入!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    control.Text = "";
                    return;
                }
                if (dt.Rows.Count == 1) //只查找到1条匹配记录,直接赋值
                {
                    control.Text = dt.Rows[0]["商品名称"].ToString().Trim();
                }
                else
                {
                    FilterInfoForm form = new FilterInfoForm(control, dt, "商品名称");
                    form.StartPosition = FormStartPosition.CenterScreen;
                    form.ShowDialog();
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 模糊查找到需要的记录,并赋值给显示控件
        /// </summary>
        /// <param name="control">传入的显示信息的控件</param>
        /// <param name="tableName">表名</param>
        /// <param name="fieldName">希望得到值的字段</param>
        /// <param name="findFields">希望在哪些字段中模糊查找</param>
        /// <param name="displayFields">在显示界面中现实的字段</param>
        public static void FindInfoToControl(Control control, string tableName, string fieldName, Dictionary <string, string> findFields, Dictionary <string, string> displayFields)
        {
            string controlText = control.Text.ToString().Trim();

            if (controlText == "" || displayFields.Count <= 0)
            {
                return;
            }

            string strSql = "select ";

            foreach (string field in displayFields.Keys)
            {
                strSql += field.Trim() + " as " + displayFields[field].Trim() + ",";
            }

            strSql  = strSql.Remove(strSql.Length - 1); //删除最后一个逗号
            strSql += " from " + tableName + " where ";

            foreach (string field in findFields.Keys)
            {
                if (findFields[field].Trim() == "s")
                {
                    strSql += field + " like '%" + controlText + "%' or ";
                }
                else if (findFields[field].Trim() == "n")
                {
                    strSql += field + " like %" + controlText + "% or ";
                }
            }
            strSql = strSql.Remove(strSql.Length - 3);

            DataTable dt = (new SqlDBConnect()).Get_Dt(strSql);

            if (dt == null || dt.Rows.Count <= 0)
            {
                MessageBox.Show("查找的信息不存在,请重新输入!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                control.Text = "";
                return;
            }
            if (dt.Rows.Count == 1) //只查找到1条匹配记录,直接赋值
            {
                control.Text = dt.Rows[0][displayFields[fieldName].Trim()].ToString().Trim();
            }
            else
            {
                FilterInfoForm form = new FilterInfoForm(control, dt, fieldName);
                form.StartPosition = FormStartPosition.CenterScreen;
                form.ShowDialog();
            }
        }
예제 #5
0
        /// <summary>
        /// 模糊查找到需要的记录,并赋值给显示控件
        /// </summary>
        /// <param name="control">传入的显示信息的控件</param>
        /// <param name="tableName">表名</param>
        /// <param name="fieldName">希望得到值的字段</param>
        /// <param name="findFields">希望在哪些字段中模糊查找</param>
        /// <param name="displayFields">在显示界面中现实的字段</param>
        public static void FindInfoToControl(Control control, string tableName, string fieldName, Dictionary<string, string> findFields, Dictionary<string, string> displayFields)
        {
            string controlText = control.Text.ToString().Trim();
            if (controlText == "" || displayFields.Count <= 0)
                return;

            string strSql = "select ";
            foreach (string field in displayFields.Keys)
            {
                strSql += field.Trim() + " as " + displayFields[field].Trim() + ",";
            }

            strSql = strSql.Remove(strSql.Length - 1); //删除最后一个逗号
            strSql += " from " + tableName + " where ";

            foreach (string field in findFields.Keys)
            {
                if (findFields[field].Trim() == "s")
                    strSql += field + " like '%" + controlText + "%' or ";
                else if (findFields[field].Trim() == "n")
                    strSql += field + " like %" + controlText + "% or ";
            }
            strSql = strSql.Remove(strSql.Length - 3);

            DataTable dt = (new SqlDBConnect()).Get_Dt(strSql);
            if (dt == null || dt.Rows.Count <= 0)
            {
                MessageBox.Show("查找的信息不存在,请重新输入!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                control.Text = "";
                return;
            }
            if (dt.Rows.Count == 1) //只查找到1条匹配记录,直接赋值
            {
                control.Text = dt.Rows[0][displayFields[fieldName].Trim()].ToString().Trim();
            }
            else
            {
                FilterInfoForm form = new FilterInfoForm(control, dt, fieldName);
                form.StartPosition = FormStartPosition.CenterScreen;
                form.ShowDialog();
            }
        }
예제 #6
0
        /// <summary>
        /// 根据传入的SQl模糊查找到需要的记录
        /// </summary>
        /// <param name="control">传入的显示信息的控件</param>
        /// <param name="strSql">传入的SQL</param>
        /// <param name="fieldName">希望得到值的字段</param>
        public static void FindInfoToControl(Control control, string strSql, string fieldName)
        {
            DataTable dt = (new SqlDBConnect()).Get_Dt(strSql);

            if (dt == null || dt.Rows.Count <= 0)
            {
                MessageBox.Show("查找的信息不存在,请重新输入!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                control.Text = "";
                return;
            }
            if (dt.Rows.Count == 1) //只查找到1条匹配记录,直接赋值
            {
                control.Text = dt.Rows[0][fieldName].ToString().Trim();
            }
            else
            {
                FilterInfoForm form = new FilterInfoForm(control, dt, fieldName);
                form.StartPosition = FormStartPosition.CenterScreen;
                form.ShowDialog();
            }
        }
예제 #7
0
 /// <summary>
 /// 根据传入的SQl模糊查找到需要的记录
 /// </summary>
 /// <param name="control">传入的显示信息的控件</param>
 /// <param name="strSql">传入的SQL</param>
 /// <param name="fieldName">希望得到值的字段</param>
 public static void FindInfoToControl(Control control, string strSql, string fieldName)
 {
     DataTable dt = (new SqlDBConnect()).Get_Dt(strSql);
     if (dt == null || dt.Rows.Count <= 0)
     {
         MessageBox.Show("查找的信息不存在,请重新输入!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
         control.Text = "";
         return;
     }
     if (dt.Rows.Count == 1) //只查找到1条匹配记录,直接赋值
     {
         control.Text = dt.Rows[0][fieldName].ToString().Trim();
     }
     else
     {
         FilterInfoForm form = new FilterInfoForm(control, dt, fieldName);
         form.StartPosition = FormStartPosition.CenterScreen;
         form.ShowDialog();
     }
 }
예제 #8
0
        /// <summary>
        /// 客户编号 文本框 的Enter键
        /// </summary>       
        private void txtCustID_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                TextBox textBox = sender as TextBox;
                string textBoxName = textBox.Text.Trim();
                if (textBoxName == "")
                    return;
                string strSql = "select CustID as 客户编码,CustName as 客户名称,PinYinCode as 拼音助记码,communicateAddr as 通信地址, AtBank as 开户银行 " +
                                "from T_CustomerInf where CustID like '%{0}%' or CustName like '%{1}%' or PinYinCode like '%{2}%'";
                strSql = string.Format(strSql, textBoxName, textBoxName, textBoxName);

                DataTable dt = (new SqlDBConnect()).Get_Dt(strSql);
                if (dt == null || dt.Rows.Count <= 0)
                {
                    DialogResult dialogResult = MessageBox.Show("查找的客户品信息不存在,是否新增客户信息?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        CustomerInfAdd customeradd = new CustomerInfAdd("add", "");
                        customeradd.ShowDialog();
                    }
                    else
                        textBox.Text = "";
                }
                else if (dt.Rows.Count == 1) //只查找到1条匹配记录,直接赋值
                {
                    textBox.Text = dt.Rows[0]["客户编码"].ToString().Trim();
                }
                else
                {
                    FilterInfoForm form = new FilterInfoForm(textBox, dt, "客户编码");
                    form.StartPosition = FormStartPosition.CenterScreen;
                    form.ShowDialog();
                }

                DataBindCustomerInf(textBox.Text.Trim());
            }
        }
예제 #9
0
        /// <summary>
        /// 需特殊处理的textBox,为其添加响应Enter键
        /// </summary>
        void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
                return;

            TextBox textBox = (sender as TextBox);
            string textBoxText = textBox.Text.Trim();
            if (textBox.Text.Trim() == "")
                return;
            string textBoxName = textBox.Name.Trim();
            switch (textBoxName)
            {
                #region Case选择
                case "s_DeliveryPerson":
                case "s_ReceiptPerson":
                case "s_Salesman":
                case "s_technician":
                case "s_VerifyPerson":
                case "s_Keeper":
                case "s_BillUserId":
                case "s_accountPerson":
                case "s_CheckPerson":
                    {
                        //送货人,收货人 业务员 技术员 验收员 保管员 制单人 收款人  复核员
                        string strSql = "select distinct UserId as 用户编码,UserName as 用户名,UserNameZJM as 用户名助记码,PersType as 类型,OfficeTel as 办公电话, MobileTel as 移动电话 " +
                                        "from T_Users where UserId like '%{0}%' or UserName like '%{1}%' or UserNameZJM like '%{2}%'";
                        strSql = string.Format(strSql, textBoxText, textBoxText, textBoxText);
                        //InitFuncs.FindInfoToControl(textBox, strSql, "用户名");
                        DataTable dt = (new SqlDBConnect()).Get_Dt(strSql);
                        if (dt == null || dt.Rows.Count <= 0)
                        {
                            MessageBox.Show("查找的信息不存在,请重新输入!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            textBox.Text = "";
                            return;
                        }
                        if (dt.Rows.Count == 1) //只查找到1条匹配记录,直接赋值
                        {
                            textBox.Text = dt.Rows[0]["类型"].ToString().Trim() + "/" + dt.Rows[0]["用户名"].ToString().Trim();
                        }
                        else
                        {
                            FilterInfoForm form = new FilterInfoForm(textBox, dt, "用户名", "类型");
                            form.StartPosition = FormStartPosition.CenterScreen;
                            form.ShowDialog();
                        }

                        break;
                    }
                default:
                    break;
                #endregion
            }
        }