public ActionResult Create(string id, WMS_CustomerModel vm, int?ViewType, long?customerid) { IEnumerable <SelectListItem> cuslist = ApplicationConfigHelper.GetProjectUserCustomers(base.UserInfo.ProjectID, base.UserInfo.ID).Where(c => c.State && (c.StoreType == 2 || c.StoreType == 3)) .Select(c => new SelectListItem() { Value = c.CustomerID.ToString(), Text = c.CustomerName }); WMS_CustomerService service = new WMS_CustomerService(); vm.StorerID = cuslist; vm.ViewType = ViewType != null ? (int)ViewType : 2; //vm.StorerKey = "必填"; //vm.City = "必填"; //vm.Company = "必填"; //vm.CompanyCode = "必填"; //vm.UserDef10 = "必填"; //vm.AddressLine1 = "必填"; //vm.Contact1 = "必填"; //vm.PhoneNum1 = "必填"; bool isShowUserDef2 = true; if (id != null) { WMS_CustomerService customer = new WMS_CustomerService(); WMS_Customer cus = customer.selectCustomer(id.ToString(), customerid.ToString()); vm.ConvertDesc(cus); vm.CustomerID = customerid; // vm.ViewType = 0; isShowUserDef2 = false; } ViewBag.isWrite = isShowUserDef2; return(View(vm)); }
public WMS_Customer ConvertDesc(WMS_Customer customer) { this.CustomerID = customer.CustomerID; this.StorerKey = customer.StorerKey; this.Active = customer.Active; this.Status = customer.Status; this.Company = customer.Company; this.ReceiptPrefix = customer.ReceiptPrefix; this.OrderPrefix = customer.OrderPrefix; this.CompanyCode = customer.CompanyCode; this.Type = customer.Type; this.AddressLine1 = customer.AddressLine1; this.AddressLine2 = customer.AddressLine2; this.AddressLine3 = customer.AddressLine3; this.AddressLine4 = customer.AddressLine4; this.PostCode = customer.PostCode; this.City = customer.City; this.State = customer.State; this.Country = customer.Country; this.CountryCode = customer.CountryCode; this.Contact1 = customer.Contact1; this.Contact2 = customer.Contact2; this.PhoneNum1 = customer.PhoneNum1; this.PhoneNum2 = customer.PhoneNum2; this.FaxNum1 = customer.FaxNum1; this.FaxNum2 = customer.FaxNum2; this.Email1 = customer.Email1; this.Email2 = customer.Email2; this.UserDef10 = customer.UserDef10; this.CompanyCode = customer.CompanyCode; this.UserDef2 = customer.UserDef2; this.UserDef3 = customer.UserDef3; return(customer); }
public ActionResult Create(WMS_CustomerModel vm) { IEnumerable <SelectListItem> cuslist = ApplicationConfigHelper.GetProjectUserCustomers(base.UserInfo.ProjectID, base.UserInfo.ID).Where(c => c.State && (c.StoreType == 2 || c.StoreType == 3)) .Select(c => new SelectListItem() { Value = c.CustomerID.ToString(), Text = c.CustomerName }); WMS_CustomerService service = new WMS_CustomerService(); vm.StorerID = cuslist; IList <WMS_Customer> customer = new List <WMS_Customer>(); //var segments = new SegmentService().GetSegmentsByCondition(new GetSegmentsByConditionRequest() { Name = "", State = true }).Result; //vm.Segments = segments.Select(s => new SelectListItem() { Value = s.ID.ToString(), Text = s.Name + "------>>详情>>" + s.Description }); //vm.Types = vm.StoreStatus > 0 ? 1 : 0; customer.Add(vm.Convert()); Response <IEnumerable <WMS_Customer> > response = service.AddCustomer(new AddWMS_CustomerRequest() { customers = customer }); { WMS_Customer cus = service.selectCustomer(vm.StorerKey, vm.CustomerID.ToString()); vm.ConvertDesc(cus); if (response.IsSuccess) { //刷新缓存 //ApplicationConfigHelper.RefreshApplicationWMS_Customers(); //ApplicationConfigHelper.RefreshGetApplicationWMS_Customer(); vm.ViewType = 0; ViewBag.Message = "0"; } return(View(vm)); } }
public IEnumerable <WMS_Customer> Get_WMS_CustomerByNumbers(IEnumerable <string> nums) { using (SqlConnection conn = new SqlConnection(BaseAccessor._dataBase.ConnectionString)) { SqlCommand cmd = new SqlCommand("Proc_Get_WMS_CustomerByNumbers", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ReceiptNumbers", nums.Select(p => new Numbers(p))); cmd.Parameters[0].SqlDbType = SqlDbType.Structured; cmd.CommandTimeout = 300; conn.Open(); IList <WMS_Customer> stores = new List <WMS_Customer>(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { WMS_Customer store = new WMS_Customer(); store.StorerKey = reader.IsDBNull(0) ? string.Empty : reader.GetString(0); store.UserDef2 = reader.IsDBNull(1) ? string.Empty : reader.GetString(1); store.UserDef3 = reader.IsDBNull(2) ? string.Empty : reader.GetString(2); store.UserDef4 = reader.IsDBNull(3) ? string.Empty : reader.GetString(3); stores.Add(store); } return(stores); } }
public WMS_CustomerToDb(WMS_Customer customer) : base(s_metadata) { SetSqlString(0, customer.StorerKey); SetSqlString(1, customer.Company); SetSqlString(2, customer.ReceiptPrefix); SetSqlString(3, customer.OrderPrefix); SetSqlString(4, customer.AddressLine1); SetSqlString(5, customer.AddressLine2); SetSqlString(6, customer.Contact1); SetSqlString(7, customer.Contact2); SetSqlString(8, customer.PhoneNum1); SetSqlString(9, customer.PhoneNum2); SetSqlString(10, customer.FaxNum1); SetSqlString(11, customer.FaxNum2); SetSqlString(12, customer.Email1); SetSqlString(13, customer.Email2); SetSqlString(14, customer.City); SetSqlString(15, customer.Country); SetSqlString(16, customer.State); SetSqlString(17, customer.CustomerID.ToString()); SetSqlString(18, customer.UserDef10); SetSqlString(19, customer.CompanyCode); SetSqlString(20, customer.UserDef2); SetSqlString(21, customer.UserDef3); }
/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <WMS_CustomerModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { WMS_Customer entity = new WMS_Customer(); entity.Id = 0; entity.CustomerCode = model.CustomerCode; entity.CustomerShortName = model.CustomerShortName; entity.CustomerName = model.CustomerName; entity.CustomerType = model.CustomerType; entity.LinkMan = model.LinkMan; entity.LinkManTel = model.LinkManTel; entity.LinkManAddress = model.LinkManAddress; entity.Status = model.Status; entity.Remark = model.Remark; entity.CreatePerson = model.CreatePerson; entity.CreateTime = ResultHelper.NowTime; entity.ModifyPerson = model.ModifyPerson; entity.ModifyTime = model.ModifyTime; db.WMS_Customer.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }
public virtual WMS_CustomerModel GetById(object id) { if (IsExists(id)) { WMS_Customer entity = m_Rep.GetById(id); WMS_CustomerModel model = new WMS_CustomerModel(); model.Id = entity.Id; model.CustomerCode = entity.CustomerCode; model.CustomerShortName = entity.CustomerShortName; model.CustomerName = entity.CustomerName; model.CustomerType = entity.CustomerType; model.LinkMan = entity.LinkMan; model.LinkManTel = entity.LinkManTel; model.LinkManAddress = entity.LinkManAddress; model.Status = entity.Status; model.Remark = entity.Remark; model.CreatePerson = entity.CreatePerson; model.CreateTime = entity.CreateTime; model.ModifyPerson = entity.ModifyPerson; model.ModifyTime = entity.ModifyTime; return(model); } else { return(null); } }
public WMS_Customer Convert() { WMS_Customer customer = new WMS_Customer(); customer.StorerKey = this.StorerKey; customer.Active = this.Active; customer.Status = this.Status; customer.Company = this.Company; customer.ReceiptPrefix = this.ReceiptPrefix; customer.OrderPrefix = this.OrderPrefix; customer.CompanyCode = this.CompanyCode; customer.Type = this.Type; customer.AddressLine1 = this.AddressLine1; customer.AddressLine2 = this.AddressLine2; customer.AddressLine3 = this.AddressLine3; customer.AddressLine4 = this.AddressLine4; customer.PostCode = this.PostCode; customer.City = this.City; customer.State = this.State; customer.Country = this.Country; customer.CountryCode = this.CountryCode; customer.Contact1 = this.Contact1; customer.Contact2 = this.Contact2; customer.PhoneNum1 = this.PhoneNum1; customer.PhoneNum2 = this.PhoneNum2; customer.FaxNum1 = this.FaxNum1; customer.FaxNum2 = this.FaxNum2; customer.Email1 = this.Email1; customer.Email2 = this.Email2; customer.CustomerID = this.CustomerID; return(customer); }
public ActionResult Edit(string ID, string CustomerID) { WMS_CustomerService customer = new WMS_CustomerService(); WMS_Customer cus = customer.selectCustomer(ID, CustomerID); CustomerModel c = new CustomerModel(); //ID, Code, Name, Description, State, CreateDate, Email, LawPerson, PostCode, c.PostCode = cus.PostCode; //Address1, Address2, Bank, Account, TaxID, InvoiceTitle, Contactor1, Title1, Phone1, return(View(c)); }
public virtual bool Edit(ref ValidationErrors errors, WMS_CustomerModel model) { try { WMS_Customer entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.CustomerCode = model.CustomerCode; entity.CustomerShortName = model.CustomerShortName; entity.CustomerName = model.CustomerName; entity.CustomerType = model.CustomerType; entity.LinkMan = model.LinkMan; entity.LinkManTel = model.LinkManTel; entity.LinkManAddress = model.LinkManAddress; entity.Status = model.Status; entity.Remark = model.Remark; entity.CreatePerson = model.CreatePerson; entity.CreateTime = model.CreateTime; entity.ModifyPerson = model.ModifyPerson; entity.ModifyTime = model.ModifyTime; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public WMS_Customer selectCustomer(string StorerKey, string customerid) { string sql = "select * from [dbo].[WMS_Customer] where StorerKey='" + StorerKey + "' and customerid='" + customerid + "'"; WMS_Customer c = new WMS_Customer(); using (SqlConnection conn = new SqlConnection(BaseAccessor._dataBase.ConnectionString)) { SqlCommand comm = new SqlCommand(sql, conn); //comm.CommandType = CommandType.StoredProcedure; SqlDataAdapter sdr = new SqlDataAdapter(comm); DataTable dt = new DataTable(); sdr.Fill(dt); foreach (DataRow dr in dt.Rows) { c.StorerKey = dr["StorerKey"].ToString(); c.City = dr["City"].ToString(); c.Company = dr["Company"].ToString(); c.AddressLine1 = dr["AddressLine1"].ToString(); c.AddressLine2 = dr["AddressLine2"].ToString(); c.Contact1 = dr["Contact1"].ToString(); c.Contact2 = dr["Contact2"].ToString(); c.PhoneNum1 = dr["PhoneNum1"].ToString(); c.PhoneNum2 = dr["PhoneNum2"].ToString(); c.FaxNum1 = dr["FaxNum1"].ToString(); c.FaxNum2 = dr["FaxNum2"].ToString(); c.Email1 = dr["Email1"].ToString(); c.Email2 = dr["Email2"].ToString(); c.ReceiptPrefix = dr["ReceiptPrefix"].ToString(); c.OrderPrefix = dr["OrderPrefix"].ToString(); c.Country = dr["Country"].ToString(); c.State = dr["State"].ToString(); c.UserDef10 = dr["UserDef10"].ToString(); c.CompanyCode = dr["CompanyCode"].ToString(); c.UserDef2 = dr["UserDef2"].ToString(); c.UserDef3 = dr["UserDef3"].ToString(); } return(c); } }
public bool ImportExcelData(string oper, string filePath, ref ValidationErrors errors) { bool rtn = true; var targetFile = new FileInfo(filePath); if (!targetFile.Exists) { errors.Add("导入的数据文件不存在"); return(false); } var excelFile = new ExcelQueryFactory(filePath); using (XLWorkbook wb = new XLWorkbook(filePath)) { //第一个Sheet using (IXLWorksheet wws = wb.Worksheets.First()) { //对应列头 excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerCode, "客户编码"); excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerShortName, "客户简称"); excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerName, "客户名称"); excelFile.AddMapping <WMS_CustomerModel>(x => x.CustomerType, "客户类型"); excelFile.AddMapping <WMS_CustomerModel>(x => x.LinkMan, "联系人"); excelFile.AddMapping <WMS_CustomerModel>(x => x.LinkManTel, "联系电话"); excelFile.AddMapping <WMS_CustomerModel>(x => x.LinkManAddress, "联系地址"); //excelFile.AddMapping<WMS_CustomerModel>(x => x.Status, "状态"); excelFile.AddMapping <WMS_CustomerModel>(x => x.Remark, "说明"); //excelFile.AddMapping<WMS_CustomerModel>(x => x.CreatePerson, "创建人"); //excelFile.AddMapping<WMS_CustomerModel>(x => x.CreateTime, "创建时间"); //excelFile.AddMapping<WMS_CustomerModel>(x => x.ModifyPerson, "修改人"); //excelFile.AddMapping<WMS_CustomerModel>(x => x.ModifyTime, "修改时间"); //SheetName,第一个Sheet var excelContent = excelFile.Worksheet <WMS_CustomerModel>(0); //开启事务 using (DBContainer db = new DBContainer()) { var tran = db.Database.BeginTransaction(); //开启事务 int rowIndex = 0; //检查数据正确性 foreach (var row in excelContent) { rowIndex += 1; string errorMessage = String.Empty; var model = new WMS_CustomerModel(); model.Id = row.Id; model.CustomerCode = row.CustomerCode; model.CustomerShortName = row.CustomerShortName; model.CustomerName = row.CustomerName; model.CustomerType = row.CustomerType; model.LinkMan = row.LinkMan; model.LinkManTel = row.LinkManTel; model.LinkManAddress = row.LinkManAddress; //model.Status = row.Status; model.Remark = row.Remark; //model.CreatePerson = row.CreatePerson; //model.CreateTime = row.CreateTime; //model.ModifyPerson = row.ModifyPerson; //model.ModifyTime = row.ModifyTime; if (!String.IsNullOrEmpty(errorMessage)) { rtn = false; errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage; continue; //rtn = false; //errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); //wws.Cell(rowIndex + 1, 15).Value = errorMessage; //continue; } //执行额外的数据校验 try { AdditionalCheckExcelData(db, ref model); } catch (Exception ex) { rtn = false; errorMessage = ex.Message; errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); //wws.Cell(rowIndex + 1, 15).Value = errorMessage; wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage; continue; } //写入数据库 WMS_Customer entity = new WMS_Customer(); entity.Id = model.Id; entity.CustomerCode = model.CustomerCode; entity.CustomerShortName = model.CustomerShortName; entity.CustomerName = model.CustomerName; entity.CustomerType = model.CustomerType; entity.LinkMan = model.LinkMan; entity.LinkManTel = model.LinkManTel; entity.LinkManAddress = model.LinkManAddress; entity.Status = "有效"; entity.Remark = model.Remark; entity.CreatePerson = oper; entity.CreateTime = DateTime.Now; entity.ModifyPerson = oper; entity.ModifyTime = DateTime.Now; db.WMS_Customer.Add(entity); try { db.SaveChanges(); } catch (Exception ex) { rtn = false; //将当前报错的entity状态改为分离,类似EF的回滚(忽略之前的Add操作) db.Entry(entity).State = System.Data.Entity.EntityState.Detached; errorMessage = ex.InnerException.InnerException.Message; errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); //wws.Cell(rowIndex + 1, 15).Value = errorMessage; wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage; } } if (rtn) { tran.Commit(); //必须调用Commit(),不然数据不会保存 } else { tran.Rollback(); //出错就回滚 } } } wb.Save(); } return(rtn); }