public void AddBackwaitsToRestaurant(DataTable backwaitData) { foreach (DataRow row in backwaitData.Rows) { Backwaiter backwait = new Backwaiter(row["Name"].ToString()); backwait.Hours = Convert.ToDecimal(row["Hours"]); decimal tips; if (row["Tips"] == null || string.IsNullOrEmpty(row["Tips"].ToString())) { tips = 0.00M; } else { tips = Convert.ToDecimal(row["Tips"]); } backwait.Tips = tips; backwait.Shift = row["Shift"].ToString().Trim(); backwait.ShiftDate = DateTime.Parse(row["Date"].ToString()).Date; restaurant.AddBackwait(backwait); } }
protected void button1_Click(object sender, EventArgs e) { restaurant = (Restaurant)Session["Restaurant"]; txtBackName.Focus(); string backName; backName = txtBackName.Text; if (!CheckDate(txtDatePicker.Text)) { return; } if (txtBackName.Text == "" || txtHours.Text == "") { if (txtBackName.Text == "") { lblBackNameEdit.Text = "*Required."; lblBackNameEdit.ForeColor = System.Drawing.Color.Red; txtBackName.BorderStyle = BorderStyle.Dotted; txtBackName.BorderColor = System.Drawing.Color.Red; } if (txtHours.Text == "") { lblHoursEdit.Text = "*Required."; lblHoursEdit.ForeColor = System.Drawing.Color.Red; txtHours.BorderStyle = BorderStyle.Dotted; txtHours.BorderColor = System.Drawing.Color.Red; } } else { decimal dblHours; var regex = new Regex(@"^[0-9]*(?:\.[0-9]*)?$"); if (regex.IsMatch(txtHours.Text.Replace("$", string.Empty).Replace(",", string.Empty)) == false) { lblHoursEdit.Text = "*Invalid entry."; lblHoursEdit.ForeColor = System.Drawing.Color.Red; } else { dblHours = Decimal.Parse(txtHours.Text.Replace("$", string.Empty).Replace(",", string.Empty)); Backwaiter backwait = new Backwaiter(txtBackName.Text); backwait.Hours = dblHours; backwait.Shift = cboBWShiftOptions.Text.Trim(); backwait.ShiftDate = GetDate(); restaurant.AddBackwait(backwait); insertBackWaitData(backwait); if (cboBWShiftOptions.Text.Equals(Shift.Dinner.ToString())) { updateBackWaitTips(Shift.Dinner.ToString(), restaurant.DinnerBackWaitHours); } else { updateBackWaitTips(Shift.Lunch.ToString(), restaurant.LunchBackWaitHours); } ScriptManager.RegisterStartupScript(this, GetType(), "Close", "$('#bwClose').click();", true); this.Page_Load(null, null); } } }