private ReceiptHead GetHeadModelFromDataReader(SqlDataReader dr) { ReceiptHead model = new ReceiptHead(); model.Address = dr["Address"].ToCHString(); model.Name = dr["Name"].ToCHString(); model.Phone = dr["Phone"].ToDBString(); model.PoNbr = dr["PoNbr"].ToDBString(); model.VendID = dr["VendID"].ToInt32(); model.PurchUnit = dr["PurchUnit"].ToDBString(); return(model); }
public string PostReciptInfo(string strReceiveJson, string strUserJson) { bool bSucc = false; string strErrMsg = string.Empty; string strPostAndTask = string.Empty; ReceiptHead DeliveryInfo = new ReceiptHead(); Receipt_DB DRD = new Receipt_DB(); UserInfo userModel = new UserInfo(); try { if (string.IsNullOrEmpty(strReceiveJson)) { return(GetReturnJson(false, DeliveryInfo, "没有过账数据!")); } DeliveryInfo = JSONUtil.JSONHelper.JsonToObject <ReceiptHead>(strReceiveJson); if (DeliveryInfo == null || DeliveryInfo.lstDetails == null || DeliveryInfo.lstDetails.Count <= 0) { return(GetReturnJson(false, DeliveryInfo, "解析客户端数据出错!")); } if (DeliveryInfo.lstDetails.Where(t => t.iQty > 0).Count() == 0) { return(GetReturnJson(false, DeliveryInfo, "收货数量都为零,请确认!")); } userModel = JSONUtil.JSONHelper.JsonToObject <UserInfo>(strUserJson); if (userModel == null || string.IsNullOrEmpty(userModel.UserNo)) { return(GetReturnJson(false, DeliveryInfo, "没有获取用户信息!")); } bSucc = DRD.PostReceipt(ref DeliveryInfo, userModel, ref strErrMsg); if (bSucc == false) { return(GetReturnJson(false, DeliveryInfo, strErrMsg)); } return(GetReturnJson(bSucc, DeliveryInfo, strErrMsg)); } catch (Exception ex) { TOOL.WriteLogMethod.WriteLog("方法:PostReciptInfo---操作人:" + userModel.UserName + strReceiveJson); return(GetReturnJson(false, DeliveryInfo, "Web异常:" + ex.Message + ex.StackTrace)); } }
public bool PostReceipt(ref ReceiptHead model, UserInfo user, ref string strError) { System.Data.DataSet ds = new DataSet(); try { if (!UploadTempReceipt(ref model)) { return(false); } #region 调ERP存储过程过账 string sql = "xMES_sp_Receipt"; //存储过程名称 SqlDataAdapter da = new SqlDataAdapter(sql, OperationSql.ERPConnStr); //设置命令对象类型 da.SelectCommand.CommandType = CommandType.StoredProcedure; //填充数据 da.Fill(ds); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Columns.Count > 0) { if (ds.Tables[0].Columns.Count == 1) { strError = ds.Tables[0].Rows[0][0].ToDBString(); return(false); } if (ds.Tables[0].Columns.Count == 2) { model.BatNbr = ds.Tables[0].Rows[0][0].ToDBString(); model.RcptNbr = ds.Tables[0].Rows[0][1].ToDBString(); } } else { strError = "未收到ERP存储过程返回数据!"; return(false); } #endregion if (!SaveReceipt(ref model, user)) { return(false); } return(true); } catch (Exception ex) { strError = ex.Message; return(false); } }
public bool SaveReceipt(ref ReceiptHead model, UserInfo user) { SqlParameter[] param = GetParameterFromModel(model, user); param[0].Value = XMLUtil.XmlUtil.Serializer(typeof(ReceiptHead), model); param[1].Value = user.UserNo; param[2].Direction = ParameterDirection.Output; OperationSql.ExecuteNonQuery2(CommandType.StoredProcedure, "Proc_SaveRecipt", param); string ErrorMsg = param[2].Value.ToDBString(); if (ErrorMsg.StartsWith("execution error")) { throw new Exception(ErrorMsg); } else { return(true); } }
private SqlParameter[] GetParameterFromModel(ReceiptHead model, UserInfo user) { int i; SqlParameter[] param = new SqlParameter[] { new SqlParameter("data_xml", SqlDbType.Xml), new SqlParameter("strUserNo", SqlDbType.NVarChar), new SqlParameter("strErrMsg", SqlDbType.NVarChar, 1000), }; i = 0; param[i++].Direction = ParameterDirection.Input; param[i++].Direction = ParameterDirection.Input; param[i++].Direction = ParameterDirection.Output; i = 0; param[i++].Size = 30000; param[i++].Size = 20; param[i++].Size = 1000; return(param); }
public string GetReceiptByPoNbr(string strPoNo, string strUserJson) { ReadAPI_DB DB = new ReadAPI_DB(); ReceiptHead model = null; bool bSucc = false; string strError = string.Empty; try { UserInfo user = JSONUtil.JSONHelper.JsonToObject <UserInfo>(strUserJson); using (SqlDataReader dr = DB.ReadData(ReadApiType.RECEIPT, strPoNo)) { while (dr.Read()) { if (model == null) { model = (GetHeadModelFromDataReader(dr)); model.lstDetails = new List <ReceiptDetails>(); } model.lstDetails.Add(GetModelFromDataReader(dr)); } if (model == null) { throw new Exception("未找到数据!"); } bSucc = true; return(GetReturnJson(bSucc, model, strError)); } } catch (Exception ex) { strError = ex.Message; bSucc = false; model = new ReceiptHead(); return(GetReturnJson(bSucc, model, strError)); } finally { } }
private string GetReturnJson(bool bSucc, ReceiptHead DeliveryInfo, string strErrMsg) { DeliveryInfo.Status = bSucc == true ? "S" : "E"; DeliveryInfo.Message = strErrMsg; return(JSONUtil.JSONHelper.ObjectToJson <ReceiptHead>(DeliveryInfo)); }
public bool UploadTempReceipt(ref ReceiptHead model) { string strError = string.Empty; SqlCommand cmd = new SqlCommand(); SqlConnection conn = new SqlConnection(); SqlDataAdapter adp = new SqlDataAdapter(); conn.ConnectionString = OperationSql.ERPConnStr; string sql = null; try { conn.Open(); } catch (Exception ex) { strError = ex.Message; model.Status = "E"; model.Message = strError; return(false); } SqlTransaction myTran; myTran = conn.BeginTransaction(); cmd.Connection = conn; cmd.Transaction = myTran; DataSet result = new DataSet(); try { foreach (var item in model.lstDetails) { sql = string.Format(@"INSERT INTO [Mes_PurchaseOrder] ([OrderNum] ,[RowNum] ,[Invcode] ,[InNum] ,[NetWt] ,[StdTareWt] ,[VbatchCode] ,[VbatchNum] ,[OldbatchCode] ,[Producttime]) VALUES ('{0}','{1}','{2}',{3},{4},{5},'{6}',{7},'{8}','{9}')", item.PoNbr, item.LineRef, item.InvtID, item.iQty, item.NetWt, item.StdTareWt, item.cBatch, item.batchQty, item.VendBatch, item.ProductionDate); cmd.CommandText = sql; if (cmd.ExecuteNonQuery() < 1) { strError = "数据保存失败!"; model.Status = "E"; model.Message = strError; myTran.Rollback(); return(false); } } myTran.Commit(); return(true); } catch (Exception ex) { strError = ex.Message; model.Status = "E"; model.Message = strError; myTran.Rollback(); return(false); } finally { conn.Close(); } }