//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; }
//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); } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { bool fileTypeOk = false; string fileExtension = ""; string virtualPath = System.Configuration.ConfigurationManager.AppSettings["ImageDish"]; string path = Server.MapPath(virtualPath); if (this.FileUpload1.HasFile) { fileExtension = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower(); string[] allowExtension = { ".gif", ".png", ".jpeg", ".jpg" }; foreach (string extension in allowExtension) { if (fileExtension.Trim() == extension) { fileTypeOk = true; } } } if (fileTypeOk) { try { Guid id = Guid.NewGuid(); string name = TextBoxName.Text; int seat = Convert.ToInt32(TextBoxSeat.Text); string pictVirtualPath = virtualPath + name.ToString() + fileExtension; SysTable table = new SysTable( id, name, seat, pictVirtualPath, TableState.AVAILABLE); this.FileUpload1.SaveAs(path + table.name.ToString() + fileExtension); bool isSucceed = admin.AddTable(table); if (isSucceed) { SubmitInfoLabel.Text = "succeed to add the dish"; //TextBox.Text = ""; //TextBox2.Text = ""; //TextBox3.Text = ""; //TextBox4.Text = ""; //TextBox5.Text = ""; //TextBox6.Text = ""; } else { SubmitInfoLabel.Text = "fail, the table name exists"; } } catch (Exception ee) { this.SubmitInfoLabel.Text = "fail check the format of the image!"; } } //no file is updated or format error else { this.SubmitInfoLabel.Text = "fail no image is avalable, or format is not allowed!"; } this.SubmitInfoLabel.Visible = true; }