public void Table1() { //使用linq+ef技术查询 myDBEntities dBEntities = new myDBEntities(); var result = dBEntities.employee; //设置表头 string write = "<table id='table1' border=1 cellspacing=0 cellpadding=2>"; write += "<tr>"; write += "<td>员工编号</td>"; write += "<td>员工姓名</td>"; write += "<td>手机号</td>"; write += "<td>是否为管理员</td>"; write += "<td>部门编号</td>"; write += "</tr>"; //通过遍历 注入表格信息 foreach (var employee in result) { write += "<tr>"; write += "<td>" + employee.ep_id + "</td>"; write += "<td>" + employee.name + "</td>"; write += "<td>" + employee.phone + "</td>"; write += "<td>" + employee.administrator + "</td>"; write += "<td>" + employee.dp_id + "</td>"; write += "</tr>"; } write += "</table>"; Response.Write(write);//响应表格到前端 }
protected void Button2_Click(object sender, EventArgs e) { //获取输入内容 string name = TextBox3.Text; if (name != "") { //创建实体类对象 department department = new department(); department.name = name; //通过linq技术添加对象到数据库 myDBEntities myDBEntities = new myDBEntities(); myDBEntities.department.Add(department); int result = myDBEntities.SaveChanges(); //通过执行返回值判断是否添加成功 if (result > 0) { Label1.Text = "添加成功"; } else { Label1.Text = "添加失败"; } } else { Label1.Text = "请输入添加的信息!"; } }
public ActionResult Details(int Id) { myDBEntities myDB = new myDBEntities(); Product product = myDB.Product.Single(x => x.Id == Id); return(View(product)); }
public void Table1() { //通过linq+ef技术查询 myDBEntities dBEntities = new myDBEntities(); var result = from dp in dBEntities.department join ep in dBEntities.employee on dp.ep_id equals ep.ep_id select new { department = dp, employee = ep }; //设置表头 string write = "<table id='table1' border=1 cellspacing=0 cellpadding=2>"; write += "<tr>"; write += "<td>部门编号</td>"; write += "<td>部门名称</td>"; write += "<td>主管编号</td>"; write += "<td>主管姓名</td>"; write += "<td>主管手机号</td>"; write += "</tr>"; //遍历 填充数据 foreach (var a in result) { write += "<tr>"; write += "<td>" + a.department.dp_id + "</td>"; write += "<td>" + a.department.name + "</td>"; write += "<td>" + a.department.ep_id + "</td>"; write += "<td>" + a.employee.name + "</td>"; write += "<td>" + a.employee.phone + "</td>"; write += "</tr>"; } write += "</table>"; Response.Write(write); }
// GET: lista proizvoda public ActionResult Index() { myDBEntities myDB = new myDBEntities(); List <Product> products = myDB.Product.Where(x => x.IsActive == true).ToList(); return(View(products)); }
// GET: Home public ActionResult MockCategories() { myDBEntities myDB = new myDBEntities(); List <Category> categories = myDB.Category.ToList(); List <String> listOfCategories = new List <string> { "Food", "Beverages", "Other" }; Category newCategory = new Category(); if (categories == null) { try { foreach (string category in listOfCategories) { newCategory.Name = category; myDB.Category.Add(newCategory); } myDB.SaveChanges(); } catch (Exception ex) { throw ex; } } return(RedirectToAction("Index", "Product")); }
public ActionResult Index(client model) { if (ModelState.IsValid) { try { var mydb = new myDBEntities(); if (mydb.clients.Any(exist => exist.Email == model.Email)) { TempData["duplicate"] = "Duplicate Email found!, please recheck your client's email"; return(View()); } mydb.clients.Add(model); mydb.SaveChanges(); ModelState.Clear(); TempData["msg"] = "Client data registred successfully!"; mydb.Dispose(); return(RedirectToAction("Index")); } catch { TempData["duplicate"] = "Something went wrong!, please verify your network connectivity"; return(View()); } } else { TempData["duplicate"] = "Inserted data not valid. Please recheck your data and register again"; return(View()); } }
public ActionResult Edit(Product editProduct) { myDBEntities myDB = new myDBEntities(); Product product = myDB.Product.Single(x => x.Id == editProduct.Id); List <Category> categories = myDB.Category.ToList(); ViewBag.Categories = new SelectList(categories, "Id", "Name"); try { product.Name = editProduct.Name.Trim(); product.Price = editProduct.Price; product.Modified = DateTime.Now; product.Created = product.Created; product.IsActive = true; product.CategoryId = editProduct.CategoryId; myDB.SaveChanges(); } catch (DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } return(RedirectToAction("Index")); }
public ActionResult Create() { myDBEntities myDB = new myDBEntities(); List <Category> categories = myDB.Category.ToList(); ViewBag.Categories = new SelectList(categories, "Id", "Name"); return(View()); }
//uređivanje proizvoda public ActionResult Edit(int Id) { myDBEntities myDB = new myDBEntities(); Product product = myDB.Product.Single(x => x.Id == Id); List <Category> categories = myDB.Category.ToList(); ViewBag.Categories = new SelectList(categories, "Id", "Name"); return(View(product)); }
public JsonResult getAllData() { var myDb = new myDBEntities(); myDb.Configuration.ProxyCreationEnabled = false; var clientList = myDb.clients.ToList(); return(Json(clientList, JsonRequestBehavior.AllowGet)); }
public JsonResult GetList_EventandDate(string ename, string edate) { var myDb = new myDBEntities(); myDb.Configuration.ProxyCreationEnabled = false; var eventList = myDb.events.Where(x => x.Date == edate).Where(x => x.EventName.Contains(ename)).ToList(); return(Json(eventList, JsonRequestBehavior.AllowGet)); }
protected void Button2_Click(object sender, EventArgs e) { //获取输入内容 string name = TextBox3.Text; string specifications = TextBox4.Text; string price = TextBox5.Text; string date = TextBox6.Text; string location = TextBox7.Text; string picture = ""; // 重新命名文件名,避免重复和保密 string exten = System.IO.Path.GetExtension(FileUpload1.FileName); //取扩展名 string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + exten; //生成新的文件名 string path = "~/images/" + newFileName; //设置上传的目标虚拟路径 if (FileUpload1.HasFile) //如果上传文件控件不为空,既有文件 { picture = newFileName; } if (name != "" && specifications != "" && price != "" && date != "" && picture != "" && location != "") { //创建实体类对象 并且赋值 equipment equipment = new equipment(); equipment.name = name; equipment.specifications = specifications; equipment.price = Convert.ToDouble(price); equipment.date = Convert.ToDateTime(date); equipment.location = location; equipment.picture = picture; equipment.ep_id = Convert.ToInt32(Session["id"]); //通过linq技术 把实体类对象添加到数据库中 myDBEntities myDBEntities = new myDBEntities(); myDBEntities.equipment.Add(equipment); int result = myDBEntities.SaveChanges(); //通过执行添加操作的返回值 判断添加是否成功 if (result > 0) { Label1.Text = "添加成功"; FileUpload1.SaveAs(Server.MapPath(path));//保存图片 } else { Label1.Text = "添加失败"; } } else { Label1.Text = "请输入添加的信息!"; } }
public JsonResult GetList_Date_Range(string date1, string date2) { //DateTime date1_val = Convert.ToDateTime(date1); // DateTime date2_val = Convert.ToDateTime(date2); var myDb = new myDBEntities(); myDb.Configuration.ProxyCreationEnabled = false; string result = "SELECT * FROM event WHERE Date >= @d1 AND Date <= @d2"; var data_range = myDb.events.SqlQuery(result, new SqlParameter("@d1", date1), new SqlParameter("@d2", date2)).ToList(); return(Json(data_range, JsonRequestBehavior.AllowGet)); }
protected void Button2_Click(object sender, EventArgs e) { //获取输入的信息 string password = TextBox3.Text; string phone = ""; string name = TextBox4.Text; bool super = checkbox.Checked; string dp_id = DropDownList1.SelectedValue; //判断手机号是否为11位 if (TextBox5.Text.Length == 11) { phone = TextBox5.Text; } //判断输入是否为空 if (name != "" && password != "" && phone != "" && dp_id != "") { //创建实体类对象 employee employee = new employee(); employee.password = password; employee.name = name; employee.phone = phone; employee.administrator = super; employee.dp_id = Convert.ToInt32(dp_id); //利用linq技术把实体类对象添加到数据库 myDBEntities myDBEntities = new myDBEntities(); myDBEntities.employee.Add(employee); int result = myDBEntities.SaveChanges(); //通过执行添加操作的返回值判断是否添加成功 if (result > 0) { Label1.Text = "添加成功"; } else { Label1.Text = "添加失败"; } } else { if (phone == "") { Label1.Text = "请正确填写手机号"; } else { Label1.Text = "请输入添加的信息!"; } } }
// GET: Home public ActionResult Index() { var myDb = new myDBEntities(); var dateNow = DateTime.Now.ToString("yyyy/MM/dd"); myDb.Configuration.ProxyCreationEnabled = false; string result = "SELECT TOP 9 * FROM event WHERE Date >= @d1 ORDER BY Date"; var data_range = myDb.events.SqlQuery(result, new SqlParameter("@d1", dateNow)).ToList(); ViewBag.LatestEvents = data_range; return(View()); }
public JsonResult GetAllList() { var myDb = new myDBEntities(); myDb.Configuration.ProxyCreationEnabled = false; var eventList = myDb.events.Select(x => new ViewEvents { EventName = x.EventName, Description = x.Description, Location = x.Location, Date = x.Date, TicketFee = x.TicketFee }).ToList(); return(Json(eventList, JsonRequestBehavior.AllowGet)); }
public string Table1() { string search = TextBox1.Text;//获取输入内容 //通过linq技术查询 myDBEntities dBEntities = new myDBEntities(); var result = from dp in dBEntities.department join ep in dBEntities.employee on dp.ep_id equals ep.ep_id select new { department = dp, employee = ep }; result = result.Where(name => name.department.name.Equals(search)); //设置表头 string write = "<table id='table1' border=1 cellspacing=0 cellpadding=2>"; write += "<tr>"; write += "<td>部门编号</td>"; write += "<td>部门名称</td>"; write += "<td>主管编号</td>"; write += "<td>主管姓名</td>"; write += "<td>主管手机号</td>"; write += "</tr>"; int flag = 0; //遍历 填充数据 foreach (var a in result) { write += "<tr>"; write += "<td>" + a.department.dp_id + "</td>"; write += "<td>" + a.department.name + "</td>"; write += "<td>" + a.department.ep_id + "</td>"; write += "<td>" + a.employee.name + "</td>"; write += "<td>" + a.employee.phone + "</td>"; write += "</tr>"; flag++; } write += "</table>"; if (flag == 0) { write = "没有查到相关数据!"; } return(write); }
//brisanje proizvoda public ActionResult Delete(int Id) { myDBEntities myDB = new myDBEntities(); Product product = myDB.Product.Single(x => x.Id == Id && x.IsActive == true); if (product != null) { product.IsActive = false; try { myDB.SaveChanges(); } catch (Exception ex) { throw ex; } } return(RedirectToAction("Index", "Product")); }
public void Table1() { //使用linq+ef查询 myDBEntities dBEntities = new myDBEntities(); var result = dBEntities.equipment; //设置表头 string write = "<table id='table1' border=1 cellspacing=0 cellpadding=2>"; write += "<tr>"; write += "<td>设备编号</td>"; write += "<td>设备名称</td>"; write += "<td>设备规格</td>"; write += "<td>设备图片</td>"; write += "<td>设备价格</td>"; write += "<td>购买日期</td>"; write += "<td>存放位置</td>"; write += "<td>负责人</td>"; write += "</tr>"; //通过遍历 设置表中的数据 foreach (var equipment in result) { write += "<tr>"; write += "<td>" + equipment.eq_id + "</td>"; write += "<td>" + equipment.name + "</td>"; write += "<td>" + equipment.specifications + "</td>"; //图片名称通过a标签包裹 前端通过js实现显示图片 write += "<td><a onclick='work(this)'>" + equipment.picture + "</a></td>"; write += "<td>" + equipment.price + "</td>"; write += "<td>" + equipment.date + "</td>"; write += "<td>" + equipment.location + "</td>"; write += "<td>" + equipment.ep_id + "</td>"; write += "</tr>"; } write += "</table>"; Response.Write(write);//响应整个表格 }