public ActionResult Delete(int ID) { #region CWICCard cwiccd = new CWICCard(); Customer cust = cwiccd.FindCust(ID); if (cust != null) { ICCard iccd = cwiccd.Find(ic => ic.CustID == ID); if (iccd != null) { iccd.CustID = 0; Response _resp = cwiccd.Update(iccd); if (_resp.Code == 0) { //记录 } } Response resp = cwiccd.Delete(ID); if (resp.Code == 0) { var data = new { code = 1, message = "删除用户失败,请联系管理员!" }; return(Json(data, JsonRequestBehavior.AllowGet)); } #region 除相关指纹 CWFingerPrint fprint = new CWFingerPrint(); List <FingerPrint> fingerLst = fprint.FindList(p => p.CustID == ID); foreach (FingerPrint print in fingerLst) { fprint.Delete(print.ID); } #endregion } #endregion var nback = new { code = 2, message = "删除成功!" }; return(Json(nback, JsonRequestBehavior.AllowGet)); }
public ActionResult HandleCard(string iccode, int type) { CWICCard cwiccd = new CWICCard(); ICCard iccd = cwiccd.Find(ic => ic.UserCode == iccode); if (iccd == null) { var data = new Response { Code = 0, Message = "找不到该卡" }; return(Json(data)); } switch (type) { case 1: iccd.Status = EnmICCardStatus.Lost; iccd.LossDate = DateTime.Now; break; case 2: iccd.Status = EnmICCardStatus.Normal; iccd.LossDate = DateTime.Parse("2017-1-1"); break; case 3: iccd.Status = EnmICCardStatus.Disposed; iccd.LogoutDate = DateTime.Now; break; default: break; } Response resp = cwiccd.Update(iccd); return(Json(resp)); }
public ActionResult Edit(CustomerModel model) { if (!ModelState.IsValid) { return(View(model)); } CWICCard cwiccd = new CWICCard(); #region 验证用户名、车牌号 //顾客姓名保证唯一的 Customer other = cwiccd.FindCust(cu => cu.UserName == model.UserName && cu.ID != model.ID); if (other != null) { ModelState.AddModelError("", "当前顾客名- " + model.UserName + " 已被占用,其车牌号- " + other.PlateNum + " ,请输入唯一的用户名!"); return(View(model)); } //车牌号码保证唯一的 other = cwiccd.FindCust(cu => cu.PlateNum == model.PlateNum && cu.ID != model.ID); if (other != null) { ModelState.AddModelError("", "当前车牌号- " + model.PlateNum + " 已被绑定,其顾客名- " + other.UserName + " ,请输入正确的车牌号!"); return(View(model)); } #endregion #region Customer cust = cwiccd.FindCust(model.ID); Location origloc = null; //原来是否绑定 if (cust.Type == EnmICCardType.FixedLocation) { origloc = new CWLocation().FindLocation(l => l.Warehouse == cust.Warehouse && l.Address == cust.LocAddress); } //是固定卡时 if (model.Type == EnmICCardType.FixedLocation) { #region if (model.Warehouse == 0 || string.IsNullOrEmpty(model.LocAddress)) { ModelState.AddModelError("", "固定卡,请指定绑定的库区及车位号!"); return(View(model)); } Location lctn = new CWLocation().FindLocation(lc => lc.Warehouse == model.Warehouse && lc.Address == model.LocAddress); if (lctn == null) { ModelState.AddModelError("", "固定卡,请正确的库区及车位地址!"); return(View(model)); } else { //固定车位时,当前车位没有存车 if (lctn.Status != EnmLocationStatus.Space) { ModelState.AddModelError("", "当前车位:" + lctn.Address + " 已存车,卡号- " + lctn.ICCode + " ,请等待取车完成后再绑定!"); return(View(model)); } } Customer custo = cwiccd.FindCust(cc => cc.Warehouse == model.Warehouse && cc.LocAddress == model.LocAddress); if (custo != null) { if (custo.ID != cust.ID) { ModelState.AddModelError("", "当前车位已被别的用户绑定"); return(View(model)); } } cust.Type = model.Type; cust.Warehouse = (int)model.Warehouse; cust.LocAddress = model.LocAddress; //释放原车位 if (origloc != null) { if (origloc.Address != lctn.Address) { SingleCallback.Instance().WatchFixLocation(origloc, 0, "", "", ""); } } //绑定当前车位 SingleCallback.Instance().WatchFixLocation(lctn, 1, cust.UserName, cust.Deadline.ToString(), cust.PlateNum); #endregion } else { cust.Type = model.Type; cust.Warehouse = 0; cust.LocAddress = ""; cust.StartDTime = DateTime.Parse("2017-1-1"); cust.Deadline = DateTime.Parse("2017-1-1"); //释放原车位 if (origloc != null) { SingleCallback.Instance().WatchFixLocation(origloc, 0, "", "", ""); } } ICCard oriIccd = cwiccd.Find(ic => ic.CustID == model.ID); ICCard newIccd = null; if (!string.IsNullOrEmpty(model.UserCode)) { newIccd = cwiccd.Find(ic => ic.UserCode == model.UserCode); if (newIccd == null) { ModelState.AddModelError("", "当前卡号没有注册!"); return(View(model)); } } if (oriIccd == null) { //原先没有绑定的 if (newIccd != null) { newIccd.CustID = cust.ID; cwiccd.Update(newIccd); } } else { if (newIccd == null) { //释放原来卡号 //释放旧卡 oriIccd.CustID = 0; cwiccd.Update(oriIccd); } else //两卡都存在 { //不是同一张卡 if (oriIccd.UserCode != newIccd.UserCode) { #region if (newIccd.Status != EnmICCardStatus.Normal) { ModelState.AddModelError("", "卡已挂失或注销,无法绑定用户!"); return(View(model)); } if (newIccd.CustID != 0) { Customer oricust = cwiccd.FindCust(newIccd.CustID); if (oricust != null) { ModelState.AddModelError("", "该卡已被绑定,车主姓名:" + oricust.UserName); return(View(model)); } } #endregion //释放旧卡 oriIccd.CustID = 0; cwiccd.Update(oriIccd); //绑定新卡 newIccd.CustID = cust.ID; cwiccd.Update(newIccd); } } } //允许更新 cust.PlateNum = model.PlateNum; cust.MobilePhone = model.MobilePhone; cust.UserName = model.UserName; cust.FamilyAddress = model.FamilyAddress; cwiccd.UpdateCust(cust); #region 更新指纹 CWFingerPrint cwfprint = new CWFingerPrint(); if (model.FingerPrint1 != "") { int fpvalue = Convert.ToInt32(model.FingerPrint1); FingerPrint fp = cwfprint.Find(fi => fi.SN_Number == fpvalue); if (fp != null) { if (fp.CustID == 0) { fp.CustID = cust.ID; cwfprint.Update(fp); } } } if (model.FingerPrint2 != "") { int fpvalue = Convert.ToInt32(model.FingerPrint2); FingerPrint fp = cwfprint.Find(fi => fi.SN_Number == fpvalue); if (fp != null) { if (fp.CustID == 0) { fp.CustID = cust.ID; cwfprint.Update(fp); } } } if (model.FingerPrint3 != "") { int fpvalue = Convert.ToInt32(model.FingerPrint3); FingerPrint fp = cwfprint.Find(fi => fi.SN_Number == fpvalue); if (fp != null) { if (fp.CustID == 0) { fp.CustID = cust.ID; cwfprint.Update(fp); } } } #endregion #endregion return(RedirectToAction("Index")); }
public ActionResult Add(CustomerModel model) { if (!ModelState.IsValid) { return(View(model)); } CWICCard cwiccd = new CWICCard(); //顾客姓名保证唯一的 Customer other = cwiccd.FindCust(cu => cu.UserName == model.UserName); if (other != null) { ModelState.AddModelError("", "当前顾客名- " + model.UserName + " 已被占用,其车牌号- " + other.PlateNum + " ,请输入唯一的用户名!"); return(View(model)); } string plate = ""; foreach (char vl in model.PlateNum) { if (Char.IsLetter(vl)) { plate += char.ToUpper(vl); } else { plate += vl; } } model.PlateNum = plate; //车牌号码保证唯一的 other = cwiccd.FindCust(cu => cu.PlateNum == model.PlateNum); if (other != null) { ModelState.AddModelError("", "当前车牌号- " + model.PlateNum + " 已被绑定,其顾客名- " + other.UserName + " ,请输入正确的车牌号!"); return(View(model)); } Location lctn = null; #region if (model.Type == EnmICCardType.FixedLocation) { if (model.Warehouse == 0 || string.IsNullOrEmpty(model.LocAddress)) { ModelState.AddModelError("", "固定车位卡,请指定绑定车位!"); return(View(model)); } lctn = new CWLocation().FindLocation(lc => lc.Warehouse == model.Warehouse && lc.Address == model.LocAddress); if (lctn == null) { ModelState.AddModelError("", "绑定车位不存在,地址-" + model.LocAddress); return(View(model)); } else { //固定车位时,当前车位没有存车 if (lctn.Status != EnmLocationStatus.Space) { ModelState.AddModelError("", "当前车位:" + lctn.Address + " 已存车,卡号- " + lctn.ICCode + " ,请等待取车完成后再绑定!"); return(View(model)); } } } ICCard iccd = null; if (!string.IsNullOrEmpty(model.UserCode)) { #region iccd = cwiccd.Find(ic => ic.UserCode == model.UserCode); if (iccd == null) { ModelState.AddModelError("", "当前用户卡号没有注册,请确保该卡已完成制卡!"); return(View(model)); } if (iccd.Status != EnmICCardStatus.Normal) { ModelState.AddModelError("", "该卡已挂失或注销,无法完成操作!"); return(View(model)); } if (iccd.CustID != 0) { Customer cust = cwiccd.FindCust(iccd.CustID); if (cust != null) { ModelState.AddModelError("", "该卡已被绑定,车主姓名:" + cust.UserName); return(View(model)); } } #endregion } Customer addcust = new Customer(); if (model.Type == EnmICCardType.FixedLocation) { Customer cust = cwiccd.FindCust(cc => cc.Warehouse == model.Warehouse && cc.LocAddress == model.LocAddress); if (cust != null) { ModelState.AddModelError("", "该车位已被其他卡绑定,无法使用该车位- " + model.LocAddress + " ,Warehouse- " + model.Warehouse); return(View(model)); } addcust.Warehouse = (int)model.Warehouse; addcust.LocAddress = model.LocAddress; } addcust.UserName = model.UserName; addcust.PlateNum = model.PlateNum; addcust.FamilyAddress = model.FamilyAddress; addcust.MobilePhone = model.MobilePhone; addcust.Type = EnmICCardType.Temp; if ((int)model.Type > 0) { addcust.Type = model.Type; } addcust.StartDTime = DateTime.Parse("2017-1-1"); addcust.Deadline = DateTime.Parse("2017-1-1"); Response resp = cwiccd.AddCust(addcust); if (resp.Code == 1) { //如果有卡号,则绑定顾客于卡号 if (iccd != null) { iccd.CustID = addcust.ID; resp = cwiccd.Update(iccd); } #region 绑定指纹,更新指纹信息 CWFingerPrint fprint = new CWFingerPrint(); if (!string.IsNullOrEmpty(model.FingerPrint1)) { Int32 sn = Convert.ToInt32(model.FingerPrint1); FingerPrint finger = fprint.Find(p => p.SN_Number == sn); if (finger != null) { finger.CustID = addcust.ID; fprint.Update(finger); } } if (!string.IsNullOrEmpty(model.FingerPrint2)) { Int32 sn = Convert.ToInt32(model.FingerPrint2); FingerPrint finger = fprint.Find(p => p.SN_Number == sn); if (finger != null) { finger.CustID = addcust.ID; fprint.Update(finger); } } if (!string.IsNullOrEmpty(model.FingerPrint3)) { Int32 sn = Convert.ToInt32(model.FingerPrint3); FingerPrint finger = fprint.Find(p => p.SN_Number == sn); if (finger != null) { finger.CustID = addcust.ID; fprint.Update(finger); } } #endregion } if (addcust.Type == EnmICCardType.FixedLocation) { SingleCallback.Instance().WatchFixLocation(lctn, 1, addcust.UserName, addcust.Deadline.ToString(), addcust.PlateNum); } #endregion return(RedirectToAction("Index")); }