📄 houseservicepanel.cs
字号:
if (cmdChanged) cmd = cmd + " and 委托人='" + tbFWweitr.Text + "'";
else cmd = cmd + "委托人='" + tbFWweitr.Text + "'";
cmdChanged = true;
}
if (tbFWshoutr.Text != "")
{
if (cmdChanged) cmd = cmd + " and 受托人='" + tbFWshoutr.Text + "'";
else cmd = cmd + " where 受托人='" + tbFWshoutr.Text + "'";
cmdChanged = true;
}
if (tbFWcount.Text != "")
{
if (cmdChanged) cmd = cmd + " and 数量=" + Int64.Parse(tbFWcount.Text);
else cmd = cmd + " where 数量='" + tbFWcount.Text + "'";
cmdChanged = true;
}
/* if (tbFWweit.Text != null)
{
if (cmdChanged) cmd = cmd + " and 委托时间='" + tbFWweit.Text + "'";
else cmd = cmd + " 委托时间='" + tbFWweit.Text + "'";
cmdChanged = true;
}
if (tbFWyuqi.Text != null)
{
if (cmdChanged) cmd = cmd + " and 预期完成时间='" + tbFWyuqi.Text + "'";
else cmd = cmd + " 预期完成时间='" + tbFWyuqi.Text + "'";
cmdChanged = true;
}*/
if (tbFWexp.Text != "")
{
if (cmdChanged) cmd = cmd + " and 时间说明='" + tbFWexp.Text + "'";
else cmd = cmd + " where 时间说明='" + tbFWexp.Text + "'";
cmdChanged = true;
}
return cmd;
}
private String generateUpdateCommand()
{
String cmd = "";
cmd = String.Format("update 服务管理信息 set 服务名称='{0}',服务类别='{1}',内容='{2}',委托人='{3}',受托人='{4}',", tbFWname.Text, cbFWkind.Text, tbFWneirong.Text, tbFWweitr.Text, tbFWshoutr.Text);
cmd = cmd + String.Format("数量={0},委托时间='{1}',预期完成时间='{2}',时间说明='{3}'", tbFWcount.Text, tbFWweit.Text, tbFWyuqi.Text, tbFWexp.Text);
cmd = cmd + String.Format(" where 服务编号='{0}'", tbFWnum.Text);
return cmd;
}
private String generateInsertCommand()
{
String cmd = "insert into 服务管理信息 values(";
cmd = cmd + String.Format("{0},'{1}','{2}','{3}','{4}',", Int64.Parse(tbFWnum.Text), tbFWname.Text, cbFWkind.Text, tbFWneirong.Text, tbFWweitr.Text);
cmd = cmd + String.Format("'{0}',{1},'{2}','{3}','{4}')", tbFWshoutr.Text, Int64.Parse(tbFWcount.Text), tbFWweit.Text, tbFWyuqi.Text, tbFWexp.Text);
return cmd;
}
private String generateDeleteCommand()
{
String cmd = String.Format("Delete from 服务管理信息 where 服务编号='{0}'", dgvFW.Rows[selectedIndex].Cells["服务编号"].Value);
return cmd;
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
}
private void btFWdel_Click(object sender, EventArgs e)
{
if (selectedIndex == -1) return;
String cmd = generateDeleteCommand();
int affectRows = DBManager.Execute(cmd);
if (affectRows == -1)
{ //数据库出错
MessageBox.Show(DBManager.errorMessage);
return;
}
else if (affectRows == 0)
{
MessageBox.Show("此数据已被其他登陆用户删除");
}
if (selectedIndex == dgvFW.Rows.Count - 2)
{
dgvFW.Rows.Remove(dgvFW.Rows[selectedIndex]);
selectedIndex--;
if (selectedIndex == -1)
{//若dgvFW没有数据则重置界面
reset();
return;
}
}
else dgvFW.Rows.Remove(dgvFW.Rows[selectedIndex]);
showDetailInfo(selectedIndex);
}
private void btFWadd_Click(object sender, EventArgs e)
{
String cmd;
if (checkInput("Insert") == false) return;//用户输入错误
cmd = generateSelectCommand(); //首先查找数据库中有没有相同内容的行
DataTable dataTable = DBManager.ExecuteSelectCommand(cmd);
if (dataTable == null)
{ //数据库出错
MessageBox.Show(DBManager.errorMessage);
return;
}
else if (dataTable.Rows.Count > 0)
{
MessageBox.Show("数据库中已存在相同信息");
return;
}
//将信息添加到数据库
cmd = generateInsertCommand(); //根据输入情况生成相应的命令
int affectedRows = DBManager.Execute(cmd);
if (affectedRows == -1)
{ //数据库出错
MessageBox.Show(DBManager.errorMessage);
return;
}
else if (affectedRows == 0)
{//
MessageBox.Show("插入失败");
return;
}
else
{
MessageBox.Show("插入成功");
//插入成功,
dgvFW.DataSource = DBManager.ExecuteSelectCommand("select * from 服务管理信息");
showDetailInfo(selectedIndex);
btFWalter.Enabled = true;
btFWdel.Enabled = true;
}
//显示插入前的一行
/*DataRow row = new DataRow();
row.set
row.ItemArray={insertDealID,tbName.Text};
dgvFWCell[] cell = new dgvFWCell[6];
for (int i = 0; i < 6; i++) cell[i] = new dgvFWCell();
row.Cells = cell;
row.Cells[0].Value=insertDealID;
row.Cells[1].Value=tbName.Text;
row.Cells[2].Value=cbSex.Text;
row.Cells[3].Value=int.Parse(tbAge.Text);
row.Cells[4].Value=tbWork.Text;
row.Cells[5].Value=cbPreferedCategory.Text;
row.Cells[6].Value=tbPreferedArea.Text;
dgvFW.Rows.Add(row);
int idx = dgvFW.Rows.IndexOf(row);
selectedIndex = idx;
showDetailInfo(idx);
*/
}
private void btFWalter_Click(object sender, EventArgs e)
{
String cmd;
if (checkInput("Modify") == false) return; //用户输入不合法
cmd = generateUpdateCommand(); //根据输入情况生成相应的命令
int affectRows = DBManager.Execute(cmd);
if (affectRows == -1)
{ //数据库出错
MessageBox.Show(DBManager.errorMessage);
return;
}
else if (affectRows == 0)
{//没有搜索到对应信息
MessageBox.Show("信息可能已被其他用户删除");
return;
}
else
{//成功修改,更新dgvFW
DataGridViewRow row = dgvFW.Rows[selectedIndex];
row.Cells["服务名称"].Value = tbFWname.Text;
row.Cells["服务类别"].Value = cbFWkind.Text;
row.Cells["内容"].Value = tbFWneirong.Text;
row.Cells["委托人"].Value = tbFWweitr.Text;
row.Cells["受托人"].Value = tbFWshoutr.Text;
row.Cells["数量"].Value = tbFWcount.Text;
row.Cells["委托时间"].Value = tbFWweit.Text;
row.Cells["预期完成时间"].Value = tbFWyuqi.Text;
row.Cells["时间说明"].Value = tbFWexp.Text;;
}
}
private void pFW2_Paint(object sender, PaintEventArgs e)
{
}
private void dgvFW_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1 || e.RowIndex >= dgvFW.Rows.Count - 1) return; //选择多行或选择列标签
showDetailInfo(e.RowIndex);
selectedIndex = e.RowIndex;
tbFWnum.Text = (dgvFW.Rows[selectedIndex].Cells["服务编号"].Value).ToString();
tbFWname.Text = (dgvFW.Rows[selectedIndex].Cells["服务名称"].Value).ToString();
cbFWkind.Text = (dgvFW.Rows[selectedIndex].Cells["服务类别"].Value).ToString();
tbFWneirong.Text = (dgvFW.Rows[selectedIndex].Cells["内容"].Value).ToString();
tbFWshoutr.Text = (dgvFW.Rows[selectedIndex].Cells["受托人"].Value).ToString();
tbFWweitr.Text = (dgvFW.Rows[selectedIndex].Cells["委托人"].Value).ToString();
tbFWcount.Text = (dgvFW.Rows[selectedIndex].Cells["数量"].Value).ToString();
tbFWweit.Text = (dgvFW.Rows[selectedIndex].Cells["委托时间"].Value).ToString();
tbFWyuqi.Text = (dgvFW.Rows[selectedIndex].Cells["预期完成时间"].Value).ToString();
tbFWexp.Text = (dgvFW.Rows[selectedIndex].Cells["时间说明"].Value).ToString();
}
private void tbFWname_TextChanged(object sender, EventArgs e)
{
}
private void tbFWcount_TextChanged(object sender, EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -