protected void BtnSave_Click(object sender, EventArgs e) { try { DataContextDataContext Dtx = new DataContextDataContext(); Booking Bk = new Booking(); Bk.reservationDate = Convert.ToDateTime(Session["IdDtBooking"]); Bk.customer_notes = TxtNotes.Text; Bk.id_customer = Convert.ToInt32(Session["loginidct"]); Bk.id_vehicle = Convert.ToInt32(DropDwVehicle.SelectedValue); Bk.id_service = Convert.ToInt32(DropDwServiceType.SelectedValue); Bk.id_time = Convert.ToInt32(Session["IdTmBooking"]); Bk.licence = TxtLicense.Text; Bk.id_status = 1; Dtx.Bookings.InsertOnSubmit(Bk); Dtx.SubmitChanges(); LblMsg.Visible = true; LblMsg.Text = "Successful booking"; } catch (Exception ex) { LblMsg.Visible = true; LblMsg.Text = "Please, try again. " + Environment.NewLine + ex.Message; } Response.Redirect("~/Views/CustomerHome.aspx"); }
public JsonResult GetCity(int Sid) { DataContextDataContext cd = new DataContextDataContext(); var data = from m in cd.CityTBs where m.StateId == Sid select new { CityId = m.CityId, CityName = m.CityName }; return(Json(new { Result = data }, JsonRequestBehavior.AllowGet)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { //if (Session["loginidct"] == null) if (Models.ValidationUser.isValidAcess(Convert.ToString(Session["loginidct"])) == false) { Response.Redirect(@"\Views\LoginUser.aspx"); } LblDtBook.Text = Convert.ToString(Session["IdDtBooking"]); LblTmBook.Text = Convert.ToString(Session["IdTmBooking"]); DataContextDataContext Dtx = new DataContextDataContext(); var Vehicle = from v in Dtx.Vehicles select v; DropDwVehicle.DataSource = Vehicle; DropDwVehicle.DataValueField = "id_vehicle"; DropDwVehicle.DataTextField = "model"; DropDwVehicle.DataBind(); var SvcType = from s in Dtx.Service_Types select s; DropDwServiceType.DataSource = SvcType; DropDwServiceType.DataValueField = "id_service"; DropDwServiceType.DataTextField = "service_type1"; DropDwServiceType.DataBind(); } catch (Exception) { Response.Redirect(@"\Views\LoginUser.aspx"); } } }
public CauHoi GetOneCauHoi(int MaCauHoi) { /* * Kiếm câu hỏi thông qua mã câu hỏi * Nếu không tìm thấy mã câu hỏi -> trả về null * Nếu tìm thấy câu hỏi -> trả về câu hỏi */ using (DataContextDataContext DB = new DataContextDataContext()) { CauHoi cauHoi = new CauHoi(); var findCauHoi = from cau in DB.CauHois where cau.MaCauHoi == MaCauHoi select cau; if (findCauHoi.Count() == 0) { return(null); } foreach (var mem in findCauHoi) { cauHoi.MaCauHoi = mem.MaCauHoi; cauHoi.CauA = mem.CauA; cauHoi.CauB = mem.CauB; cauHoi.CauC = mem.CauC; cauHoi.CauD = mem.CauD; cauHoi.CauDung = mem.CauDung; cauHoi.DoKho1 = mem.DoKho1; cauHoi.Khoi = mem.Khoi; cauHoi.NoiDung = mem.NoiDung; } return(cauHoi); } }
public bool DeleteDeOnTapOnMaDeThi(string MaDe) { /* * Xóa đề ôn tập dựa trên mã đề * Nếu mã đề không tồn tại -> trả về false * Nếu mã đề tồn tại và xóa thành công thì trả về true */ using (DataContextDataContext DB = new DataContextDataContext()) { var findMaDeONDeOnTap = from MADEONDEONTAP in DB.DeOnTaps where MADEONDEONTAP.MaDe == MaDe select MADEONDEONTAP; if (findMaDeONDeOnTap.Count() == 0) { return(false); } foreach (var men in findMaDeONDeOnTap) { DB.DeOnTaps.DeleteOnSubmit(men); } DB.SubmitChanges(); return(true); } }
public DeOnTap FindOneDeOnTapONMaHocSinhANDMaDeANDMaKhoi(string MaHocSinh, int MaKhoi, string MaDe) { /* * Tìm 1 dề ôn tập dựa trên mã học sinh và mã đề và mã khối * Nếu không tồn tại mã khối , mã học sinh , mã đề trong DeOnTap -> trả về null * Nếu tồn tại thì trả đề ôn tâp */ using (DataContextDataContext DB = new DataContextDataContext()) { DeOnTap deOnTap = new DeOnTap(); var findOneDeOnTapONMaHocSinhANDMaDeANDMaKhoi = from HSonDEONTAP in DB.DeOnTaps where HSonDEONTAP.MaHocSinh == MaHocSinh && HSonDEONTAP.MaKhoi == MaKhoi && HSonDEONTAP.MaDe == MaDe select HSonDEONTAP; if (findOneDeOnTapONMaHocSinhANDMaDeANDMaKhoi.Count() == 0) { return(null); } foreach (var men in findOneDeOnTapONMaHocSinhANDMaDeANDMaKhoi) { deOnTap.MaDe = men.MaDe; deOnTap.MaHocSinh = men.MaHocSinh; deOnTap.MaKhoi = men.MaKhoi; deOnTap.Diem = men.Diem; deOnTap.NgayGioiHan = men.NgayGioiHan; } return(deOnTap); } }
public bool UpdateGiaoVienOnPassword(string MaGV, string Password) { /* * Update password in giáo viên thông ma MaGV * Nếu không tìm thấy MaGV -> trả về false * Nếu tìm thấy MaGV -> thay đổi Password -> thay đổi thành công -> trả về true */ using (DataContextDataContext DB = new DataContextDataContext()) { int FindMaGVOnGiaoVien = (from giaovien in DB.GiaoViens where giaovien.MaGiaVien == MaGV select giaovien).Count(); if (FindMaGVOnGiaoVien == 0) { return(false); } var FindGiaoVien = from giaovien in DB.GiaoViens where giaovien.MaGiaVien == MaGV select giaovien; foreach (var Temp in FindGiaoVien) { Temp.Password = Password; } DB.SubmitChanges(); return(true); } }
public int UpdateDoKhoOnMaDeAndMaKhoi(string MaDe, int MaKhoi, string DoKho) { /* * Update độ khó của mã đề và mã khối * Nếu không tìm thấy MaDe và Mã khối -> trả về 1 * Nếu độ khó khác dễ hoặc vừa hoặc khó -> trả về 2 * Update thành công thì trả -> trả về 0 */ using (DataContextDataContext DB = new DataContextDataContext()) { var findOneDeOnMaDeAndMaKhoi = from D in DB.Des where D.MaDe == MaDe && D.MaKhoi == MaKhoi select D; if (findOneDeOnMaDeAndMaKhoi.Count() == 0) { return(1); } if (DoKho != "dễ" && DoKho != "trung bình" && DoKho != "khó") { return(2); } foreach (var mem in findOneDeOnMaDeAndMaKhoi) { mem.DoKho = DoKho; } DB.SubmitChanges(); return(0); } }
public bool DeleteGiaoVienOnMaGV(string MaGV) { /* * Xóa giáo viên thông qua mã giáo viên * Nếu tìm thấy , xóa thành công -> trả về true * Nếu không tìm thấy -> trả về false */ using (DataContextDataContext DB = new DataContextDataContext()) { var KiemTraGiaoVienCoTonTaiHayKhong = from giaovien in DB.GiaoViens where giaovien.MaGiaVien == MaGV select giaovien; if (KiemTraGiaoVienCoTonTaiHayKhong.Count() == 0) { return(false); } foreach (var men in KiemTraGiaoVienCoTonTaiHayKhong) { DB.GiaoViens.DeleteOnSubmit(men); } DB.SubmitChanges(); return(true); } }
public bool UpdateGiaoVienOnDiaChi(string MaGV, string DiaChi) { /* * Update địa chỉ của giáo viên * Nếu không tồn tại MaGV -> trả về false * Nếu tồn tại MaGV -> update địa chỉ thành công -> trả về true */ using (DataContextDataContext DB = new DataContextDataContext()) { int FindMaGVOnGiaoVien = (from giaovien in DB.GiaoViens where giaovien.MaGiaVien == MaGV select MaGV).Count(); if (FindMaGVOnGiaoVien == 0) { return(false); } var FindGiaoVien = from giaovien in DB.GiaoViens where giaovien.MaGiaVien == MaGV select giaovien; foreach (var giaovien in FindGiaoVien) { giaovien.DiaChi = DiaChi; } DB.SubmitChanges(); return(true); } }
public GiaoVien FindGiaoVienOnEmailAndPassword(string Email, string Password) { /* * Tìm giáo viên thông qua Email và Password * Nếu không tìm thấy -> trả về null * Nếu tìm thấy -> trả về GiaoVien */ using (DataContextDataContext DB = new DataContextDataContext()) { GiaoVien GiaoVienOne = new GiaoVien(); var GiaoViens = from giaovien in DB.GiaoViens where giaovien.Email == Email && giaovien.Password == Password select giaovien; if (GiaoViens.Count() == 0) { return(null); } foreach (var temp in GiaoViens) { GiaoVienOne.MaGiaVien = temp.MaGiaVien; GiaoVienOne.DiaChi = temp.DiaChi; GiaoVienOne.Email = temp.Email; GiaoVienOne.HoTen = temp.HoTen; GiaoVienOne.MaKhoi = temp.MaKhoi; GiaoVienOne.Password = temp.Password; GiaoVienOne.SDT = temp.SDT; break; } return(GiaoVienOne); } }
public List <GiaoVien> FindAllGiaoVien() { /* * Tìm tất cả các giáo viên * Nếu không có giáo viên nào thì trả về null * Nếu có thì trả về giáo viên */ using (DataContextDataContext DB = new DataContextDataContext()) { List <GiaoVien> giaoViens = new List <GiaoVien>(); var FindAddGiaoVienTemp = from giaovien in DB.GiaoViens select giaovien; if (FindAddGiaoVienTemp.Count() == 0) { return(null); } foreach (var temp in FindAddGiaoVienTemp) { giaoViens.Add(temp); } return(giaoViens); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["user"] == null) { signUpBtnMain.Visible = true; loginBtnMain.Visible = true; logoutBtnMain.Visible = false; lblWelcomeMsg.Visible = false; } else { signUpBtnMain.Visible = false; loginBtnMain.Visible = false; logoutBtnMain.Visible = true; lblWelcomeMsg.Visible = true; } if (!IsPostBack) { if (Session["user"] != null) { DataContextDataContext objDataContext = new DataContextDataContext(); CustomerTable objCustomer = objDataContext.CustomerTables.Single(cus => cus.CustomerEmail == Session["user"]); string cusName = objCustomer.CustomerName; lblWelcomeMsg.Text = "Welcome back, " + cusName + "!"; } } }
private void button1_Click(object sender, EventArgs e) { using (DataContextDataContext DB = new DataContextDataContext()) { DAO.HT.CauHoiDAO cauHoiDAO = new CauHoiDAO(); if (String.IsNullOrEmpty(txtFileName.Text) == true) { MessageBox.Show("File trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (String.IsNullOrEmpty(comboBox1.Text) == true) { MessageBox.Show("sheet trông", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (var mem in cauHois) { if (cauHoiDAO.getCauHoiOnCauHoi(mem.NoiDung) == true) { MessageBox.Show("Câu hỏi có nội dung là :" + mem.NoiDung + " . Đã là tồn tại trong csdl ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); continue; } DB.CauHois.InsertOnSubmit(mem); } DB.SubmitChanges(); MessageBox.Show("Thành công", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public int UpdateGiaoVienOnSDT(string MaGV, string SDT) { /* * Update số điện thoại của giáo viên * Nếu MaGV không tồn tại , trả về 1 * Nếu tìm thấy SDT trùng với 1 giáo viên khác , trả về 2 * Update thành công , trả về 0 */ using (DataContextDataContext DB = new DataContextDataContext()) { var FindMaGVGiaoVien = from giaovien in DB.GiaoViens where giaovien.MaGiaVien == MaGV select giaovien; if (FindMaGVGiaoVien.Count() == 0) { return(1); } int FindSDTGiaoVien = (from giaovien in DB.GiaoViens where giaovien.MaGiaVien != MaGV && giaovien.SDT == SDT select giaovien).Count(); if (FindSDTGiaoVien != 0) { return(2); } foreach (var men in FindMaGVGiaoVien) { men.SDT = SDT; } DB.SubmitChanges(); return(0); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["user"] == null) { string OriginalUrl = HttpContext.Current.Request.RawUrl; string LoginPageUrl = "CustomerLogin.aspx"; HttpContext.Current.Response.Redirect(String.Format("{0}?ReturnUrl={1}", LoginPageUrl, OriginalUrl)); } calculateSum(); if (PriceInTotal.Text == "0") { Label1.Visible = true; } else if (PriceInTotal.Text != "0") { Label2.Visible = true; PriceInTotal.Visible = true; Button1.Visible = true; } if (!IsPostBack) { if (Session["user"] == null) { Response.Redirect("CustomerLogin.aspx"); } else { using (DataContextDataContext objDataContext = new DataContextDataContext()) { CustomerTable objCustomer = objDataContext.CustomerTables.Single(cus => cus.CustomerEmail == Session["user"]); } } } }
public int UpdateGiaoVienOnMaKhoi(string MaGV, int MaKhoi) { /* * Update Giao Viên với mã khối * Nếu không tìm thấy MaGV -> trả về 1 * Nếu không tìm thấy MaKhoi -> trả về 2 * Update thanh công -> trả về 3 */ using (DataContextDataContext DB = new DataContextDataContext()) { var FindMaGVGiaoVien = from giaovien in DB.GiaoViens where giaovien.MaGiaVien == MaGV select giaovien; if (FindMaGVGiaoVien.Count() == 0) { return(1); } int FindMaKhoi = (from khoi in DB.Khois where khoi.MaKhoi == MaKhoi select khoi).Count(); if (FindMaKhoi == 0) { return(2); } foreach (var men in FindMaGVGiaoVien) { men.MaKhoi = MaKhoi; } DB.SubmitChanges(); return(0); } }
public int UpdateTenDeOnMaDeAndMaKhoi(string MaDe, int MaKhoi, string TenDe) { using (DataContextDataContext DB = new DataContextDataContext()) { /* * Update tên đề dựa trên mã đề và mã khối * Nếu không tìm thấy mã đề và mã khối trong csdl -> trả về 1 * Nếu tìm thấy và update thành công -> trả về 0 */ var findOneTenDeOnMaDeAndMaKhoi = from D in DB.Des where D.MaDe == MaDe && D.MaKhoi == MaKhoi select D; if (findOneTenDeOnMaDeAndMaKhoi.Count() == 0) { return(1); } foreach (var mem in findOneTenDeOnMaDeAndMaKhoi) { mem.TenDe = TenDe; } DB.SubmitChanges(); return(0); } }
public GiaoVien FindOneGiaoVienOnEmail(string Email) { /* * Tìm giáo viên thông qua Email * Nếu không tìm thấy -> trả về null * Nếu tìm thấy -> trả về giáo viên */ using (DataContextDataContext DB = new DataContextDataContext()) { GiaoVien giaoVien = new GiaoVien(); var findOne = from giaovien in DB.GiaoViens where giaovien.Email == Email select giaovien; if (findOne.Count() == 0) { return(null); } foreach (var temp in findOne) { giaoVien.MaGiaVien = temp.MaGiaVien; giaoVien.DiaChi = temp.DiaChi; giaoVien.Email = temp.Email; giaoVien.HoTen = temp.HoTen; giaoVien.MaKhoi = temp.MaKhoi; giaoVien.Password = temp.Password; giaoVien.SDT = temp.SDT; } return(giaoVien); } }
public bool DeleteDeOnTapOnMaHocSinh(string MaHocSinh, string MaDe) { /* * Xóa đề on tập trên bảng ôn tập * Nếu không tìm thấy Ma Hoc Sinh và Ma De -> thì trả về false * Nếu tìm thấy và xóa thành công -> thì trả về true */ using (DataContextDataContext DB = new DataContextDataContext()) { var findMaHocSinhANDMaDe = from DE in DB.DeOnTaps where DE.MaDe == MaDe && DE.MaHocSinh == MaHocSinh select DE; if (findMaHocSinhANDMaDe.Count() == 0) { return(false); } foreach (var men in findMaHocSinhANDMaDe) { DB.DeOnTaps.DeleteOnSubmit(men); } DB.SubmitChanges(); return(true); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["user"] == null) { string OriginalUrl = HttpContext.Current.Request.RawUrl; string LoginPageUrl = "CustomerLogin.aspx"; HttpContext.Current.Response.Redirect(String.Format("{0}?ReturnUrl={1}", LoginPageUrl, OriginalUrl)); } if (!IsPostBack) { DataContextDataContext objDataContext = new DataContextDataContext(); CustomerTable objCustomer = objDataContext.CustomerTables.Single(cus => cus.CustomerEmail == Session["user"]); string customerEmail = objCustomer.CustomerEmail; DataContextDataContext db = new DataContextDataContext(); var queryWishList = from p in db.WishLists join o in db.ArtistUploads on p.productID equals o.productID join s in db.ArtistTables on o.authorEmail equals s.authorEmail where p.customerEmail == customerEmail && o.authorEmail == s.authorEmail select new { p.productID, p.wishListID, p.unitPrice, o.description, p.quantity, p.customerEmail, o.productname, o.artImage, o.authorEmail, s.authorName }; DataList1.DataSource = queryWishList; DataList1.DataBind(); if (DataList1.Items.Count == 0) { emptyWishListMessage.Text = "<br />" + "<h3>" + "You currently do not have any products in this wish list, kindly click " + "<a href=\"CustomerBrowse.aspx\">here</a>" + " to start browsing and add items into your wish list!" + "</h3>" + "<br />"; emptyWishListMessage.Visible = true; } } }
public string getNameKhoi(int MaKhoi) { /* * Tìm kiếm tên của khối thông qua mã khối * Nếu không tìm thấy trả về null * Nếu tìm thấy trả về tên của khoi */ using (DataContextDataContext DB = new DataContextDataContext()) { string nameKhoi = null; var khoiName = from khoi in DB.Khois where khoi.MaKhoi == MaKhoi select khoi; if (khoiName.Count() == 0) { return(null); } foreach (var khoi in khoiName) { nameKhoi = khoi.TenKhoi; } return(nameKhoi); } }
protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e) { // Get product ID string prodID = ""; Label tempProdID = DataList1.Items[e.Item.ItemIndex].FindControl("productId2") as Label; prodID = tempProdID.Text; // Check if the product is in the Customer's "Wish List" and "Shopping Cart" // If yes, delete those items, then only remove this from Seller Upload Table DataContextDataContext dbRemoveWishList = new DataContextDataContext(); var checkInWishList = (from p in dbRemoveWishList.WishLists where p.productID == int.Parse(prodID) select p).ToList(); dbRemoveWishList.WishLists.DeleteAllOnSubmit(checkInWishList.ToList()); dbRemoveWishList.SubmitChanges(); DataContextDataContext dbRemoveCart = new DataContextDataContext(); var checkInShoppingCart = (from p in dbRemoveCart.ShoppingCarts where p.productID == int.Parse(prodID) select p).ToList(); dbRemoveCart.ShoppingCarts.DeleteAllOnSubmit(checkInShoppingCart.ToList()); dbRemoveCart.SubmitChanges(); DataContextDataContext db = new DataContextDataContext(); ArtistUpload currentArtistUpload = db.ArtistUploads.Single(pId => pId.productID == int.Parse(prodID)); db.ArtistUploads.DeleteOnSubmit(currentArtistUpload); db.SubmitChanges(); BindUploadProduct(); }
public List <CauHoiGiaoVien> getAllCauHoi() { /* * Lấy ra danh sách câu hỏi trả về list */ using (DataContextDataContext DB = new DataContextDataContext()) { List <CauHoiGiaoVien> cauHois = new List <CauHoiGiaoVien>(); var cauhois = from cauHoi in DB.CauHois where cauHoi.HocSinhDongGop == false select cauHoi; foreach (var cauhoi in cauhois) { CauHoiGiaoVien temp = new CauHoiGiaoVien(); temp.MaCauHoi = cauhoi.MaCauHoi; temp.NoiDung = cauhoi.NoiDung; temp.CauA = cauhoi.CauA; temp.CauB = cauhoi.CauB; temp.CauC = cauhoi.CauC; temp.CauD = cauhoi.CauD; temp.CauDung = cauhoi.CauDung; temp.DoKhoTen = cauhoi.DoKho1.TenDoKho; temp.TenKhoi = cauhoi.Khoi.TenKhoi; cauHois.Add(temp); } return(cauHois); } }
//Function: initialize a concrete user, return it as use of this session, if the user is valid //Paramaters: //Return: concrete user type, (Customer or Manager) // null when the user is invalid //用户身份验证,根据名字密码查数据库,合法的话,返回出manager或者customer //不合法返回NUll public static User Login(string pName, string pPwd) { User user = null; DataContextDataContext dc = new DataContextDataContext(); bool? isValid = false; ISingleResult<is_valid_userResult> rs = dc.is_valid_user(pName, pPwd, ref isValid); if (isValid == true) { foreach (is_valid_userResult s in rs) { if (s.type == 1) { user = new Customer(s.name, s.pwd, s.mail); } else if (s.type == 2) { user = new Manager(s.name, s.pwd, s.mail); } else { } } } else //invalid {} return user; }
public List <CauHoi> getAllCauHoiCauHoiOnMaKhoi(int MaKhoi) { /* * Lấy ra danh sách câu hỏi trả về list */ using (DataContextDataContext DB = new DataContextDataContext()) { List <CauHoi> cauHois = new List <CauHoi>(); var cauhois = from cauHoi in DB.CauHois where cauHoi.HocSinhDongGop == false && cauHoi.MaKhoi == MaKhoi select cauHoi; foreach (var cauhoi in cauhois) { CauHoi temp = new CauHoi(); temp.MaCauHoi = cauhoi.MaCauHoi; temp.NoiDung = cauhoi.NoiDung; temp.CauA = cauhoi.CauA; temp.CauB = cauhoi.CauB; temp.CauC = cauhoi.CauC; temp.CauD = cauhoi.CauD; temp.CauDung = cauhoi.CauDung; temp.DoKho1 = cauhoi.DoKho1; temp.Khoi = cauhoi.Khoi; cauHois.Add(temp); } return(cauHois); } }
public De getOneDeOnMaDe(string MaDe) { /* * Tìm đề thông qua mã đề * Nếu không tìm thấy -> trả về null * Nếu tìm thấy -> trả về đề */ using (DataContextDataContext DB = new DataContextDataContext()) { De de = new De(); var findOneDeONMaDe = from D in DB.Des where D.MaDe == MaDe select D; if (findOneDeONMaDe.Count() == 0) { return(null); } foreach (var mem in findOneDeONMaDe) { de.MaDe = mem.MaDe; de.TenDe = mem.TenDe; de.MaKhoi = mem.MaKhoi; de.DoKho = mem.DoKho; } return(de); } }
public JsonResult GetState(int cid) { DataContextDataContext cd = new DataContextDataContext(); var data = from m in cd.StateTBs where m.CountryId == cid select new { StateId = m.StateId, StateName = m.StateName }; return(Json(new { Result = data }, JsonRequestBehavior.AllowGet)); }
public int UpdateMaKhoiOnMaKhoiAndMaDe(string MaDe, int MaKhoiTruocUpdate, int MaKhoiSauUpdate) { /* * Tìm và update mã khối sau khi update , * Nếu không tìm thấy mã đề và khối trong BangDe thì -> trả về 1 * Nếu mã khối không update không tìm thấy trong khối -> trả về 2 * Update thành công -> trả về 3 */ using (DataContextDataContext DB = new DataContextDataContext()) { var findMaKhoiSaoKhiUpdate = from KH in DB.Khois where KH.MaKhoi == MaKhoiSauUpdate select KH; if (findMaKhoiSaoKhiUpdate.Count() == 0) { return(2); } var findDeTruocKhiUpdate = from KH in DB.Des where KH.MaDe == MaDe && KH.MaKhoi == MaKhoiTruocUpdate select KH; if (findDeTruocKhiUpdate.Count() == 0) { return(1); } foreach (var mem in findDeTruocKhiUpdate) { mem.MaKhoi = MaKhoiSauUpdate; } DB.SubmitChanges(); return(0); } }
public DeVaCauHoiOnMaDeDTO getAllCauHoiTrongDe(string MaDe, int MaKhoi) { /* * Tìm Câu hỏi trong đề nào * Nếu không tìm tấy Mã đề và mã khối trong CSDL -> trả về null * Nếu tìm thấy -> trả về Mã đề + List cau hỏi */ using (DataContextDataContext DB = new DataContextDataContext()) { DeVaCauHoiOnMaDeDTO getAllCauHoiOnMaDe = new DeVaCauHoiOnMaDeDTO(); var findMaDe = from D in DB.CauHoiTrongDeNaos where D.MaDe == MaDe && D.MaKhoi == MaKhoi select D; if (findMaDe.Count() == 0) { return(null); } int tempCount = 0; foreach (var mem in findMaDe) { if (tempCount == 0) { getAllCauHoiOnMaDe.MaDe = mem.MaDe; getAllCauHoiOnMaDe.MaKhoi = mem.MaKhoi; tempCount++; } getAllCauHoiOnMaDe.listCauHoiOnMaDe.Add(mem.CauHoi); } return(getAllCauHoiOnMaDe); } }
public Khoi FindKhoiOnMaKhoi(int MaKhoi) { /* * tìm khối trả về khoi * nếu không tìm thấy -> trả về null * Nếu tìm thấy trả về khoi */ using (DataContextDataContext DB = new DataContextDataContext()) { Khoi khoiOne = new Khoi(); var khois = from khoi in DB.Khois where khoi.MaKhoi == MaKhoi select khoi; if (khois.Count() == 0) { return(null); } foreach (var khoi in khois) { khoiOne = khoi; } return(khoiOne); } }
public void ChageState(TableState pState) { state = pState; hide = pState.ToString(); //~ synchronize to db, if need to maintain the state in db DataContextDataContext dc = new DataContextDataContext(); dc.update_state_table(id, (int?)state); }
//Function: initiate all the tables with states, by querying the db ////从数据库把桌子信息读出来,带着当前的状态 public static void InitAllTable() { tableList = new List<SysTable>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<select_all_tableResult> rs = dc.select_all_table(); foreach (select_all_tableResult r in rs) { Reservation reservation = null; ISingleResult<get_current_reservation_by_tableResult> rs2 = dc.get_current_reservation_by_table(r.name); foreach (get_current_reservation_by_tableResult r2 in rs2) { List<DishQuota> dishQuotaList = new List<DishQuota>(); ISingleResult<get_dishquota_by_reservationResult> rs3 = dc.get_dishquota_by_reservation(r2.id); foreach (get_dishquota_by_reservationResult r3 in rs3) { double price = 0; ISingleResult<get_dish_by_nameResult> rs4 = dc.get_dish_by_name(r3.dish_name); foreach (get_dish_by_nameResult r4 in rs4) { price = (double)r4.price; } DishQuota dishQuota = new DishQuota((Guid)r3.id, r3.dish_name, price, (int)r3.quato, r3.note); dishQuotaList.Add(dishQuota); } reservation = new Reservation( r2.id, r2.user_from, r2.customer_name, r2.phone, (DateTime)r2.arrive_time, r2.table_name, (int)r2.seat, (ReservationType)r2.type, (ReservationState)r2.state, dishQuotaList); } //only one reservation is bound to a table in a certain time // in exact this foreach loop, not outside SysTable table = new SysTable( (Guid)r.id, r.name, (int)r.seat, r.pict_path, (TableState)r.current_state ); table.SetReservation(reservation); tableList.Add(table); } }
public static Dictionary<string, DateTime> GetBusinessTime() { Dictionary<string, DateTime> dictionary = new Dictionary<string, DateTime>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<select_all_businesstimeResult> rs = dc.select_all_businesstime(); foreach (select_all_businesstimeResult r in rs) { dictionary.Add(r.keyword, r.time); } return dictionary; }
//Function: check all the AVAILABLE reservations in db, and find out in the span of current time which table is reserved // set certain reservations and tables involed as RESERVED //Remarks: be involved periodically and automaticlly by a timer // this is the begining of all the state transfer of tables and reservations in memory //$调用存储过程,查数据库里的reservation,比对现在时间和reservation预定时间的关系,确定哪些订单进入到reserved状态了 public static void CheckTableReserved() { DataContextDataContext dc = new DataContextDataContext(); //装数据库返回的数据集合 ISingleResult<get_reserved_tablename_and_reservationResult> rs = dc.get_reserved_tablename_and_reservation(DateTime.Now); foreach (get_reserved_tablename_and_reservationResult r in rs) { //装reservation的很多dish List<DishQuota> dishQuotaList = new List<DishQuota>(); //in fact no dish, if dishes is not allowed to order before custom comming //ISingleResult<get_dishquota_by_reservationResult> rs2 = dc.get_dishquota_by_reservation(r.id); //foreach (get_dishquota_by_reservationResult r2 in rs2) //{ // double price = 0; // ISingleResult<get_dish_by_nameResult> rs3 = dc.get_dish_by_name(r2.dish_name); // foreach (get_dish_by_nameResult r3 in rs3) // { // price = (double)r3.price; // } // DishQuota dishQuota = new DishQuota(r2.id, r2.dish_name, price, (int)r2.quato, r2.note); // dishQuotaList.Add(dishQuota); //} //从数据集的一条记录组装一个reservation Reservation reservation = new Reservation( r.id, r.user_from, r.customer_name, r.phone, (DateTime)r.arrive_time, r.table_name, (int)r.seat, (ReservationType)r.type, (ReservationState)r.state, dishQuotaList); foreach (SysTable t in Restaurant.tableList) { //如果内存中的table是还没被约定的,占用的,这条reservation预定的就是这张桌子,吧这张桌子预定到这张桌子 if (t.name == reservation.tableName && (t.state != TableState.BUSY && t.state != TableState.TIMEOUT)) { t.SetReservation(reservation); //reservation 绑定到桌子 t.ChageState(TableState.RESERVED); //桌子状态reserved } else { } } } }
public static List<Tag> GetHotTag() { List<Tag> tagList = new List<Tag>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<get_hot_tagResult> rs2 = dc.get_hot_tag(); foreach (get_hot_tagResult r2 in rs2) { Tag tag = new Tag(r2.name, (int)r2.popularity); tagList.Add(tag); } return tagList; }
public List<string> GetAvailableTableName(DateTime pDateTime) { List<string> tableNameList = new List<string>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<get_available_tableResult> rs = dc.get_available_table(pDateTime); foreach (get_available_tableResult r in rs) { tableNameList.Add(r.name); } return tableNameList; }
public static void CommitReservation(Reservation pR) { DataContextDataContext dc = new DataContextDataContext(); //$dc.ins dc.insert_reservation( (Guid?)pR.id, pR.userFrom, pR.customerName, pR.phone, (DateTime?)pR.arriveTime, pR.tableName, (int?)pR.seat, (int?)pR.state); }
//Function: add a new table to the system public bool AddTable(SysTable pTable) { bool isInsert = false; try { DataContextDataContext dc = new DataContextDataContext(); dc.insert_table(pTable.id, pTable.name, pTable.seat, pTable.pictPath, (int?)pTable.state); isInsert = true; } catch (Exception ex) { } return isInsert; }
public News(Guid pId, string pTitle, string pContent, DateTime pPublishTime, string pAboutDish) { id = pId; title = pTitle; content = pContent; publishTime = pPublishTime; aboutDish = pAboutDish; DataContextDataContext dc = new DataContextDataContext(); ISingleResult<get_dish_by_nameResult> rs2 = dc.get_dish_by_name(aboutDish); foreach (get_dish_by_nameResult r2 in rs2) { pictPath = r2.pict_path; } }
//when a Delivery is committed, the dishes in the delivery is commiteed to db at one time public void CommitDelivery(Delivery pD) { DataContextDataContext dc = new DataContextDataContext(); dc.insert_delivery( (Guid?)pD.id, pD.userFrom, pD.customerName, pD.phone, pD.address, (DateTime?)pD.commitTime, (DateTime?)pD.deliveryTime ); foreach (DishQuota dq in pD.dishQuotaList) { dc.insert_delivery_dish((Guid?)dq.id, pD.id, dq.dishName, (int?)dq.quota, dq.note); } }
//Function: add a new dish to the system public bool AddDish(Dish pDish) { bool isInsert = false; try { DataContextDataContext dc = new DataContextDataContext(); dc.insert_dish(pDish.name, pDish.description, pDish.price, pDish.pictPath, pDish.popularity); isInsert = true; foreach (Tag t in pDish.tagList) { dc.update_tag_pupularity_or_insert(t.name); dc.insert_taganddish(t.name, pDish.name); } } catch (Exception ex) { } return isInsert; }
public static Admin Login(string pName, string pPwd) { Admin admin = null; bool? isAdmin = false; DataContextDataContext dc = new DataContextDataContext(); ISingleResult<is_adminResult> rs = dc.is_admin(pName, pPwd, ref isAdmin); if (isAdmin == true) { foreach (is_adminResult r in rs) { admin = new Admin(r.name, r.pwd, r.mail); } } else { } return admin; }
public static List<Delivery> GetAllHistoryDelivery() { List<Delivery> deliveryList = new List<Delivery>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<select_all_history_deliveryResult> rs = dc.select_all_history_delivery(); foreach (select_all_history_deliveryResult r in rs) { List<DishQuota> dishQuotaLish = new List<DishQuota>(); ISingleResult<get_dishquota_by_deliveryResult> rs2 = dc.get_dishquota_by_delivery(r.id); foreach (get_dishquota_by_deliveryResult r2 in rs2) { double price = 0; ISingleResult<get_dish_by_nameResult> rs3 = dc.get_dish_by_name(r2.dish_name); foreach (get_dish_by_nameResult r3 in rs3) { price = (double)r3.price; } DishQuota dishQuota = new DishQuota(r2.id, r2.dish_name, price, (int)r2.quota, r2.note); dishQuotaLish.Add(dishQuota); } Delivery delivery = new Delivery( (Guid)r.id, r.user_from, r.customer_name, r.phone, r.address, (DateTime)r.commit_time, (DateTime)r.delivery_time, (DeliveryState)r.state, dishQuotaLish); deliveryList.Add(delivery); } return deliveryList; }
public static List<Reservation> GetAllHistoryReservation() { List<Reservation> reservationList = new List<Reservation>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<select_all_history_reservationResult> rs = dc.select_all_history_reservation(); foreach (select_all_history_reservationResult r in rs) { List<DishQuota> dishQuotaList = new List<DishQuota>(); ISingleResult<get_dishquota_by_reservationResult> rs2 = dc.get_dishquota_by_reservation(r.id); foreach (get_dishquota_by_reservationResult r2 in rs2) { double price = 0; ISingleResult<get_dish_by_nameResult> rs3 = dc.get_dish_by_name(r2.dish_name); foreach (get_dish_by_nameResult r3 in rs3) { price = (double)r3.price; } DishQuota dishQuota = new DishQuota(r2.id, r2.dish_name, price, (int)r2.quato, r2.note); dishQuotaList.Add(dishQuota); } Reservation reservation = new Reservation( r.id, r.user_from, r.customer_name, r.phone, (DateTime)r.arrive_time, r.table_name, (int)r.seat, (ReservationType)r.type, (ReservationState)r.state, dishQuotaList); reservationList.Add(reservation); } return reservationList; }
public string[] SearchUnfinishedReservationAutoComplete(string prefixText, int count) { List<string> tempStrList = new List<string>(); string[] nameArray = new string[10]; DataContextDataContext dc = new DataContextDataContext(); ISingleResult<search_reservation_autocompleteResult> rs = dc.search_reservation_autocomplete(prefixText); foreach (search_reservation_autocompleteResult r in rs) { tempStrList.Add(r.customer_name); } int num = tempStrList.Count<string>(); string[] final = new string[num]; for (int i = 0; i <= num - 1; i++) { final[i] = tempStrList.ElementAt(i); } return final; }
public string[] LoginAutoCommplete(string prefixText, int count) { List<string> tempStrList = new List<string>(); string[] nameArray = new string[10]; DataContextDataContext dc = new DataContextDataContext(); ISingleResult<login_autocompleteResult> rs = dc.login_autocomplete(prefixText); foreach (login_autocompleteResult r in rs) { tempStrList.Add(r.name); } int num = tempStrList.Count<string>(); string[] final = new string[num]; for (int i = 0; i <= num - 1; i++) { final[i] = tempStrList.ElementAt(i); } return final; }
//List<Reservation> timeoutReservationList = new List<Reservation>(); //List<Delivery> timeoutDelivery = new List<Delivery>(); //Function: initiate the all the dishes, by query the configure information in db //从数据库吧dish信息读出来,dish是Admin通过adddish加的 public static void InitAllDish() { dishList = new List<Dish>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<select_all_dishResult> rs = dc.select_all_dish(); foreach (select_all_dishResult r in rs) { List<Tag> tagList = new List<Tag>(); List<Comment> commentList = new List<Comment>(); ISingleResult<get_tag_by_dishResult> rs2 = dc.get_tag_by_dish(r.name); foreach (get_tag_by_dishResult r2 in rs2) { Tag tag = new Tag(r2.name, (int)r2.popularity); tagList.Add(tag); } ISingleResult<get_comment_by_dishResult> rs3 = dc.get_comment_by_dish(r.name); foreach (get_comment_by_dishResult r3 in rs3) { Comment comment = new Comment(r3.id,r3.content,r3.about_dish,r3.user_from); commentList.Add(comment); } Dish dish = new Dish( r.name, r.description, (double)r.price, r.pict_path, (int)r.popularity, tagList, commentList); dishList.Add(dish); } }
//public void Logout() //{} //Function: initialize a customer, and insert a new record of custoemr into db //Return: custoemr newd if user name is valid // null if pName exists in db //user注册后,返回custoemr,把注册记录插到SysUser表 public static Customer Register(string pName, string pPwd, string pMail) { Customer custom = null; bool? isExist = false; DataContextDataContext dc = new DataContextDataContext(); dc.is_registered(pName, ref isExist); if (isExist == true) { } //custom = null else // not exist, can insert { try { dc.insert_customer(pName, pPwd, pMail); custom = new Customer(pName, pPwd, pMail); } catch (Exception ex) { } //custom = null; } return custom; }
//public void DeleteDish(Guid pId) //{ // foreach (DishQuota dq in dishQuotaList) // { // if (dq.id == pId) // { // dishQuotaList.Remove(dq); // } // else // { } // } //} public void ChangeState(ReservationState pState) { state = pState; //~ synchronize to db, if need to maintain the state in db DataContextDataContext dc = new DataContextDataContext(); dc.update_state_reservation(id, (int?)state); }
public void AddDish(DishQuota pDishQuota) { dishQuotaList.Add(pDishQuota); DataContextDataContext dc = new DataContextDataContext(); dc.insert_reservation_dish(pDishQuota.id, id, pDishQuota.dishName, pDishQuota.quota,pDishQuota.note); }
public void DeleteDish(string pName) { DataContextDataContext dc = new DataContextDataContext(); dc.delete_dish(pName); }
public void ChangeState(DeliveryState pState) { state = pState; //~ synchronize to db, if need to maintain the state in db DataContextDataContext dc = new DataContextDataContext(); dc.update_state_delivery(id, (int?)state); }
public Dictionary<string, TableState> GetAllTableStateByTime(DateTime pDateTime) { Dictionary<string, TableState> tableStateDict = new Dictionary<string, TableState>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<get_available_tableResult> rs = dc.get_available_table(pDateTime); foreach (get_available_tableResult r in rs) { tableStateDict.Add(r.name, TableState.AVAILABLE); } ISingleResult<get_reserved_tablename_and_reservationResult> rs2 = dc.get_reserved_tablename_and_reservation(pDateTime); foreach (get_reserved_tablename_and_reservationResult r2 in rs2) { tableStateDict.Add(r2.table_name, TableState.RESERVED); } return tableStateDict; }
public void CancelReservation(Guid pId) { DataContextDataContext dc = new DataContextDataContext(); dc.delete_reservation(pId); }
//Function: modify the arrive time of the reservation // invoked when the reservation becomes TIMEOUT and the manager helps to delay the available time for this reservation //$resrvation timeout后,manager可以给延时,状态从timeout到reserved 这个是后加的,设计的有问题,转换写死到数据库存储过程了 public void ProlongReservation(Guid pId, DateTime pDateTime) { DataContextDataContext dc = new DataContextDataContext(); dc.prolong_reservation(pId, pDateTime); }
//CustomService customService = new CustomService(); //ManagerService managerService = new ManagerService(); //Function: assign a table to the custoemr who come into restaurant without a reservation //Parameters: // string pTableName: table name assigned to the customer walk in // Reservation pR: reservation generated which belongs to this new customer //Remarks: // change the TableState to BUSY, the table is specified by pTableName // set the ReservationState to BUSY of pR //$ 一个客人进来,没有提前预定的 table 从available->busy,reservation-》busy public void WalkInArrive(string pTableName, Reservation pR) { foreach (SysTable t in Restaurant.tableList) { if (t.name == pTableName) { DataContextDataContext dc = new DataContextDataContext(); dc.insert_reservation( (Guid?)pR.id, pR.userFrom, pR.customerName, pR.phone, (DateTime?)pR.arriveTime, pR.tableName, (int?)pR.seat, (int?)pR.state); t.SetReservation(pR); //so the table now maintain a reservation t.ChageState(TableState.BUSY); t.GetReservation().ChangeState(ReservationState.BUSY); } else { } } }
//Function: update the DeliveryState as DELIVERED in db, the delivery is is specified by pId //$delivey送出后,manager点一个按钮,undelivered-》deliveried public void SendDelivery(Guid pId) { DataContextDataContext dc = new DataContextDataContext(); dc.update_state_delivery((Guid?)pId, (int?)DeliveryState.DELIVERED); }
//Function: search reservations by keyword //Remarks: if the keyword == null, return all the records public List<Reservation> SearchReservationMatch(string keyword) { List<Reservation> reservationList = new List<Reservation>(); if (keyword == null) { keyword = "%"; } //search all the records else { } DataContextDataContext dc = new DataContextDataContext(); ISingleResult<search_current_reservation_by_keywordResult> rs = dc.search_current_reservation_by_keyword(keyword); foreach (search_current_reservation_by_keywordResult r in rs) { List<DishQuota> dishQuotaList = new List<DishQuota>(); ISingleResult<get_dishquota_by_reservationResult> rs2 = dc.get_dishquota_by_reservation(r.id); foreach (get_dishquota_by_reservationResult r2 in rs2) { double price = 0; ISingleResult<get_dish_by_nameResult> rs3 = dc.get_dish_by_name(r2.dish_name); foreach (get_dish_by_nameResult r3 in rs3) { price = (double)r3.price; } DishQuota tDishQuota = new DishQuota(r2.id, r2.dish_name, price, (int)r2.quato, r2.note); dishQuotaList.Add(tDishQuota); } Reservation reservation = new Reservation( r.id, r.user_from, r.customer_name, r.phone, (DateTime)r.arrive_time, r.table_name, (int)r.seat, (ReservationType)r.type, (ReservationState)r.state, dishQuotaList); reservationList.Add(reservation); } return reservationList; }
//Function: insert a news in db public void PublishNews(News pNews) { DataContextDataContext dc = new DataContextDataContext(); dc.insert_news(pNews.id, pNews.title, pNews.content, (DateTime?)pNews.publishTime, pNews.aboutDish); }