⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientlistpanel.cs

📁 社区管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
            {//成功修改,更新DataGridView
                DataGridViewRow row = dataGridView.Rows[selectedIndex];
                row.Cells["姓名"].Value = tbName.Text;
                row.Cells["性别"].Value = cbSex.Text;
                row.Cells["年龄"].Value = tbAge.Text;
                row.Cells["职业"].Value = tbWork.Text;
                row.Cells["需求1"].Value = cbPreferedCategory.Text;
                row.Cells["需求2"].Value = tbPreferedArea.Text;
            }
        }

        private void showDetailInfo(int idx)
        {
            if (idx < 0) return;
            selectedIndex = idx;
            dealID = (Int64)dataGridView.Rows[idx].Cells["交易编号"].Value;//得到用户选择的行的主键
            DataTable dt = DBManager.ExecuteSelectCommand(String.Format("select * from 交易信息 where 交易编号='{0}'", dealID));
            if (dt == null)
            {//数据库错误
                MessageBox.Show(DBManager.errorMessage);
                dealID = 0;
                return;
            }
            else if (dt.Rows.Count == 0)
            {  //未找到此记录
                MessageBox.Show("此记录可能已被其他用户删除");
                dealID = 0;
                return;
            }

            tbName.Text = (String)dt.Rows[0]["姓名"];
            cbSex.Text = (String)dt.Rows[0]["性别"];
            tbAge.Text = (Int32)dt.Rows[0]["年龄"] + "";  //用这种方式将数字转换成字符串
            tbWork.Text = (String)dt.Rows[0]["职业"];
            tbTel.Text = (Int64)dt.Rows[0]["电话"] + "";
            tbCellPhone.Text = (Int64)dt.Rows[0]["移动电话"] + "";
            cbPreferedCategory.Text = (String)dt.Rows[0]["需求1"];
            tbPreferedArea.Text = (String)dt.Rows[0]["需求2"];
            tbPrepayAmmount.Text = (double)dt.Rows[0]["预付金额"] + "";
            tbUsage.Text = (String)dt.Rows[0]["需求3"];
            tbAddress.Text = (String)dt.Rows[0]["联系地址"];

            bModify.Enabled = true;//此时可以操作修改、删除数据
            bDelete.Enabled = true;
        }

        private bool checkInput(String str)
        {
            tbName.Text = tbName.Text.Trim();   //将多余的空格去掉
            cbSex.Text = cbSex.Text.Trim();
            tbAge.Text = tbAge.Text.Trim();
            tbWork.Text = tbWork.Text.Trim();
            tbTel.Text = tbTel.Text.Trim();
            tbCellPhone.Text = tbCellPhone.Text.Trim();
            cbPreferedCategory.Text = cbPreferedCategory.Text.Trim();
            tbPreferedArea.Text = tbPreferedArea.Text.Trim();
            tbPrepayAmmount.Text = tbPrepayAmmount.Text.Trim();
            tbUsage.Text = tbUsage.Text.Trim();
            tbAddress.Text = tbAddress.Text.Trim();

            if (str == "Insert" || str == "Modify")
            {//以下是在更新或插入时检查输入是否为空
                if (tbName.Text == "") return ErrorMessage("姓名为空");
                if (cbSex.Text == "") return ErrorMessage("性别为空");
                if (tbAge.Text == "") return ErrorMessage("年龄为空");
                if (tbWork.Text == "") return ErrorMessage("职业为空");
                if (tbTel.Text == "") return ErrorMessage("电话为空");
                if (tbCellPhone.Text == "") return ErrorMessage("移动电话为空");
                if (cbPreferedCategory.Text == "") return ErrorMessage("需求户型为空");
                if (tbPreferedArea.Text == "") return ErrorMessage("需求大小为空");
                if (tbPrepayAmmount.Text == "") return ErrorMessage("预付金额为空");
                if (tbUsage.Text == "") return ErrorMessage("住房用途为空");
                if (tbAddress.Text == "") return ErrorMessage("联系地址为空");
            }

            //下面为检查输入数字的TextBox和ComboBox的输入格式是否正确
            if (cbSex.Text != "" && cbSex.Text != "男" && cbSex.Text != "女") return ErrorMessage("性别输入错误");
            //当此函数由查询按钮调用时,某些控件可能为空字符串,因此在转化前加了一个判断
            try
            {
                if (tbAge.Text != "") Int64.Parse(tbAge.Text);    //
            }
            catch
            {
                return ErrorMessage("年龄输入错误");
            }

            try
            {
                if (tbTel.Text != "") Int64.Parse(tbTel.Text);
            }
            catch
            {
                return ErrorMessage("电话号码输入错误");
            }

            try
            {
                if (tbCellPhone.Text != "") Int64.Parse(tbCellPhone.Text);
            }
            catch
            {
                return ErrorMessage("手机号码输入错误");
            }

            try
            {
                if (tbPreferedArea.Text != "") int.Parse(tbPreferedArea.Text);
            }
            catch
            {
                return ErrorMessage("需求大小输入错误");
            }

            try
            {
                if (tbPrepayAmmount.Text != "") float.Parse(tbPrepayAmmount.Text);
            }
            catch
            {
                return ErrorMessage("预付金额输入错误");
            }
            return true;
        }

        private String generateSelectCommand()
        {
            String cmd = "Select 姓名,性别,需求1,需求2,年龄,职业,交易编号 from 交易信息 where 交易类型='房屋出售'";
            bool cmdChanged = false;

            if (tbName.Text != "")
                cmd = cmd + " and 姓名='" + tbName.Text + "'";

            if (cbSex.Text != "")
                cmd = cmd + " and 性别='" + cbSex.Text + "'";

            if (tbAge.Text != "")
                cmd = cmd + " and 年龄='" + tbAge.Text + "'";

            if (tbWork.Text != "")
                cmd = cmd + " and 职业='" + tbWork.Text + "'";

            if (tbTel.Text != "")
                cmd = cmd + " and 电话='" + tbTel.Text + "'";

            if (tbCellPhone.Text != "")
                cmd = cmd + " and 移动电话='" + tbCellPhone.Text + "'";

            if (cbPreferedCategory.Text != "")
                cmd = cmd + " and 需求1='" + cbPreferedCategory.Text + "'";

            if (tbPreferedArea.Text != "")
                if (cmdChanged) cmd = cmd + " and 需求2='" + tbPreferedArea.Text + "'";

            if (tbPrepayAmmount.Text != "")
                cmd = cmd + " and 预付金额='" + tbPrepayAmmount.Text + "'";

            if (tbUsage.Text != "")
                cmd = cmd + " and 需求3='" + tbUsage.Text + "'";

            if (tbAddress.Text != "")
                cmd = cmd + " and 联系地址='" + tbAddress.Text + "'";

            return cmd;
        }

        private String generateUpdateCommand()
        {
            String cmd = "";
            cmd = String.Format("update 交易信息 set 姓名='{0}',性别='{1}',年龄='{2}',职业='{3}',电话='{4}',", tbName.Text, cbSex.Text, tbAge.Text, tbWork.Text, tbTel.Text);
            cmd = cmd + String.Format("移动电话='{0}',需求1='{1}',需求2='{2}',预付金额='{3}',需求3='{4}',联系地址='{5}'", tbCellPhone.Text, cbPreferedCategory.Text, tbPreferedArea.Text, tbPrepayAmmount.Text, tbUsage.Text, tbAddress.Text);
            cmd = cmd + String.Format(" where 交易编号='{0}'", dealID);
            return cmd;
        }

        private String generateInsertCommand() {
            String cmd="insert into 交易信息 values(";
            Int64 id = DateTime.Now.ToBinary();
            insertDealID = id;
            cmd = cmd + String.Format("'{0}','房屋出售','{1}','{2}','{3}','{4}',",id,tbName.Text,cbSex.Text,tbAge.Text,tbWork.Text);
            cmd = cmd + String.Format("'{0}','{1}','{2}','{3}','{4}','',",tbTel.Text,tbCellPhone.Text,cbPreferedCategory.Text,tbPreferedArea.Text,tbUsage.Text);
            cmd = cmd + String.Format("'{0}','0','{1}')",tbAddress.Text,tbPrepayAmmount.Text);
            return cmd;
        }

        private String generateDeleteCommand() { 
            String cmd=String.Format("Delete from 交易信息 where 交易编号='{0}'",dataGridView.Rows[selectedIndex].Cells["交易编号"].Value);
            return cmd;
        }

        private void label8_Click(object sender, EventArgs e)
        {

        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -