/// <summary> /// 新增客户 /// </summary> /// <param name="data"></param> /// <param name="listTransportPrice"></param> /// <param name="listForceFeePrice"></param> /// <param name="listStorageFeePrice"></param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回True,否则返回False</returns> public long InsertCustomer(Customer data, List<CustomerTransportPrice> listTransportPrice, List<CustomerForceFeePrice> listForceFeePrice, List<CustomerStorageFeePrice> listStorageFeePrice, long nOpStaffId, string strOpStaffName, out string strErrText) { long nCustomerId = 0; try { using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (CustomerDAO dao = new CustomerDAO()) { //新增客户数据 nCustomerId = dao.InsertCustomer(data, nOpStaffId, strOpStaffName, out strErrText); if (nCustomerId <= 0) return 0; //新增客户结算价格数据 foreach (CustomerTransportPrice price in listTransportPrice) { price.CustomerId = nCustomerId; if (!dao.InsertCustomerTransportPrice(price, nOpStaffId, strOpStaffName, out strErrText)) { return 0; } } //新增客户力支费价格数据 foreach (CustomerForceFeePrice price in listForceFeePrice) { price.CustomerId = nCustomerId; if (!dao.InsertCustomerForceFeePrice(price, nOpStaffId, strOpStaffName, out strErrText)) { return 0; } } //新增客户仓储费价格数据 foreach (CustomerStorageFeePrice price in listStorageFeePrice) { price.CustomerId = nCustomerId; if (!dao.InsertCustomerStorageFeePrice(price, nOpStaffId, strOpStaffName, out strErrText)) { return 0; } } } transScope.Complete(); } return nCustomerId; } catch (Exception e) { strErrText = e.Message; return 0; } }
/// <summary> /// 修改客户 /// </summary> /// <param name="data"></param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回True,否则返回False</returns> public bool UpdateCustomer(Customer data, long nOpStaffId, string strOpStaffName, out string strErrText) { //创建存储过程参数 SqlParameter[] Params = { MakeParam(ID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)data.Id), MakeParam(NAME_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)data.Name), MakeParam(FULLNAME_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)data.FullName), MakeParam(WARNINGSTOCK_PARAM, SqlDbType.Int, 4, ParameterDirection.Input, (object)data.WarningStock), MakeParam(STOPSTOCK_PARAM, SqlDbType.Int, 4, ParameterDirection.Input, (object)data.StopStock), MakeParam(SETTLEMENTEXPRESSION_PARAM, SqlDbType.NVarChar, 100, ParameterDirection.Input, (object)data.SettlementExpression), MakeParam(VALUATIONMODE_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.ValuationMode), MakeParam(GROSSWEIGHTRATE_PARAM, SqlDbType.Decimal, 13, ParameterDirection.Input, (object)data.GrossWeightRate), MakeParam(REMARK_PARAM, SqlDbType.NVarChar, 500, ParameterDirection.Input, (object)data.Remark??System.String.Empty), MakeParam(OWNORGANID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)data.OwnOrganId), MakeParam(OPSTAFFID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)nOpStaffId), MakeParam(OPSTAFFNAME_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)strOpStaffName), }; if (Execute("UpdateCustomer", Params, out strErrText) >= 0) return true; else return false; }
public ActionResult UploadCustomersFile() { try { if (Request.Files.Count > 0) { HttpPostedFileBase uploadFile = Request.Files[0] as HttpPostedFileBase; if (uploadFile.ContentLength > 0) { //上传文件 string strDestFolder = HttpContext.Server.MapPath("/AttachFiles") + @"\" + DateTime.Now.ToString("yyyy-MM-dd"); if (!Directory.Exists(strDestFolder)) Directory.CreateDirectory(strDestFolder); string filePath = strDestFolder + @"\" + Guid.NewGuid().ToString() + Path.GetExtension(uploadFile.FileName); uploadFile.SaveAs(filePath); //读取数据 string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""; using (OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConnectionString)) { conn.Open(); using (DataTable dtExcelSchema = conn.GetSchema("Tables")) { string strSheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString(); string strQuery = "SELECT * FROM [" + strSheetName + "]"; OleDbDataAdapter adapter = new OleDbDataAdapter(strQuery, conn); DataSet ds = new DataSet(); adapter.Fill(ds, "Items"); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { Customer data = new Customer(); data.Name = ds.Tables[0].Rows[i][1].ToString(); data.FullName = ds.Tables[0].Rows[i][2].ToString(); data.WarningStock = int.Parse(ds.Tables[0].Rows[i][6].ToString()); data.StopStock = int.Parse(ds.Tables[0].Rows[i][7].ToString()); data.SettlementExpression = ds.Tables[0].Rows[i][8].ToString(); data.ValuationMode = ds.Tables[0].Rows[i][9].ToString(); data.GrossWeightRate = decimal.Parse(ds.Tables[0].Rows[i][10].ToString()); data.OwnOrganId = long.Parse(ds.Tables[0].Rows[i][11].ToString()); data.Remark = ds.Tables[0].Rows[i][12].ToString(); string strErrText; CustomerSystem customer = new CustomerSystem(); if (customer.InsertCustomer(data, new List<CustomerTransportPrice>(), new List<CustomerForceFeePrice>(), new List<CustomerStorageFeePrice>(), LoginAccountId, LoginStaffName, out strErrText) <= 0) { return Content(string.Format(InnoSoft.LS.Resources.Strings.ImportFailed, strErrText, i + 2)); } } } } } } } } return Content(string.Empty); } catch (Exception e) { return Content(e.Message); } }
public ActionResult NewCustomer(CustomerViewModel model) { if (ModelState.IsValid) { //创建数据 Customer data = new Customer(); data.Name = model.Name; data.FullName = model.FullName; data.WarningStock = model.WarningStock; data.StopStock = model.StopStock; data.SettlementExpression = model.SettlementExpression; data.ValuationMode = model.ValuationMode; data.GrossWeightRate = decimal.Parse(model.GrossWeightRate); data.OwnOrganId = model.OwnOrganId; data.Remark = model.Remark ?? string.Empty; List<CustomerTransportPrice> listTransportPrice = new List<CustomerTransportPrice>(); if (model.TransportPrices != null) { foreach (CustomerTransportPriceViewModel m in model.TransportPrices) { CustomerTransportPrice p = new CustomerTransportPrice(); p.CustomerId = m.CustomerId; p.StartCountry = m.StartCountry; p.StartProvince = m.StartProvince; p.StartCity = m.StartCity; p.DestCountry = m.DestCountry; p.DestProvince = m.DestProvince; p.DestCity = m.DestCity; p.MinTunnagesOrPiles = m.MinTunnagesOrPiles; p.MaxTunnagesOrPiles = m.MaxTunnagesOrPiles; p.StartTime = DateTime.Parse(m.StartTime); p.EndTime = DateTime.Parse(m.EndTime); p.CarType = m.CarType; p.TransportPrice = m.TransportPrice; p.RiverCrossingCharges = m.RiverCrossingCharges; listTransportPrice.Add(p); } } List<CustomerForceFeePrice> listForceFeePrice = new List<CustomerForceFeePrice>(); if (model.ForceFeePrices != null) { foreach (CustomerForceFeePriceViewModel m in model.ForceFeePrices) { CustomerForceFeePrice p = new CustomerForceFeePrice(); p.CustomerId = m.CustomerId; p.StartTime = DateTime.Parse(m.ForceFeePriceStartTime); p.EndTime = DateTime.Parse(m.ForceFeePriceEndTime); p.LoadingForceFeePrice = m.LoadingForceFeePrice; p.UnloadingForceFeePrice = m.UnloadingForceFeePrice; listForceFeePrice.Add(p); } } List<CustomerStorageFeePrice> listStorageFeePrice = new List<CustomerStorageFeePrice>(); if (model.StorageFeePrices != null) { foreach (CustomerStorageFeePriceViewModel m in model.StorageFeePrices) { CustomerStorageFeePrice p = new CustomerStorageFeePrice(); p.CustomerId = m.CustomerId; p.StartTime = DateTime.Parse(m.StorageFeePriceStartTime); p.EndTime = DateTime.Parse(m.StorageFeePriceEndTime); p.StorageFeePrice = m.StorageFeePrice; listStorageFeePrice.Add(p); } } //保存数据 string strErrText; CustomerSystem customer = new CustomerSystem(); if (customer.InsertCustomer(data, listTransportPrice, listForceFeePrice, listStorageFeePrice, LoginAccountId, LoginStaffName, out strErrText) > 0) { return Json(string.Empty); } else { return Json(strErrText); } } return View(model); }
/// <summary> /// 修改客户 /// </summary> /// <param name="data"></param> /// <param name="listTransportPrice"></param> /// <param name="listForceFeePrice"></param> /// <param name="listStorageFeePrice"></param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回True,否则返回False</returns> public bool UpdateCustomer(Customer data, List<CustomerTransportPrice> listTransportPrice, List<CustomerForceFeePrice> listForceFeePrice, List<CustomerStorageFeePrice> listStorageFeePrice, long nOpStaffId, string strOpStaffName, out string strErrText) { try { using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (CustomerDAO dao = new CustomerDAO()) { //修改客户数据 if (!dao.UpdateCustomer(data, nOpStaffId, strOpStaffName, out strErrText)) { return false; } //删除原结算价格数据 if (!dao.DeleteCustomerTransportPrices(data.Id, nOpStaffId, strOpStaffName, out strErrText)) { return false; } //重新新增结算价格数据 foreach (CustomerTransportPrice price in listTransportPrice) { if (!dao.InsertCustomerTransportPrice(price, nOpStaffId, strOpStaffName, out strErrText)) { return false; } } //删除原力支费价格数据 if (!dao.DeleteCustomerForceFeePrices(data.Id, nOpStaffId, strOpStaffName, out strErrText)) { return false; } //重新新增力支费价格数据 foreach (CustomerForceFeePrice price in listForceFeePrice) { if (!dao.InsertCustomerForceFeePrice(price, nOpStaffId, strOpStaffName, out strErrText)) { return false; } } //删除原仓储费价格数据 if (!dao.DeleteCustomerStorageFeePrices(data.Id, nOpStaffId, strOpStaffName, out strErrText)) { return false; } //重新新增仓储费价格数据 foreach (CustomerStorageFeePrice price in listStorageFeePrice) { if (!dao.InsertCustomerStorageFeePrice(price, nOpStaffId, strOpStaffName, out strErrText)) { return false; } } } transScope.Complete(); } return true; } catch (Exception e) { strErrText = e.Message; return false; } }
/// <summary> /// 修改客户 /// </summary> /// <param name="data"></param> /// <param name="listTransportPrice"></param> /// <param name="listForceFeePrice"></param> /// <param name="listStorageFeePrice"></param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回True,否则返回False</returns> public bool UpdateCustomer(Customer data, List<CustomerTransportPrice> listTransportPrice, List<CustomerForceFeePrice> listForceFeePrice, List<CustomerStorageFeePrice> listStorageFeePrice, long nOpStaffId, string strOpStaffName, out string strErrText) { CustomerRule rule = new CustomerRule(); return rule.UpdateCustomer(data, listTransportPrice, listForceFeePrice, listStorageFeePrice, nOpStaffId, strOpStaffName, out strErrText); }