//分页 void DataBindToRepeater(int currentPage) { using (var db = new TeachingCenterEntities()) { List <Develop> service; DateTime min = new DateTime(1900, 1, 1); DateTime max = new DateTime(2300, 12, 31); if (logmin.Value != "") { min = Convert.ToDateTime(logmin.Value); } if (logmax.Value != "") { max = Convert.ToDateTime(logmax.Value).AddDays(1); } if (txtSearch.Text == "") { if (dropCategory.SelectedValue != "全部分类") { int category = DevelopHelper.getCategoryId(dropCategory.SelectedValue); service = db.Develop.Where(a => a.Develop_deleted == 0 && a.Develop_category == category && a.Develop_time >= min && a.Develop_time <= max).OrderByDescending(a => a.Develop_time).ToList(); } else { service = db.Develop.Where(a => a.Develop_deleted == 0 && a.Develop_time >= min && a.Develop_time < max).OrderByDescending(a => a.Develop_time).ToList(); } } else { if (dropCategory.SelectedValue != "全部分类") { int category = DevelopHelper.getCategoryId(dropCategory.SelectedValue); service = db.Develop.Where(a => a.Develop_deleted == 0 && a.Develop_category == category && a.Develop_time >= min && a.Develop_time <= max && a.Develop_title.Contains(txtSearch.Text)).OrderByDescending(a => a.Develop_time).ToList(); } else { service = db.Develop.Where(a => a.Develop_deleted == 0 && a.Develop_time >= min && a.Develop_time < max && a.Develop_title.Contains(txtSearch.Text)).OrderByDescending(a => a.Develop_time).ToList(); } } ltCount.Text = service.Count().ToString(); PagedDataSource pds = new PagedDataSource(); pds.AllowPaging = true; pds.PageSize = 10; pds.DataSource = service.ToList(); pds.CurrentPageIndex = currentPage - 1; rptService.DataSource = pds; rptService.DataBind(); ltTotal.Text = pds.PageCount.ToString(); if (Convert.ToInt32(ltNow.Text) == 1) { btnLast.Enabled = false; } else { btnLast.Enabled = true; } if (Convert.ToInt32(ltNow.Text) == pds.PageCount) { btnNext.Enabled = false; } else { btnNext.Enabled = true; } } }
protected void btnSub_Click(object sender, EventArgs e) { string title = txtTitle.Text; string link = txtLink.Text; string content = myEditor11.InnerHtml; string arthor = txtAuthor.Text; string summary = TextBox1.Text; if (title.Length == 0 || arthor.Length == 0) { JSHelper.ShowAlert("输入不能为空!"); } else if (cbxLink.Checked && link.Length == 0) { JSHelper.ShowAlert("输入不能为空!"); } else if (!cbxLink.Checked && content.Length == 0) { JSHelper.ShowAlert("输入不能为空!"); } else if (summary.Length == 0) { JSHelper.ShowAlert("输入不能为空!"); } else { try { if (fup.PostedFile.FileName == "") { lblInfo.Text = "请选择文件!"; } else { if (!IsAllowedExtension(fup)) { lblInfo.Text = "上传文件格式不正确!"; } else { string filepath = fup.PostedFile.FileName; string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath("picture/") + filename; fup.PostedFile.SaveAs(serverpath); serverpath = filename; lblInfo.Text = "上传成功!"; using (var db = new TeachingCenterEntities()) { if (!cbxLink.Checked) { link = ""; } Develop dev = new Develop(); dev.Develop_title = title; dev.Develop_author = arthor; dev.Develop_time = DateTime.Now; dev.Develop_content = content; dev.Develop_summary = summary; dev.Develop_link = link; dev.Develop_category = DevelopHelper.getCategoryId(dropCategory.SelectedValue); dev.Develop_hit = 0; dev.Develop_path = serverpath; dev.Develop_deleted = 0; db.Develop.Add(dev); db.SaveChanges(); //JSHelper.ShowAlert("发布成功!"); //JSHelper.Redirect("DevelopManage.aspx"); Server.Transfer("DevelopManage.aspx"); } } } } catch { } } }
protected void btnSub_Click(object sender, EventArgs e) { string title = txtTitle.Text; string link = txtLink.Text; string content = myEditor11.InnerHtml; string summary = TextBox1.Text; string arthor = txtAuthor.Text; if (title.Length == 0 || arthor.Length == 0) { JSHelper.ShowAlert("输入不能为空!"); } else if (cbxLink.Checked && link.Length == 0) { JSHelper.ShowAlert("输入不能为空!"); } else if (!cbxLink.Checked && content.Length == 0) { JSHelper.ShowAlert("输入不能为空!"); } else if (summary.Length == 0) { JSHelper.ShowAlert("输入不能为空!"); } else { int id = 1; try { string teacher = Session["AdminID"].ToString(); id = Convert.ToInt32(Request.QueryString["id"].ToString()); //using (var db = new TeachingCenterEntities()) //{ // var cate = from it in db.DevelopCategory select it; // dropCategory.DataSource = cate.ToList(); // dropCategory.DataTextField = "DevelopCategory_name"; // dropCategory.DataBind(); // Develop dev = db.Develop.Single(a => a.Develop_id == id); // txtTitle.Text = dev.Develop_title; // TextBox1.Text = dev.Develop_summary; // txtLink.Text = dev.Develop_link; // txtAuthor.Text = dev.Develop_author; // myEditor11.InnerHtml = Server.HtmlDecode(dev.Develop_content); //} using (var db = new TeachingCenterEntities()) { Develop dev = db.Develop.Single(a => a.Develop_id == id); dev.Develop_title = title; dev.Develop_author = arthor; dev.Develop_time = DateTime.Now; dev.Develop_content = content; dev.Develop_link = link; if (!cbxLink.Checked) { link = ""; } dev.Develop_summary = summary; dev.Develop_category = DevelopHelper.getCategoryId(dropCategory.SelectedValue); dev.Develop_hit = 0; dev.Develop_deleted = 0; dev.Develop_time = Convert.ToDateTime(pushlishTime.Value.ToString()); //db.Develop.Add(dev); db.SaveChanges(); //JSHelper.ShowAlert("修改成功!"); //JSHelper.Redirect("DevelopManage.aspx"); Server.Transfer("DevelopManage.aspx"); } } catch { } } }