private void btnEnsure_Click(object sender, EventArgs e) { AutoId ai = new AutoId(); if (ValidateInput()) { string sql; DBHelper db = null; try { db = new DBHelper(); string Room_id = cboNewHouse.Text.Substring(0, cboNewHouse.Text.IndexOf(" ")); string R_id = hh.GetR_id(Room_id); sql = string.Format("Update Guest set R_id='{0}',Bookleave='{1}',comeDate='{3}' where G_GuestId='{2}'", R_id, dtpBookLeave.Text, lblOldDate.Tag, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); if (db.UpdateDeleteAdd(sql) > 0) { if (hh.IshaveBook(cboOldHouse.Text)) { sql = string.Format("update Room set State ='{0}' where R_id='{1}'", "预订", hh.GetR_id(cboOldHouse.Text)); } else { sql = string.Format("update Room set State ='{0}' where R_id='{1}'", "空净", hh.GetR_id(cboOldHouse.Text)); } db.UpdateDeleteAdd(sql); sql = string.Format("update Room set State='{0}' where R_id='{1}'", "待客", R_id); db.UpdateDeleteAdd(sql); sql = string.Format("insert into Consume values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", ai.GetId("C_ConsumeId", "Consume"), lblOldDate.Tag, "换房消费", lblOldPrice.Text, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "房间消费", UserHelper.LoginId, txtRemark.Text ); db.UpdateDeleteAdd(sql); MessageBox.Show("换房成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("换房失败!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { db.GetClose(); } } }
//写入商品消费表中 private void Consume() { string G_GuestId = ""; AutoId ai = new AutoId(); //自动生成id 辅助类 HouseHelper hh = new HouseHelper(); //辅助类 DBHelper db = null; //连数据库类 db = new DBHelper(); try { string sql; string C_ConsumeId; string R_id = hh.GetR_id(cboRoomId.Text); sql = string.Format("select G_GuestId from Guest where R_id='{0}' and faceDate='{1}'", R_id, ""); SqlDataReader sdr = db.SelectAll(sql); if (sdr.Read()) { G_GuestId = sdr["G_GuestId"].ToString(); } sdr.Close(); int rows = 0; //循环写入 for (int i = 0; i < lvSelect.Items.Count; i++) { C_ConsumeId = ai.GetId("C_ConsumeId", "Consume"); sql = string.Format("insert into Consume values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", C_ConsumeId, G_GuestId, lvSelect.Items[i].SubItems[0].Text, lvSelect.Items[i].SubItems[2].Text, lvSelect.Items[i].SubItems[3].Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "商品消费", UserHelper.LoginId, ""); //MessageBox.Show(sql); rows = db.UpdateDeleteAdd(sql); } if (rows > 0) { MessageBox.Show("消费成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("消费失败!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { db.GetClose(); } }
//显示价格等信息 private void ShowInfo(string room_id, int type) { string price = ""; DBHelper db = null; try { db = new DBHelper(); string sql = string.Format("select * from Room where R_RoomId='{0}'", room_id); SqlDataReader sdr = db.SelectAll(sql); if (sdr.Read()) { if (type == 0) { price = sdr["price"].ToString(); this.lblOldPrice.Text = price; } else { lblNewHouse.Text = sdr["price"].ToString(); } } sdr.Close(); HouseHelper hh = new HouseHelper(); string R_id = hh.GetR_id(room_id); sql = string.Format("select comeDate,G_GuestId from Guest where R_id='{0}' and faceDate='{1}'", R_id, ""); sdr = db.SelectAll(sql); if (sdr.Read()) { if (type == 0) { lblOldDate.Text = sdr["comeDate"].ToString(); lblOldDate.Tag = sdr["G_GuestId"].ToString(); } } sdr.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { db.GetClose(); } }
//入住酒店 private void House() { int count = lvSelectHouse.Items.Count; if (IsAwoke.foregiftSmall == "1") { double money = 0; for (int i = 0; i < count; i++) { money += Convert.ToDouble(lvSelectHouse.Items[i].SubItems[2].Text); } if (Convert.ToDouble(txtAdvanceForegift.Text) < money && txtCust.Text == "") { MessageBox.Show("押金小于房款!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAdvanceForegift.Focus(); txtAdvanceForegift.SelectAll(); return; } } int rows = 0; for (int i = 0; i < count; i++) { AutoId auto = new AutoId(); string G_GuestId = auto.GetId("G_GuestId", "Guest"); //MessageBox.Show(G_GuestId); string Room_id = lvSelectHouse.Items[i].SubItems[0].Text; string R_id = lvSelectHouse.Items[i].Tag.ToString(); string uName = txtName.Text; string sex = ""; if (rdoMan.Checked) { sex = "男"; } else { sex = "女"; } string CertificateType = cboCertificate.Text; string CertificateID = txtCertificateId.Text; string CertificatePic = picName; string Address = txtAddress.Text; string contactTel = txtContactTel.Text; string Underwrite = ""; string comeDate = dtpComeDate.Text; string Bookleave = dtpBookleave.Text; string faceDate = ""; string R_price = lvSelectHouse.Items[i].SubItems[2].Text; string Due = ""; string Fact = ""; string locate = ""; string Operator = UserHelper.LoginId; string remark = txtRemark.Text; string U_UserId = txtCust.Text; string sql = string.Format("insert into Guest values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}')", G_GuestId, R_id, U_UserId, uName, sex, CertificateType, CertificateID, CertificatePic, Address, contactTel, 0, Underwrite, comeDate, Bookleave, faceDate, R_price, Due, Fact, locate, Operator, remark ); DBHelper db = null; try { db = new DBHelper(); rows = db.UpdateDeleteAdd(sql); sql = string.Format("update Room set State='{0}', R_Count = R_Count + '{2}' where R_id ='{1}'", "待客", R_id, 1); //MessageBox.Show(sql); int temp = db.UpdateDeleteAdd(sql); if (cboIsAwoke.Checked) { sql = string.Format("insert into Awoke values('{0}','{1}','{2}','{3}','{4}')", auto.GetId("A_AwokeId", "Awoke"), lvSelectHouse.Items[i].SubItems[0].Text + "号房到期", "未读", dtpBookleave.Text, txtRemark.Text ); db.UpdateDeleteAdd(sql); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { db.GetClose(); } } HouseHelper Uhh = new HouseHelper(); string URoom_id = lvSelectHouse.Items[0].SubItems[0].Text; string R_id2 = Uhh.GetR_id(lvSelectHouse.Items[0].Text); DBHelper Udb = null; string Usql = string.Format("update Guest set AdvanceForegift='{0}' where R_id='{1}'", txtAdvanceForegift.Text, R_id2); Udb = new DBHelper(); Udb.UpdateDeleteAdd(Usql); if (rows > 0) { MessageBox.Show("入住成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("入住失败!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//显示可供房信息 private void ShowOldHouseOne() { cboGuest.Items.Clear(); HouseHelper hh = new HouseHelper(); DBHelper db = null; db = new DBHelper(); try { string sql = string.Format("select R_RoomId from Room where State='{0}'", "待客"); SqlDataReader sdr = db.SelectAll(sql); while (sdr.Read()) { cboGuest.Items.Add(sdr["R_RoomId"].ToString()); } sdr.Close(); db = new DBHelper(); sql = string.Format("select G_GuestId from Guest where R_id='{0}' and Fact='{1}'", hh.GetR_id(cboGuest.Text), ""); SqlDataReader sdr2 = db.SelectAll(sql);; if (sdr2.Read()) { guestIdTwo = sdr["G_GuestId"].ToString(); } sdr2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { db.GetClose(); } }
private void cboUnite_SelectedIndexChanged(object sender, EventArgs e) { DBHelper db = null; HouseHelper hh = new HouseHelper(); db = new DBHelper(); string sql = string.Format("select G_GuestId from Guest where R_id='{0}' and Fact='{1}'", hh.GetR_id(cboUnite.Text), ""); SqlDataReader sdr2 = db.SelectAll(sql); if (sdr2.Read()) { guestIdTwo = sdr2["G_GuestId"].ToString(); } sdr2.Close(); // MessageBox.Show(guestIdTwo); }
//合并 private void Unite() { string roomId; string price; string G_GuestId; DBHelper db = null; HouseHelper hh = new HouseHelper(); AutoId ai = new AutoId(); //自动生成id类 db = new DBHelper(); string sql = ""; //大量申明 string U_UserId = ""; string Uname = ""; string Sex = ""; string CertificateType = ""; string CertificateID = ""; string CertificatePic = ""; string Address = ""; string contactTel = ""; string Underwrite = ""; string comeDate = ""; string Bookleave = ""; string faceDate = ""; string Due = ""; string Fact = ""; string locate = ""; string Operator = UserHelper.LoginId; string remark = ""; string R_id = hh.GetR_id(cboNewHouse.Text); MessageBox.Show(R_id); sql = string.Format("select * from Guest where R_id = '{0}' and faceDate = '{1}' ", R_id, ""); SqlDataReader sdr = db.SelectAll(sql); if (sdr.Read()) { U_UserId = sdr["U_UserId"].ToString(); Uname = sdr["Uname"].ToString(); Sex = sdr["Sex"].ToString(); CertificateType = sdr["CertificateType"].ToString(); CertificateID = sdr["CertificateID"].ToString(); CertificatePic = sdr["CertificatePic"].ToString(); Address = sdr["Address"].ToString(); contactTel = sdr["contactTel"].ToString(); Underwrite = sdr["Underwrite"].ToString(); comeDate = dtpComeDate.Text; Bookleave = dtpBookleave.Text; faceDate = ""; } sdr.Close(); int rows = 0; for (int i = 0; i < lvSelectHouse.Items.Count; i++) { G_GuestId = ai.GetId("G_GuestId", "Guest"); roomId = hh.GetR_id(lvSelectHouse.Items[i].SubItems[0].Text); price = lvSelectHouse.Items[i].SubItems[2].Text; //MessageBox.Show(Uname.ToString()); sql = string.Format("insert into Guest values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}')", G_GuestId, roomId, U_UserId, Uname, Sex, CertificateType, CertificateID, CertificatePic, Address, contactTel, txtAdvanceForegift.Text, Underwrite, comeDate, Bookleave, faceDate, price, Due, Fact, locate, Operator, remark ); rows = db.UpdateDeleteAdd(sql); sql = string.Format("update Room set State='{0}' where R_id='{1}'", "待客", hh.GetR_id(lvSelectHouse.Items[i].SubItems[0].Text)); db.UpdateDeleteAdd(sql); } if (rows > 0) { MessageBox.Show("合并成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("合并失败!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//OK按钮 private void btnTransact_Click(object sender, EventArgs e) { if (!ValidateInput()) { return; } if (lvNeedHouse.Items.Count <= 0) { MessageBox.Show("您没选任何房间!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } HouseHelper hh = new HouseHelper(); AutoId auto = new AutoId(); int count = lvNeedHouse.Items.Count; string room_id; string type; string r_type; double R_price; int rows = 0; DBHelper db = null; try { db = new DBHelper(); if (IsAwoke.foregiftSmall == "1") { double money = 0; for (int i = 0; i < count; i++) { money += Convert.ToDouble(lvNeedHouse.Items[i].SubItems[2].Text); } if (Convert.ToDouble(txtAdvanceForegift.Text) < money && txtCust.Text == "") { MessageBox.Show("押金小于房款!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } for (int i = 0; i < count; i++) { string G_GuestId = auto.GetId("G_GuestId", "Guest"); room_id = lvNeedHouse.Items[i].SubItems[0].Text; type = lvNeedHouse.Items[i].SubItems[1].Text; r_type = lvNeedHouse.Items[i].SubItems[2].Text; R_price = Convert.ToDouble(lvNeedHouse.Items[i].SubItems[2].Text); string R_id = hh.GetR_id(room_id); string cust = txtCust.Text; string Uname = txtName.Text; string sex = rdoMan.Checked ? "南" : "女"; string CertificateType = cboCertificate.Text; string CertificateID = txtCertificateId.Text; string Address = txtAddress.Text; string contactTel = txtContactTel.Text; string AdvanceForegift = txtAdvanceForegift.Text; string Underwrite = ""; string comeDate = dtpComeDate.Text; string Bookleave = dtpBookleave.Text; string faceDate = ""; string Due = ""; string Fact = ""; string locate = ""; string Operator = UserHelper.LoginId; string remark = txtRemark.Text; string sql = string.Format("insert into Guest values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}')", G_GuestId, R_id, cust, Uname, sex, CertificateType, CertificateID, picName, Address, contactTel, 0, Underwrite, comeDate, Bookleave, faceDate, R_price, Due, Fact, locate, Operator, remark ); rows = db.UpdateDeleteAdd(sql); sql = string.Format("update Room set State='{0}', R_Count = R_Count + '{2}' where R_id ='{1}'", "待客", R_id, 1); db.UpdateDeleteAdd(sql); if (cboIsAwoke.Checked) { sql = string.Format("insert into Awoke values('{0}','{1}','{2}','{3}','{4}')", auto.GetId("A_AwokeId", "Awoke"), lvNeedHouse.Items[i].SubItems[0].Text + "号房到期", "未读", dtpBookleave.Text, txtRemark.Text ); db.UpdateDeleteAdd(sql); } } HouseHelper Uhh = new HouseHelper(); string URoom_id = txtMainHouse.Text; string UR_id = lvNeedHouse.Items[0].Tag.ToString(); DBHelper Udb = null; string Usql = string.Format("update Guest set AdvanceForegift='{0}' where R_id='{1}'", txtAdvanceForegift.Text, UR_id); Udb = new DBHelper(); Udb.UpdateDeleteAdd(Usql); if (rows > 0) { MessageBox.Show("入住成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { db.GetClose(); } }