博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
后台全选功能以及数据的提交方法
阅读量:4507 次
发布时间:2019-06-08

本文共 9557 字,大约阅读时间需要 31 分钟。

                  
销售品牌/厂家:
" tag="brands" />
<%--
 
--%>
 
CarByCompany.ascx
    
" tag="brands" />
CarByCompany.ascx.cs文件代码:
 public object InputID    {        set;        get;    }    protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id = Convert.ToInt32(InputID); using (dcauto2012Entities db = new dcauto2012Entities()) { IList
list = db.Company.OrderByDescending(o => o.CompanyID) .Where(o => o.BrandID == id) .Where(o => o.ISDongChang == 0) .Where(o => o.InputID != 31) .ToList(); rptCompany.DataSource = list; rptCompany.DataBind(); } } } add.aspx.cs
using System;using System.Data;using System.Configuration;using System;using System.Collections.Generic;using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using dcauto.Utils; using EFDAL; using System.Data; using System.Data.Objects; using Webdiyer.WebControls.Mvc; using System.IO; public partial class manage_car_fourS_add : System.Web.UI.Page { int currentid; protected void Page_Load(object sender, EventArgs e) { ((manage_car_carfoursinfomaster)this.Master).txtTitle = "4S店添加"; if (!this.IsPostBack) { using (dcauto2012Entities db = new dcauto2012Entities()) { WebUtil.CtrlToList(rptbrand, db.Brand.OrderBy(o => o.ISDongChang).OrderBy(o => o.Orders).OrderBy(o => o.BrandID).Where(o => o.ISDongChang == 0).Where(s => s.InputID != 5).ToList()); } } } protected void btnSave_Click(object sender, ImageClickEventArgs e) { string[] borf = hidCarsBrand.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); int flag = 0; if (borf.Length > 0) { flag = 1; } if (flag == 0) { jsHint.Alert("请选择至少一个品牌.若没有则先添加品牌后进行添加4S店"); } else { FourS model = new FourS(); model.Name = txtpname.Text; model.Adress = txtadress.Text; model.Content = txtcontent.Text; string picstr = ""; if (f1.HasFile) { string _imgpath = globalVariables.NewFileName + Path.GetExtension(f1.FileName).ToLower(); f1.PostedFile.SaveAs(globalVariables.CarsPic + _imgpath); model.Pic = _imgpath; } string picstr1 = ""; if (f2.HasFile) { picstr1 = globalVariables.NewFileName + Path.GetExtension(f2.FileName).ToLower(); f2.PostedFile.SaveAs(globalVariables.CarsPic + picstr1); model.Map = picstr1; } string picstr3 = ""; if (f3.HasFile) { picstr3 = globalVariables.NewFileName + Path.GetExtension(f3.FileName).ToLower(); f3.PostedFile.SaveAs(globalVariables.CarsPic + picstr3); model.Pic2 = picstr3; } model.Url = TextBox1.Text; model.Zip = TextBox2.Text; model.Selltel1 = TextBox3.Text; model.Selltel2 = TextBox4.Text; model.Servtel1 = TextBox5.Text; model.Servtel2 = TextBox6.Text; model.Fax = TextBox7.Text; model.Email = TextBox8.Text; model.Companyurl = txtcompanyintro.Text; model.Mapurl = txtmapurl.Text; int userid = 1; if (Session["UserId"] + "" != "") userid = int.Parse(Session["UserId"] + ""); model.Datetime = DateTime.Now; model.AddUser = Session["loginname"] + ""; model.AddUserid = userid; model.ModUser = Session["loginname"] + ""; model.ModUserid = userid; try { using (dcauto2012Entities db = new dcauto2012Entities()) { db.FourS.AddObject(model); db.SaveChanges(); var brandid = 0; foreach (string item in borf) { string witch = item.Substring(0, 1); string id = item.Replace("c", "").Replace("s", ""); EFDAL.FourSunion fs = new FourSunion(); fs.FourSid = model.FourSid; if (witch == "s") { brandid = int.Parse(id); fs.Brandid = brandid; } if (witch == "c") { fs.Brandid = brandid; fs.Companyid = int.Parse(id); db.FourSunion.AddObject(fs); db.SaveChanges(); } } } jsHint.Confirm("添加成功,是否继续添加?", "fourS.asp", "fourS_add.aspx"); } catch (Exception) { jsHint.toUrl("添加失败!", "fourS.aspx"); } } } }
编辑修改:
后台保存代码:
using System;using System.Data;using System.Configuration;using System;using System.Collections.Generic;using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using dcauto.Utils; using EFDAL; using System.Data; using System.Data.Objects; using Webdiyer.WebControls.Mvc; using System.IO; public partial class manage_car_fourS_edit : BasePage { int currentid; protected void Page_Load(object sender, EventArgs e) { ((manage_car_carfoursinfomaster)this.Master).txtTitle = "4S店修改"; if (!this.IsPostBack) { using (dcauto2012Entities db = new dcauto2012Entities()) { WebUtil.CtrlToList(rptbrand, db.Brand.OrderBy(o => o.ISDongChang).OrderBy(o => o.Orders).OrderBy(o => o.BrandID).Where(o => o.ISDongChang == 0).Where(s => s.InputID != 5).ToList()); } if (!string.IsNullOrEmpty(Request["Id"])) InitCtrl(Convert.ToInt32(int.Parse(Request["Id"]))); } } private void InitCtrl(int id) { using (dcauto2012Entities db = new dcauto2012Entities()) { currentid = id; FourS model = db.FourS.Where(s => s.FourSid == id).FirstOrDefault(); this.txtpname.Text = model.Name; this.txtadress.Text = model.Adress; this.txtcontent.Text = model.Content; TextBox1.Text = model.Url; TextBox2.Text = model.Zip; TextBox3.Text = model.Selltel1; TextBox4.Text = model.Selltel2; TextBox5.Text = model.Servtel1; TextBox6.Text = model.Servtel2; TextBox7.Text = model.Fax; TextBox8.Text = model.Email; txtcompanyintro.Text = model.Companyurl; txtmapurl.Text = model.Mapurl; if (!string.IsNullOrEmpty(model.Pic)) { this.f1error.Text = ""; } if (!string.IsNullOrEmpty(model.Map)) { this.f2error.Text = ""; } if (!string.IsNullOrEmpty(model.Pic2)) { this.f3error.Text = ""; } IList
list = db.FourSunion.Where(s => s.FourSid == id).OrderByDescending(s => s.FourSunionid).ToList(); System.Text.StringBuilder result = new System.Text.StringBuilder(); foreach (FourSunion item in list) { if (item.Companyid != null && item.Brandid != null) { result.Append("s"); result.Append(item.Brandid); result.Append(","); } if (item.Companyid != null && item.Brandid != null) { result.Append("c"); result.Append(item.Companyid); result.Append(","); } } hidCarsBrand.Value = result.ToString(); } } public void db1_Click(object sender, EventArgs e) { using (dcauto2012Entities db = new dcauto2012Entities()) { int foursid = Convert.ToInt32(Request.Params["Id"]); FourS model = db.FourS.Where(s => s.FourSid == foursid).FirstOrDefault(); model.Pic = ""; db.SaveChanges(); f1error.Text = ""; } } public void db2_Click(object sender, EventArgs e) { using (dcauto2012Entities db = new dcauto2012Entities()) { int foursid = Convert.ToInt32(Request.Params["Id"]); FourS model = db.FourS.Where(s => s.FourSid == foursid).FirstOrDefault(); model.Map = ""; db.SaveChanges(); f2error.Text = ""; } } public void db3_Click(object sender, EventArgs e) { using (dcauto2012Entities db = new dcauto2012Entities()) { int foursid = Convert.ToInt32(Request.Params["Id"]); FourS model = db.FourS.Where(s => s.FourSid == foursid).FirstOrDefault(); model.Pic2 = ""; db.SaveChanges(); f3error.Text = ""; } } protected void btnSave_Click(object sender, ImageClickEventArgs e) { using (dcauto2012Entities db = new dcauto2012Entities()) { int foursid = Convert.ToInt32(Request.Params["Id"]); FourS model = db.FourS.Where(s => s.FourSid == foursid).FirstOrDefault(); model.Name = txtpname.Text; model.Adress = txtadress.Text; model.Content = txtcontent.Text; string picstr = ""; if (f1.HasFile) { string _imgpath = globalVariables.NewFileName + Path.GetExtension(f1.FileName).ToLower(); f1.PostedFile.SaveAs(globalVariables.CarsPic + _imgpath); model.Pic = _imgpath; } string picstr1 = ""; if (f2.HasFile) { picstr1 = globalVariables.NewFileName + Path.GetExtension(f2.FileName).ToLower(); f2.PostedFile.SaveAs(globalVariables.CarsPic + picstr1); model.Map = picstr1; } string picstr3 = ""; if (f3.HasFile) { picstr3 = globalVariables.NewFileName + Path.GetExtension(f3.FileName).ToLower(); f3.PostedFile.SaveAs(globalVariables.CarsPic + picstr3); model.Pic2 = picstr3; } model.Url = TextBox1.Text; model.Zip = TextBox2.Text; model.Selltel1 = TextBox3.Text; model.Selltel2 = TextBox4.Text; model.Servtel1 = TextBox5.Text; model.Servtel2 = TextBox6.Text; model.Fax = TextBox7.Text; model.Email = TextBox8.Text; model.Companyurl = txtcompanyintro.Text; model.Mapurl = txtmapurl.Text; int userid = 1; if (Session["UserId"] + "" != "") userid = int.Parse(Session["UserId"] + ""); model.Datetime = DateTime.Now; model.AddUser = Session["loginname"] + ""; model.AddUserid = userid; model.ModUser = Session["loginname"] + ""; model.ModUserid = userid; try { db.SaveChanges(); string[] borf = hidCarsBrand.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); IList
list = db.FourSunion.Where(s => s.FourSid == model.FourSid).OrderByDescending(s => s.FourSunionid).ToList(); for (int i = 0; i < list.Count; i++) { db.FourSunion.DeleteObject(list[i]); } db.SaveChanges(); var brandid = 0; foreach (string item in borf) { string witch = item.Substring(0, 1); string id = item.Replace("c", "").Replace("s", ""); EFDAL.FourSunion fs = new FourSunion(); fs.FourSid = model.FourSid; if (witch == "s") { brandid = int.Parse(id); fs.Brandid = brandid; } if (witch == "c") { fs.Brandid = brandid; fs.Companyid = int.Parse(id); db.FourSunion.AddObject(fs); db.SaveChanges(); } } jsHint.toUrl("修改成功!", "fourS.aspx?page=" + Request.QueryString["page"]); } catch (Exception) { jsHint.toUrl("修改失败!", "fourS.aspx?page=" + Request.QueryString["page"]); } } } }
 
 
 
 
 

转载于:https://www.cnblogs.com/ft-Pavilion/p/4634997.html

你可能感兴趣的文章
1.7 本机单步调试(Intellij IDEA)
查看>>
自动化运维:日志系统上线规范(十)
查看>>
同步、异步、阻塞与非阻塞
查看>>
01软件架构设计的思想与模式阅读笔记
查看>>
Selenium 上传文件失败,解决办法一
查看>>
2019年,我们需要加强关注网络安全的6大原因
查看>>
Hexo主题 —— NexT优化
查看>>
Python Web Flask源码解读(三)——模板渲染过程
查看>>
JavaScript 中的对象(一)- 对象的概念、模型、以及创建
查看>>
产品的痛点、爽点和痒点
查看>>
密码学摘要算法之SHA2
查看>>
dealloc和weak底层实现
查看>>
【网络】Windows 下 socket 编程范例
查看>>
【IT】CRC校验码是怎么回事呢?
查看>>
hashmap C++实现
查看>>
C++深拷贝和浅拷贝细节理解
查看>>
云风协程库coroutine源码分析
查看>>
【漫谈数据仓库】 如何优雅地设计数据分层 ODS DW DM层级
查看>>
POJ - 2559 && POJ - 3494 (单调栈)
查看>>
POJ - 2796 Feel Good (单调栈)
查看>>