📄 hotelreserve.cs
字号:
txt8.ReadOnly=!blnEdit;
txt9.ReadOnly=!blnEdit;
txt10.ReadOnly=!blnEdit;
txt11.ReadOnly=!blnEdit;
txt12.ReadOnly=!blnEdit;
txt13.ReadOnly=!blnEdit;
txt15.ReadOnly=!blnEdit;
txt16.ReadOnly=!blnEdit;
txt17.ReadOnly=!blnEdit;
txt18.ReadOnly=!blnEdit;
txt19.ReadOnly=!blnEdit;
txt20.ReadOnly=!blnEdit;
cmb2.Enabled=blnEdit;
cmb3.Enabled=blnEdit;
checkBox1.Enabled=blnEdit;
btnRoom.Enabled=blnEdit;
}
//-------重写新增记录时设置默认值函数--------
protected override void SetDefaultValue()
{
//base.SetDefaultValue();
txt14.Text="预定";//新增单据状态为预定
//自动计算新编号
string connStr="workstation id=localhost;Integrated Security=SSPI;Database=hotelbook;";
SqlConnection cn=new SqlConnection(connStr);
cn.Open();
SqlCommand cmd=cn.CreateCommand();
if(dataSet21.预定单.Rows.Count==0)
cmd.CommandText="select max(预定单号) 最大编号 from 预定单历史";
else
cmd.CommandText="select max(预定单号) 最大编号 from 预定单";
object result=cmd.ExecuteScalar();
int order=1;
if(result!=System.DBNull.Value)
{
string maxID=result.ToString().Trim();
maxID=maxID.Substring(2,maxID.Length-2);
order=Convert.ToInt16(maxID)+1;
}
int length=order.ToString().Length;
string newID="";
switch(length)
{
case 1:
newID="YD0000000"+order.ToString();
break;
case 2:
newID="YD000000"+order.ToString();
break;
case 3:
newID="YD00000"+order.ToString();
break;
case 4:
newID="YD0000"+order.ToString();
break;
case 5:
newID="YD000"+order.ToString();
break;
case 6:
newID="YD00"+order.ToString();
break;
case 7:
newID="YD0"+order.ToString();
break;
}
txt4.Text=newID;//自动生成编号
cmb2.Text=System.DateTime.Now.Date.ToString();//抵店时间默认为当天
cmb3.Text=System.DateTime.Now.Date.AddDays(3).ToString();//离店时间为3天后
} //-------重写检查非空字段函数--------
protected override bool CheckNotNull()
{
if(txt4.Text.Trim()=="")// 检查预定编号
{
MessageBox.Show("预定编号不能为空","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
return(false);
}
if(txt6.Text.Trim()=="")//检查客房编号
{
MessageBox.Show("请选择客房编号","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
return(false);
}
if(cmb2.Text.Trim()=="")//检查抵店时间
{
MessageBox.Show("请选择抵店时间","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
return(false);
}
return base.CheckNotNull ();
}
//-----显示和选择抵店日期和离店日期-----
private void cmb2_DropDown(object sender, System.EventArgs e)
{
selectDate(cmb2);
}
private void cmb3_DropDown(object sender, System.EventArgs e)
{
selectDate(cmb3);
}
//----------关闭日期控件的显示----------
private void cmb2_Leave(object sender, System.EventArgs e)
{
calen1.Visible=false;
}
private void cmb3_Leave(object sender, System.EventArgs e)
{
calen1.Visible=false;
}
//-----------单击下拉列表框下拉箭头时显示日期以供选择---------------
private void selectDate(ComboBox cb)
{
calen1.Left=cb.Left;//设置日期控件的位置
calen1.Top=cb.Top-calen1.Height-10+groupBox2.Top;
if(cb.Text.Trim()!="")
{
calen1.SelectionStart=Convert.ToDateTime(cb.Text);//日历显示的时间为数据时间
calen1.SelectionEnd=Convert.ToDateTime(cb.Text);
}
calen1.Visible=true;//显示日期
calen1.Show();
}
//-----------从日历控件中选择日期信息------------
private void calen1_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e)
{
//判断是由哪个下拉列表框调出日历,以便回馈日期信息
if(calen1.Left==cmb2.Left)
cmb2.Text=calen1.SelectionEnd.ToString();
if(calen1.Left==cmb3.Left)
cmb3.Text=calen1.SelectionEnd.ToString();
}
//--------根据输入条件,搜索数据----------
private void btnSearch_Click(object sender, System.EventArgs e)
{
da1.SelectCommand.Parameters[0].Value="%";
da1.SelectCommand.Parameters[1].Value="%";
da1.SelectCommand.Parameters[2].Value="%";
if(txt1.Text.Trim()!="")
{
da1.SelectCommand.Parameters[0].Value="%"+txt1.Text.Trim()+"%";
}
if(txt2.Text.Trim()!="")
{
da1.SelectCommand.Parameters[1].Value="%"+txt2.Text.Trim()+"%";
}
if(txt3.Text.Trim()!="")
{
da1.SelectCommand.Parameters[2].Value="%"+txt3.Text.Trim()+"%";
}
dataSet21.Clear();//刷新数据集
da1.Fill(dataSet21);
//填充其他编号和名称数据
da2.Fill(dataSet21);
}
//----------显示房态图并选择房间---------
private void btnRoom_Click(object sender, System.EventArgs e)
{
RoomStatus newfrm=new RoomStatus(1);
newfrm.ShowDialog();
}
private void btnRoom_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(roomInfo[0].Trim()=="")
{
return;
}
txt6.Text=roomInfo[0];//显示房间编号
cmb1.Text=roomInfo[1];//显示房间类型
string strConn="workstation id=localhost;Integrated Security=SSPI;Database=hotelbook;";
SqlConnection cn=new SqlConnection(strConn);
cn.Open();
SqlCommand cmd=cn.CreateCommand();
cmd.CommandText="SELECT 价格 FROM 客房类型 where 类型名称='"+cmb1.Text+"'";
txt7.Text=cmd.ExecuteScalar().ToString().Trim();//读入该类型客房价格
txt8.Text=txt7.Text;//入住价格默认和客房价格一致
}
//---------保存预定单后更新房态-----------
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
//在保存数据后再进行处理
if(e.Button.ToolTipText=="提交")
{
//更新预定房间状态
string strConn="workstation id=localhost;Integrated Security=SSPI;Database=hotelbook;";
SqlConnection cn=new SqlConnection(strConn);
cn.Open();
SqlCommand cmd=cn.CreateCommand();
cmd.CommandText="update 客房信息 set 状态='将到' where 客房编号='"+txt6.Text+"'";
cmd.ExecuteNonQuery();
}
} }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -