/// <summary> /// 新增货物自定义数据 /// </summary> /// <param name="data"></param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回true,否则返回false</returns> public bool InsertGoods(Goods data, long nOpStaffId, string strOpStaffName, out string strErrText) { long nId = 0; //创建存储过程参数 SqlParameter[] Params = { MakeParam(ID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Output, (object)nId), MakeParam(NAME_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)data.Name), MakeParam(TYPEID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)data.TypeId), MakeParam(GOODSNO_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.GoodsNo), MakeParam(SPECMODEL_PARAM, SqlDbType.NVarChar, 100, ParameterDirection.Input, (object)data.SpecModel), MakeParam(GWEIGHT_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.GWeight??System.DBNull.Value), MakeParam(GRADE_PARAM, SqlDbType.NVarChar, 10, ParameterDirection.Input, (object)data.Grade??System.DBNull.Value), MakeParam(BRAND_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.Brand??System.DBNull.Value), MakeParam(PIECEWEIGHT_PARAM, SqlDbType.NVarChar, 20, ParameterDirection.Input, (object)data.PieceWeight??System.DBNull.Value), MakeParam(PACKING_PARAM, SqlDbType.NVarChar, 10, ParameterDirection.Input, (object)data.Packing??System.DBNull.Value), MakeParam(REMARK_PARAM, SqlDbType.NVarChar, 100, ParameterDirection.Input, (object)data.Remark??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("InsertGoods", Params, out strErrText) >= 0) return true; else return false; }
public ActionResult UploadGoodsFile() { 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++) { Goods data = new Goods(); data.GoodsNo = ds.Tables[0].Rows[i][0].ToString(); data.Name = ds.Tables[0].Rows[i][1].ToString(); long nTypeId = 0; if (!long.TryParse(ds.Tables[0].Rows[i][2].ToString(), out nTypeId)) { return Content(string.Format(InnoSoft.LS.Resources.Strings.NotValidTypeId, i + 2)); } data.TypeId = nTypeId; data.SpecModel = ds.Tables[0].Rows[i][3].ToString(); data.GWeight = ds.Tables[0].Rows[i][4].ToString(); data.Grade = ds.Tables[0].Rows[i][5].ToString(); data.Brand = ds.Tables[0].Rows[i][6].ToString(); if (ds.Tables[0].Rows[i][7].ToString() != string.Empty) { decimal decPieceWeight = 0; if (!decimal.TryParse(ds.Tables[0].Rows[i][7].ToString(), out decPieceWeight)) { return Content(string.Format(InnoSoft.LS.Resources.Strings.NotValidPieceWeight, i + 2)); } } data.PieceWeight = ds.Tables[0].Rows[i][7].ToString(); data.Packing = ds.Tables[0].Rows[i][8].ToString(); data.Remark = ds.Tables[0].Rows[i][9].ToString(); string strErrText; DDSystem dd = new DDSystem(); if (!dd.InsertGoods(data, LoginAccountId, LoginStaffName, out strErrText)) { return Content(string.Format(InnoSoft.LS.Resources.Strings.ImportFailed, strErrText, i + 2)); } } } } } } } } return Content(string.Empty); } catch (Exception e) { return Content(e.Message); } }
/// <summary> /// 新增货物自定义数据 /// </summary> /// <param name="data"></param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回true,否则返回false</returns> public bool InsertGoods(Goods data, 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.InsertGoods(data, nOpStaffId, strOpStaffName, out strErrText)) return false; } transScope.Complete(); } return true; } catch (Exception e) { strErrText = e.Message; return false; } }
public ActionResult NewGoods(GoodsViewModel model) { if (ModelState.IsValid) { //创建数据 Goods data = new Goods(); data.Name = model.Name; data.TypeId = model.TypeId; data.GoodsNo = model.GoodsNo; data.SpecModel = model.SpecModel; data.GWeight = model.GWeight; data.Grade = model.Grade; data.Brand = model.Brand; data.PieceWeight = model.PieceWeight; data.Packing = model.Packing; data.Remark = model.Remark; //保存数据 string strErrText; DDSystem dd = new DDSystem(); if (dd.InsertGoods(data, LoginAccountId, LoginStaffName, out strErrText)) { return Json(string.Empty); } else { return Json(strErrText); } } return View(model); }