/*
         * 查询对应clientName纪录,并赋值给相应的textBox
         */
        public void setTextBoxValue(int id)
        {
            clientNo = id;

            ClientInformationManager clientInformationManager = new ClientInformationManager();
            Dictionary<String, String> rst = clientInformationManager.queryClientById(clientNo);
            foreach (Control ctl in this.Controls)
            {
                if (ctl.GetType().Name == "TextBox")
                {
                    TextBox textBox = (TextBox)ctl;
                    textBox.Text = rst[textBox.Name];
                }
            }
        }
        /*
         * 保存新客户信息到数据库
         */
        private void saveBtn_Click(object sender, EventArgs e)
        {
            ClientInformationManager clientInformationManager = new ClientInformationManager();
            Dictionary<String, String> items = new Dictionary<String, String>();
            foreach (Control child in this.Controls)
            {
                if (child.GetType().Name == "TextBox")
                {
                    items.Add(child.Name,((TextBox)child).Text);        //TextBox控件名和DB对应字段名称相同
                }
            }

            if (operationFlag == 0)
            {
                clientInformationManager.insertClient(items);
            }
            else if(operationFlag == 1)
            {
                items.Add("clientNo",Convert.ToString(clientNo));
                clientInformationManager.updateClient(items);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 /*
  * 根据条件查询相应的客户信息
  */
 public void searchClients(Dictionary<String,String> items)
 {
     ClientInformationManager clientInformationManager = new ClientInformationManager();
     this.clientList.DataSource = clientInformationManager.queryClientByMutiCondition(items);
 }
 /*
  * 遍历客户表,填充dataGridView
  */
 private void fillClientList()
 {
     ClientInformationManager clientInformationManager = new ClientInformationManager();
     this.clientList.DataSource = clientInformationManager.listClient();
 }
        /*
         * 删除按钮点击事件函数
         */
        private void removeBtn_Click(object sender, EventArgs e)
        {
            if (this.clientList.Rows.Count <= 0)
            {
                MessageBox.Show(this,
                                "当前表内容为空,无法删除!",
                                "删除客户提示",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            //表格最多只能选择一行
            int currentIndex = this.clientList.CurrentRow.Index;
            if (currentIndex >= 0)
            {
                DialogResult rst = MessageBox.Show(this,
                                                   "确定删除该选中项纪录?",
                                                   "删除客户提示",
                                                   MessageBoxButtons.OKCancel,
                                                   MessageBoxIcon.Warning);
                if (rst == DialogResult.OK)
                {
                    DataGridViewRow currentRow = this.clientList.Rows[currentIndex];
                    ClientInformationManager clientInformationManager = new ClientInformationManager();
                    clientInformationManager.removeClientById(int.Parse(currentRow.Cells[0].Value.ToString()));
                    fillClientList();
                }
            }
        }