/// <summary> /// 新增收货单位数据 /// </summary> /// <param name="data"></param> /// <param name="listDistance"></param> /// <param name="nOpStaffId"></param> /// <param name="strOpStaffName"></param> /// <param name="strErrText"></param> /// <returns></returns> public long InsertReceiver(Receiver data, List<ReceiverDistance> listDistance, long nOpStaffId, string strOpStaffName, out string strErrText) { long nReceiverId = 0; try { using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (DDDAO dao = new DDDAO()) { //新增收货单位数据 nReceiverId = dao.InsertReceiver(data, nOpStaffId, strOpStaffName, out strErrText); if (nReceiverId <= 0) return 0; //新增距离数据 foreach (ReceiverDistance distance in listDistance) { if (!dao.InsertReceiverDistance(distance, nOpStaffId, strOpStaffName, out strErrText)) { return 0; } } } transScope.Complete(); } return nReceiverId; } catch (Exception e) { strErrText = e.Message; return 0; } }
/// <summary> /// 修改收货单位数据 /// </summary> /// <param name="data"></param> /// <param name="listDistance"></param> /// <param name="nOpStaffId"></param> /// <param name="strOpStaffName"></param> /// <param name="strErrText"></param> /// <returns></returns> public bool UpdateReceiver(Receiver data, List<ReceiverDistance> listDistance, long nOpStaffId, string strOpStaffName, out string strErrText) { try { using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (DDDAO dao = new DDDAO()) { //修改收货单位档案数据 if (!dao.UpdateReceiver(data, nOpStaffId, strOpStaffName, out strErrText)) return false; //修改距离数据 if (!dao.DeleteReceiverDistances(data.Name, nOpStaffId, strOpStaffName, out strErrText)) { return false; } foreach (ReceiverDistance distance in listDistance) { if (!dao.InsertReceiverDistance(distance, 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="nOpStaffId"></param> /// <param name="strOpStaffName"></param> /// <param name="strErrText"></param> /// <returns></returns> public long InsertReceiver(Receiver data, long nOpStaffId, string strOpStaffName, out string strErrText) { //创建存储过程参数 SqlParameter[] Params = { MakeParam(ID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Output, (object)data.Id), MakeParam(NAME_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)data.Name), MakeParam(COUNTRYNAME_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.Country), MakeParam(PROVINCENAME_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.Province), MakeParam(CITYNAME_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.City), MakeParam(ADDRESS_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)data.Address), MakeParam(RECEIVERCONTACT_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.Contact??System.DBNull.Value), MakeParam(RECEIVERCONTACTTEL_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.ContactTel??System.DBNull.Value), MakeParam(OPSTAFFID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)nOpStaffId), MakeParam(OPSTAFFNAME_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)strOpStaffName), }; SqlParameterCollection outParams; if (Execute("InsertReceiver", Params, out outParams, out strErrText) < 0) { return 0; } else { return (long)outParams[ID_PARAM].Value; } }
/// <summary> /// 修改收货单位数据 /// </summary> /// <param name="data"></param> /// <param name="nOpStaffId"></param> /// <param name="strOpStaffName"></param> /// <param name="strErrText"></param> /// <returns></returns> public bool UpdateReceiver(Receiver 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(COUNTRYNAME_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.Country), MakeParam(PROVINCENAME_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.Province), MakeParam(CITYNAME_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.City), MakeParam(ADDRESS_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)data.Address), MakeParam(RECEIVERCONTACT_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.Contact??System.DBNull.Value), MakeParam(RECEIVERCONTACTTEL_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.ContactTel??System.DBNull.Value), MakeParam(OPSTAFFID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)nOpStaffId), MakeParam(OPSTAFFNAME_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)strOpStaffName), }; if (Execute("UpdateReceiver", Params, out strErrText) >= 0) return true; else return false; }
/// <summary> /// 新增收货单位数据 /// </summary> /// <param name="data"></param> /// <param name="listDistance"></param> /// <param name="nOpStaffId"></param> /// <param name="strOpStaffName"></param> /// <param name="strErrText"></param> /// <returns></returns> public long InsertReceiver(Receiver data, List<ReceiverDistance> listDistance, long nOpStaffId, string strOpStaffName, out string strErrText) { ReceiverRule rule = new ReceiverRule(); return rule.InsertReceiver(data, listDistance, nOpStaffId, strOpStaffName, out strErrText); }
public ActionResult NewReceiver(ReceiverViewModel model) { if (ModelState.IsValid) { //创建数据 Receiver data = new Receiver(); data.Name = model.Name; data.Country = model.Country; data.Province = model.Province; data.City = model.City; data.Address = model.Address; data.Contact = model.Contact; data.ContactTel = model.ContactTel; List<ReceiverDistance> listDistance = new List<ReceiverDistance>(); if (model.Distances != null) { foreach (ReceiverDistanceViewModel m in model.Distances) { ReceiverDistance d = new ReceiverDistance(); d.ReceiverName = model.Name; d.StartCountry = m.StartCountry; d.StartProvince = m.StartProvince; d.StartCity = m.StartCity; d.KM = m.KM; listDistance.Add(d); } } //保存数据 string strErrText; DDSystem dd = new DDSystem(); if (dd.InsertReceiver(data, listDistance, LoginAccountId, LoginStaffName, out strErrText) > 0) { return Json(string.Empty); } else { return Json(strErrText); } } return View(model); }