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")); }