protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e) { if (e.CommandName == "Approve" || e.CommandName == "Deactivate") { int index = Convert.ToInt32(e.CommandArgument); int id = int.Parse(GridView1.DataKeys[index].Value.ToString()); ApplyDB db = new ApplyDB(); Apply apply = db.GetApplyById(id); if (apply != null && apply.ApplyStatus == ApplyStatus.Submitted) { apply.ApplyStatus = ApplyStatus.Approved; db.UpdateApply(apply); var applies = db.GetApplyByTimeRange(apply.ApplyDate, apply.TimeRange, ApplyStatus.Submitted); foreach (var item in applies) { item.ApplyStatus = ApplyStatus.Deactivated; db.UpdateApply(item); } } else if (apply != null && apply.ApplyStatus == ApplyStatus.Approved) { apply.ApplyStatus = ApplyStatus.Deactivated; db.UpdateApply(apply); } this.LoadCurrentApplies(); } }
public bool IsUserCanObservation(string user) { ApplyDB db = new ApplyDB(); IEnumerable<Apply> applies = db.GetMyApplies(DateTime.Now.Date, user); var query = from x in applies where x.ApplyStatus == ApplyStatus.Approved && DateTime.Now >= x.TimeFrom && DateTime.Now <= x.TimeTo select x; return query.Any(); }
protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e) { int id = int.Parse(e.Keys[e.RowIndex].ToString()); ApplyDB db = new ApplyDB(); Apply apply = db.GetApplyById(id); if (apply != null && apply.ApplyStatus == ApplyStatus.Submitted) { apply.ApplyStatus = ApplyStatus.Approved; db.UpdateApply(apply); } else if (apply != null && apply.ApplyStatus == ApplyStatus.Approved) { apply.ApplyStatus = ApplyStatus.Deactivated; db.UpdateApply(apply); } this.LoadCurrentApplies(); }
private void LoadCurrentApplies() { this.GridView1.DataSource = null; ApplyDB db = new ApplyDB(); var applies = db.GetCurrentApplies(); var query = from q in applies select new { ID = q.ID, Name = q.UserId, Date = q.ApplyDate, TimeRange = Helper.TimeRangeArray[q.TimeRange], Status = Helper.GetStatus(q.ApplyStatus) }; this.GridView1.DataSource = query.ToList(); this.GridView1.DataBind(); }