protected void Button1_Click(object sender, EventArgs e) { nav.Visible = false; try { int maxid = 0; DataClasses1DataContext db = new DataClasses1DataContext(); if (db.works.Count() != 0) { maxid = db.works.Max(x => x.id); } else { maxid = 0; } work w = new work(); w.id = maxid + 1; w.user_id = Convert.ToInt32(user_id.Value.ToString()); w.course_id = Convert.ToInt32(course_id.Value.ToString()); w.subject = subject.Value.ToString(); w.detail = details.Value.ToString(); w.status = status.Value.ToString(); w.dead_time = Calendar1.SelectedDate; db.works.InsertOnSubmit(w); db.SubmitChanges(); Response.Redirect(Request.RawUrl); } catch (Exception ex) { nav.Visible = true; alert.InnerText = e.ToString(); } }
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { try { DataClasses1DataContext db = new DataClasses1DataContext(); int id = Convert.ToInt32(e.CommandArgument.ToString()); if (e.CommandName.Equals("Delete") == true) { var cc = from c in db.works where c.id == id select c; work bn = cc.First(); var del = from u in db.acceptances where u.work_id == id select u; foreach (var cx in del) { db.acceptances.DeleteOnSubmit(cx); } var del2 = from u in db.applicants where u.work_id == id select u; foreach (var cx in del2) { db.applicants.DeleteOnSubmit(cx); } db.SubmitChanges(); db.works.DeleteOnSubmit(bn); db.SubmitChanges(); Response.Redirect("/WebForm1.aspx"); } else if (e.CommandName.Equals("subject") == true) { var cc = from c in db.works where c.id == id select c; work bn = cc.First(); Response.Redirect("/workpage.aspx?workid=" + bn.id); } } catch (Exception ex) { alert.Visible = true; error.Visible = true; error.InnerText = ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { HtmlGenericControl alg = (HtmlGenericControl)this.Master.FindControl("alert"); alg.Visible = false; randd = 0; try { DataClasses1DataContext db = new DataClasses1DataContext(); string id = Request.QueryString["workid"]; var works = from i in db.works where i.id == Convert.ToInt32(id) select i; var a = works.First(); mywork = a; subject.InnerText = a.subject.ToString(); detail.InnerText = a.detail.ToString(); //Label1.Text = a.subject.ToString(); int ii = a.dead_time.ToUniversalTime().Subtract(DateTime.Now).Days; time.InnerText = Convert.ToString(ii); Random rnd = new Random(); int imgrand = rnd.Next(1, 9); // creates a number between 1 and 12 var ap = mywork.applicants; var all = from i in db.applicants join x in db.users on i.user_id equals x.id where i.work_id == mywork.id select x; Repeater1.DataSource = all; Repeater1.DataBind(); } catch (Exception ex) { HtmlGenericControl er = (HtmlGenericControl)this.Master.FindControl("error"); HtmlGenericControl al = (HtmlGenericControl)this.Master.FindControl("alert"); al.Visible = true; er.Visible = true; er.InnerText = ex.Message; } }
protected void ApOrDecCommand(object source, RepeaterCommandEventArgs e) { DataClasses1DataContext db = new DataClasses1DataContext(); int id = Convert.ToInt32(e.CommandArgument.ToString()); var workupdate = from i in db.works where i.id == id select i; work w = workupdate.First(); if (e.CommandName == "Approve") { w.Approve = 1; } else if (e.CommandName == "Decline") { w.Approve = 0; } db.SubmitChanges(); }