📄 houseservicepanel.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DataBaseManagerLibrary;
namespace FuWuControlLibrary1
{
public partial class HouseServicePanel : UserControl
{
private DataBaseManager DBManager;
private Int64 dealID;
private int selectedIndex;
public HouseServicePanel()
{
InitializeComponent();
reset();
//setDataBaseManager(null);
}
public void visilize()
{
reset(); //将各个控件置为初始状态
this.Visible = true;
}
public void disVisilize()
{
this.Visible = false;
}
private bool ErrorMessage(String msg)
{
MessageBox.Show(msg);
return false;
}
private void reset()
{
dealID = 0;
dgvFW.DataSource = null;
selectedIndex = -1;
// btFWalter.Enabled = false;
// btFWdel.Enabled = false;
// btFWpri.Enabled = false;
tbFWnum.Text = "";
tbFWname.Text = "";
tbFWneirong.Text = "";
cbFWkind.Text = "";
tbFWweitr.Text = "";
tbFWshoutr.Text = "";
tbFWcount.Text = "";
tbFWexp.Text = "";
}
public void setDataBaseManager(DataBaseManager DBManager)
{
//String SqlConnectInfo = "server=66C69BFD29E4473;database=test;uid=sa;pwd=''";
//DBManager = new DataBaseManager(SqlConnectInfo);
this.DBManager = DBManager;
DataTable dt = DBManager.ExecuteSelectCommand("select * from 服务管理信息");
if (dt == null) MessageBox.Show(DBManager.errorMessage);
dgvFW.DataSource = dt;
// Int64 i=(Int64)dgvFW.Rows[0].Cells["服务编号"].Value;
}
private void btFWsel_Click(object sender, EventArgs e)
{
String cmd;
if (checkInput("Select") == false) return; //用户输入不合法
cmd = generateSelectCommand(); //根据输入情况生成相应的命令
DataTable dataTable = DBManager.ExecuteSelectCommand(cmd);
if (dataTable == null)
{ //数据库出错
MessageBox.Show(DBManager.errorMessage);
return;
}
else if (dataTable.Rows.Count == 0)
{//没有搜索到对应信息,显示一个空的dgvFW
dgvFW.DataSource = dataTable;
return;
}
else
{//至少找到一条信息,将信息显示到dgvFW,并将第一条信息详细列出
dgvFW.DataSource = dataTable;
showDetailInfo(0);
}
}
private void showDetailInfo(int idx)
{
if (idx < 0) return;
selectedIndex = idx;
dealID = (Int64)dgvFW.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;
}
/* if (idx < 0) return;
selectedIndex = idx;
dealID = (Int64)dgvFW.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)
{ //未找到此记录where 服务编号={0}
MessageBox.Show("此记录可能已被其他用户删除");
dealID = 0;
return;
}
tbFWnum.Text = (Int64)dt.Rows[0]["服务编号"] + "";
tbFWname.Text = (String)dt.Rows[0]["服务名称"];
cbFWkind.Text = (String)dt.Rows[0]["服务类别"];
tbFWneirong.Text = (String)dt.Rows[0]["内容"]; //用这种方式将数字转换成字符串
tbFWweitr.Text = (String)dt.Rows[0]["委托人"];
tbFWshoutr.Text = (String)dt.Rows[0]["受托人"];
tbFWcount.Text = (Int64)dt.Rows[0]["数量"] + "";
// tbFWweit.Value = dt.Rows[0]["委托时间"];
// tbFWyuqi.Value = dt.Rows[0]["预期完成时间"];
tbFWexp.Text = (String)dt.Rows[0]["时间说明"];
btFWalter.Enabled = true;//此时可以操作修改、删除数据
btFWdel.Enabled = true;*/
}
private bool checkInput(String str)
{
tbFWnum.Text = tbFWnum.Text.Trim();
tbFWname.Text = tbFWname.Text.Trim();
cbFWkind.Text = cbFWkind.Text.Trim();
tbFWneirong.Text = tbFWneirong.Text.Trim();
tbFWweitr.Text = tbFWweitr.Text.Trim();
tbFWshoutr.Text = tbFWshoutr.Text.Trim();
tbFWcount.Text = tbFWcount.Text.Trim();
tbFWexp.Text = tbFWexp.Text.Trim();
if (str == "Insert" || str == "Modify")
{//以下是在更新或插入时检查输入是否为空
if (tbFWnum.Text == "") return ErrorMessage("服务编号为空");
if (tbFWname.Text == "") return ErrorMessage("服务名称为空");
if (cbFWkind.Text == "") return ErrorMessage("服务类别为空");
if (tbFWneirong.Text == "") return ErrorMessage("内容为空");
if (tbFWweitr.Text == "") return ErrorMessage("委托人为空");
if (tbFWshoutr.Text == "") return ErrorMessage("受托人为空");
if (tbFWcount.Text == "") return ErrorMessage("数量为空");
if (tbFWexp.Text == "") return ErrorMessage("时间说明为空");
}
//下面为检查输入数字的TextBox和ComboBox的输入格式是否正确
if (tbFWnum.Text != "") {
try
{
Int64.Parse(tbFWnum.Text);
}
catch {
return ErrorMessage("编号输入错误");
}
}
if (tbFWcount.Text != "")
{
try
{
Int64.Parse(tbFWcount.Text);
}
catch
{
ErrorMessage("数量输入错误");
}
}
if (cbFWkind.Text != ""&&cbFWkind.Text!="代缴"&&cbFWkind.Text!="代收"&&cbFWkind.Text!="代领"&&cbFWkind.Text!="一览")
return ErrorMessage("服务类型输入错误");
return true;
}
private String generateSelectCommand()
{
String cmd = "Select 服务编号,服务名称,服务类别,内容,委托人,受托人,数量,委托时间,预期完成时间,时间说明 from 服务管理信息 ";
bool cmdChanged = false;
if (tbFWnum.Text != "")
{
if (cmdChanged) cmd = cmd + "and 服务编号=" + Int64.Parse(tbFWnum.Text);
else
{
cmd = cmd + "where 服务编号=" + Int64.Parse(tbFWnum.Text);
cmdChanged = true;
}
}
if (tbFWname.Text != "")
{
if (cmdChanged) cmd = cmd + " and 服务名称='" + tbFWname.Text + "'";
else cmd = cmd + " where 服务名称='" + tbFWname.Text + "'";
cmdChanged = true;
}
if (cbFWkind.Text != "")
{
if (cmdChanged) cmd = cmd + " and 服务类别='" + cbFWkind.Text + "'";
else cmd = cmd + "服务类别='" + cbFWkind.Text + "'";
cmdChanged = true;
}
if (tbFWneirong.Text != "")
{
if (cmdChanged) cmd = cmd + " and 内容='" + tbFWneirong.Text + "'";
else cmd = cmd + " where 内容='" + tbFWneirong.Text + "'";
cmdChanged = true;
}
if (tbFWweitr.Text != "")
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -