using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.Transactions; using System.Web; using DeiNiu.Utils; using DeiNiu.wms.Data.Model; using DeiNiu.wms.Data.Model.Wcf; using DeiNiu.wms.Logical; using Newtonsoft.Json; using WcfServiceAuthentication; namespace DeiNiu.Wcf { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“Android”。 // 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 Android.svc 或 Android.svc.cs,然后开始调试。 [DataContract] public class FormatedResult { private int code = 0; private Object data = null; private string message = string.Empty; public FormatedResult(string data, int code = 0, string message = "") { this.data = data; this.code = code; this.message = message; } public FormatedResult(Exception er) { this.code = 400; this.message = er.Message; } public FormatedResult( int code = 0, string message = "") { this.code = code; this.message = message; } public FormatedResult(DataTable dt, int code = 0, string message = "") { this.data = JsonConvert.SerializeObject(Android.DataTableToDicList(dt)); this.code = code; this.message = message; } public FormatedResult(Object obj ) { this.data = JsonConvert.SerializeObject(obj); } [DataMember] public int Code { get => code; set => code = value; } [DataMember] public Object Data { get => data; set => data = value; } [DataMember] public string Message { get => message; set => message = value; } } public class Android : basicService, IAndroid { private int operId = 0; static log4net.ILog log = log4net.LogManager.GetLogger("androidSvc"); static internal List> DataTableToDicList(DataTable dt) { List> list = new List>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Dictionary map = new Dictionary(); for (int j = 0; j < dt.Columns.Count; j++) { map.Add((string)dt.Columns[j].ColumnName, dt.Rows[i][j].ToString().TrimEnd()); } list.Add(map); } } return list; } string DataTableToJson2(DataTable dt, string tableName = "table0") { StringBuilder Json = new StringBuilder(); Json.Append("{\"" + tableName + "\":["); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Json.Append("{"); for (int j = 0; j < dt.Columns.Count; j++) { Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":\"" + dt.Rows[i][j].ToString() + "\""); if (j < dt.Columns.Count - 1) { Json.Append(","); } } Json.Append("}"); if (i < dt.Rows.Count - 1) { Json.Append(","); } } } Json.Append("]}"); //var jsonObj= JsonConvert.DeserializeObject(Json.ToString()); return Json.ToString().Replace("\\", ""); } string DataTableToJson1(DataTable dt, string tableName = "table0") { StringBuilder Json = new StringBuilder(); Json.Append("{\"" + tableName + "\":["); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Json.Append("{"); for (int j = 0; j < dt.Columns.Count; j++) { Json.Append("\"" + dt.Columns[j].ColumnName.ToString().TrimEnd() + "\":\"" + dt.Rows[i][j].ToString().TrimEnd() + "\""); if (j < dt.Columns.Count - 1) { Json.Append(","); } } Json.Append("}"); if (i < dt.Rows.Count - 1) { Json.Append(","); } } } Json.Append("]}"); return Json.ToString(); } //-------------------------user validation public FormatedResult validUser(string userId, string passwd) { try { Employee emp = new Employee(); return new FormatedResult(emp.ValidUser(userId, passwd) + ""); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult validRole(string account, string passwd, string role) { throw new NotImplementedException(); } protected void validUser(int operId, string token) { bool isValid = AuthenticationInspector.validUser(operId, token); if (!isValid) { // throw new Exception("非授权用户访问"); } setOperId(operId, token); } protected void setOperId(int operId, string token) { this.operId = operId; this.token = token; } List getAuthLst(int userId, string type = "") { Dictionary> auths = new LAuthority().getMobileAuthorities(userId); List auth = new List(); if (string.IsNullOrEmpty(type)) { if (auths.Keys.Contains("移动设备")) { List portAuth = auths["移动设备"]; foreach (Authority au in portAuth) { auth.Add(au.auth_name); } } if (auths.Keys.Contains("细分权限")) { List portAuth = auths["细分权限"]; /* foreach (Authority au in portAuth) { auth.Add(au.auth_name); } */ List tmp = new List(); foreach (Authority au in portAuth) { tmp.Add(au.auth_name); } auth.AddRange(tmp); getOperId(); ConstAuthourity.setSpecialAuths(userId, tmp); } } else { if (auths.Keys.Contains(type)) { List portAuth = auths[type]; foreach (Authority au in portAuth) { auth.Add(au.auth_name); } } } return auth; } public FormatedResult getPortAuths(int userId, string token) { validUser(userId, token); //针对wince访问,手动验证用户 try { return new FormatedResult(JsonConvert.SerializeObject(getAuthLst(userId))); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getTmpAuthCode() { int randomCode = ConstAuthourity.userKeyPares.ContainsKey(getOperId()) ? ConstAuthourity.userKeyPares[getOperId()] : 0; return new FormatedResult( randomCode +""); } public FormatedResult login(string account, string passwd) { LAuthority auth = new LAuthority(); Employee em = auth.login(account, passwd); AuthenticationInspector.authCach[em.ID] = em.token; List tmp = new List(); foreach (Authority au in em.AuthSpecials) { tmp.Add(au.auth_name); } ConstAuthourity.setSpecialAuths(em.ID, tmp); // return new FormatedResult(JsonConvert.SerializeObject(em)); // em.extrMsg = "this is test"; if (WmsConstants.IS_ONLINE_RESTRICT) { if(WmsConstants.SYSTEM_VALID_LEFT_DAYS <= 0) { em = new Employee(); }else if( WmsConstants.SYSTEM_VALID_LEFT_DAYS <20) { log.Debug(string.Format("Warrning is expiring... IS_ONLINE_RESTRICT: {0}, SYSTEM_VALID_LEFT_DAYS: {1}, SYSTEM_VALID_DATE {2} ", WmsConstants.IS_ONLINE_RESTRICT, WmsConstants.SYSTEM_VALID_LEFT_DAYS, WmsConstants.SYSTEM_VALID_DATE)); em.extrMsg = String.Format("警告:系统将在{0}天后到期停用, 请及时缴费", WmsConstants.SYSTEM_VALID_LEFT_DAYS); } // log.Debug("login user " + em.ToString()); } return new FormatedResult(em); } public List getSpecialAuths(int userId, int warehouse = -1) { List lst = new List(); Dictionary> auths = new LAuthority().getCatedAuthorities(userId, warehouse); foreach (String cate in auths.Keys) { foreach (Authority link in auths[cate]) { if (link.auth_special) { lst.Add(link.auth_name); } } } return lst; } /* public WcfEmployee login2(string account, string passwd) { Employee em = new Employee(); string token = null; if (em.login(account, passwd)) { token = em.token; AuthenticationInspector.authCach[em.ID] = token; } WcfEmployee wcf = new WcfEmployee(); return wcf.getWcfObject(em); } */ public FormatedResult getDictionary() { DataTable dt = new lNode().QueryByFlags(); return new FormatedResult(JsonConvert.SerializeObject(DataTableToDicList(dt))); } FormatedResult IAndroid.getNodesByFlag(int flag) { return new FormatedResult(new Node().queryChildsByFlag(flag)); } //------------------------- stock location begin ------------------------------------------------------------------------------------------ private static lWmslocation _loc; private static lWmsStock _stock; private static lWmsStockPandian _pandian; lWmsStockPandian pandian { get { if (_pandian == null || _pandian.operId != getOperId()) { _pandian = new lWmsStockPandian(getOperId()); } return _pandian; } } lWmsStock lstock { get { if (_stock == null || _stock.operId != getOperId()) { _stock = new lWmsStock(getOperId()); } return _stock; } } lWmslocation loc { get { if (_loc == null || _loc.operId != getOperId()) { _loc = new lWmslocation(getOperId()); } return _loc; } } public FormatedResult getLines(string custName) { DataTable dt = new lTmsLineDetail().getAllLines(custName); /* List lines = new List(); foreach (DataRow dr in dt.Rows) { lines.Add(dr["id"].ToString() + WmsConstants.SPLIT + dr["name"].ToString()); } */ try { return new FormatedResult(JsonConvert.SerializeObject(DataTableToDicList(dt))); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } /// ///取所属货区 /// /// /// public FormatedResult getPartions(int userId) { /* DataTable dt = lport.getPartions(userId); List partions = new List(); foreach (DataRow dr in dt.Rows) { partions.Add(dr["partion"].ToString() + WmsConstants.SPLIT + dr["partName"].ToString()); } return partions; */ try { return new FormatedResult(JsonConvert.SerializeObject(DataTableToDicList(lport.getPartions(userId)))); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getStockLocation(string locId) { /* List> list = DataTableToDicList(lstock.getStockLocation(locId)); string json = JsonConvert.SerializeObject(list); return new FormatedResut(json); */ try { return new FormatedResult(JsonConvert.SerializeObject(DataTableToDicList(lstock.getStockLocation(locId.Trim())))); } catch (Exception e) { log.Error(e); log.Debug(" authcation error :" + e.Message); return new FormatedResult(e); } } public FormatedResult getStockLocationsByBarcode(string barcode) { // return DataTableToJson1(lstock.wmsStock.queryByGoodsBarcode(barcode).Tables[0]); /*DataTable dt = lstock.wmsStock.queryByGoodsBarcode(barcode).Tables[0]; List list = new List(); foreach (DataRow dr in dt.Rows) { list.Add( new WcfWmsLocation(dr)); } return list; */ try { return new FormatedResult(JsonConvert.SerializeObject(DataTableToDicList(lstock.wmsStock.queryByGoodsBarcode(barcode).Tables[0]))); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult updateStockLocation(string locId, string goodsId, int skuId, string batch, decimal count, string reason, int type) { try { bool result = lstock.updateStockLocation(locId, goodsId, skuId, batch, count, reason, (enumStockRecordType)type); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult initialStockIn(string goodsId, string locId, decimal batchCount, string prodDate, string validDate, string batch) { try { enumRepResult result = lstock.initialStockIn(goodsId, locId, batchCount, prodDate, batch); return new FormatedResult(result.ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult clearLocation(string locId, string reason) { try { bool result = lstock.clearLocation(locId, reason); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult upLocationStatus(string locId, int status) { try { bool result = lstock.updateLocationStatus(locId, status); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult updateGoodsLocationVolume(string goodsId, int volType, decimal volume) { try { bool result = lstock.updateGoodsLocationVolume(goodsId, volType, volume); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getLocation(string locId) { try { var result = DataTableToDicList(loc.getWmslocation.getLocations(locId)); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getStockCompareErp(string goodsId, string barcode) { try { var result = DataTableToDicList(lstock.wmsStock.getStockLocationCompareErp(goodsId, barcode)); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult upDownStockLocation(string locId, string goodsId, int skuId, string batch, decimal count, int type, int oldRecId,string flowNo) { try { var result = lstock.upDownGoodsCountWithLocation(locId, goodsId, skuId, batch, count, "", (enumStockRecordType)type, oldRecId,flowNo).ToString(); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getDownStockList4Up(int operId, string flowNo) { try { var result = DataTableToDicList(lstock.wmsStock.getLocationDownList4UpFlow(operId,flowNo)); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult locationEleIdCombine(string locId, int eleId) { try { var result = loc.locationEleIdCombine(locId, eleId); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult repItemIn(string locId, string goodsId, int skuId, string batch, decimal count, int portId) { try { var result = (int)lstock.repItemIn(locId, goodsId, skuId, batch, count, portId); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getLocations(int skuId, string skuCode, string goodsId, string batch, decimal count) { try { DataTable dt = lstock.getBulkLocations(skuId, skuCode, goodsId, batch, count); var result = DataTableToDicList(dt); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getGoodsStockLocations(string barcode) { try { var result = DataTableToDicList(lstock.wmsStock.getGoodsStockLocations(barcode)); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception er) { log.Error(er); return new FormatedResult(er); } } public FormatedResult getGoodsERPStoreByBarcode(string barcode) { try { var result = DataTableToDicList(lstock.wmsStock.getGoodsERPStoreByBarcode(barcode)); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getPandianOrders(int ownerId, int status) { try { var result = DataTableToDicList(pandian.getWmsStockPandian.getPandianOrders(ownerId, status)); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getPandianItem(string orderNo, string locationId) { try { var result = DataTableToDicList(pandian.getPandianResultItem(orderNo, locationId)); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult postPandianItem(int mirrorId, decimal count) { try { var result = pandian.postPandianItem( mirrorId, count); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult newPandianItem(string orderNo, string locationId, int mirrroId, string goodsId, string prdDate, string batch, decimal count) { try { var result = pandian.newPandianItem(orderNo, locationId, mirrroId, goodsId, prdDate, batch, count); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getPandianTargetItem(string orderNo, string locationId) { try { var result = pandian.getPandianTargetItem(orderNo, locationId ); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getPandianTasksByLoc( string locationId) { try { var result = pandian.getPandianTasksByLoc( locationId); return new FormatedResult(JsonConvert.SerializeObject(result)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } //------------------------- stock In Request begin ------------------------------------------------------------------------------------------ static lWmsInRequest _lir; lWmsInRequest lir { get { if (_lir == null || _lir.operId != getOperId()) { _lir = new lWmsInRequest(getOperId()); } return _lir; } } FormatedResult IAndroid.getPreInDetail(string preInNo) { try { return new FormatedResult(lir.getPreInSumary(preInNo)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.receiveDetail(string preInNo, string goodsId, decimal arriveNumber, decimal receiveNumber, int inType, string inRemark, decimal temperature, bool isCache, int cachePartion) { // return lir.receiveDetail(preInNo, id, arriveNumber, receiveNumber, inType, inRemark, shipId, isCache, cachePartion); try { return new FormatedResult(lir.receivePreDetail(preInNo, goodsId, arriveNumber, receiveNumber, inType, inRemark, isCache, cachePartion, temperature) + ""); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getGoodsPackByBarcode(string barcode) { try { return new FormatedResult(lir.getGoodsDetailByBarcode(barcode)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } static lWmsGoods _lgood; lWmsGoods lgood { get { if (_lgood == null || _lgood.operId != getOperId()) { _lgood = new lWmsGoods(getOperId()); } return _lgood; } } FormatedResult IAndroid.getGoodsPacking(string goodsId) { try { return new FormatedResult(new WmsGoods().queryPacking(goodsId)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.goodsMaintain(string goodsId,decimal fullMax, decimal bulkMax, decimal batch1Max, decimal batch2Max, decimal batch3Max, int ABC, int storeType, string barcode, int expiredDays ,bool canSeedOut) { try { lgood.goodsMaintain(goodsId,fullMax, bulkMax, batch1Max, batch2Max, batch3Max, ABC, storeType, barcode, expiredDays, canSeedOut); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } return new FormatedResult(true + ""); } FormatedResult IAndroid.goodsPacking(int id, string goodsId, string barcode, int packingQty, string manufacturer2, string spec, decimal chang, decimal kuan, decimal gao, decimal weight, int stackLayers, int stackLayNums, bool isDelete) { try { lgood.updatePackInfo(id,goodsId,barcode,packingQty,manufacturer2,spec,chang,kuan,gao,weight, stackLayers, stackLayNums,isDelete); } catch (Exception er) { log.Error(er); return new FormatedResult(er); } return new FormatedResult(true + ""); } FormatedResult IAndroid.getReceiveDetailByBarcode(string preInOrder, string barcode) { try { return new FormatedResult(lir.getReceiveDetailByBarcode(preInOrder, barcode)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getValidSeedsCnt(string goodsId, decimal batchCount) { try { return new FormatedResult(lir.getValidSeedsCnt(goodsId, batchCount) + ""); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.isFlowNoValid(string preInOrder, string flowNo) { throw new NotImplementedException(); } /// /// 取消上架任务,重新验货入库 /// 同批次的,同托盘的其他任务一起取消 /// /// /// /// FormatedResult IAndroid.retrieveValidIn(int jobId) { try { return new FormatedResult(lir.retrieveValidByJobId(jobId) + ""); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult retrieveValidByDetailId(int detailId) { try { return new FormatedResult(lir.retrieveValidByDetailId(detailId) + ""); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult retrieveValidBySkuId(string preInNo, int skuId) { try { return new FormatedResult(lir.retrieveValidByPreNo(preInNo, skuId) + ""); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.validIn(string preInNo, string flowNo, string goodsId, decimal batchCount, decimal seedsCount, string prdDate, string validDate, string batch, string entiId, bool isPass, bool isIsuLocations, bool isVirtualIn, int secondValidUserId, bool isFlowUni, bool isZhitong = false, string pickOrderNo = null, int zhitongPartion = 0, int outPickDetailId = 0, int purch_d_id = 0,bool isOnce=false) { // lir.receivePreDetail(preInNo, goodsId, batchCount, receiveNumber, inType, inRemark, isCache, cachePartion, temperature); Dictionary sku = new Dictionary(); sku.Add(WmsConstants.SKU_RESEVRED_PRDDATE_ATTNAME, prdDate); sku.Add(WmsConstants.SKU_RESEVRED_EXPIREDATE_ATTNAME, validDate); sku.Add(WmsConstants.SKU_RESEVRED_BATCH_ATTNAME, batch); sku.Add(WmsConstants.SKU_RESEVRED_ENTI_ATTNAME, entiId); try { // throw new Exception("test...."); enumValidInResult result = lir.validIn(preInNo, flowNo, goodsId.Trim(), batchCount, seedsCount, sku, isPass, isIsuLocations, isVirtualIn, secondValidUserId, 0, true, isFlowUni, isZhitong, pickOrderNo, zhitongPartion, outPickDetailId, purch_d_id,isOnce); FormatedResult rs = new FormatedResult(result.ToString(), (int)result, result.ToString()); return rs; } catch (Exception e) { log.Error(e); return new FormatedResult(400, e.Message); } } FormatedResult IAndroid.getPreValidResult(string preInNo, string flowNo, bool showAllUsers) { try { return new FormatedResult(lir.getPreValidResult4Wince(preInNo, flowNo, showAllUsers)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getValidInDetail(string preInNo, string flowNo) { try { return new FormatedResult(lir.getValidInDetail(preInNo, flowNo)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.finishUpShelfItem(string flowNo, int id, decimal count, string locationId, string reason) { try { enumRepResult result = lir.finishUpShelfItem(flowNo, id, count, locationId, reason); DataTable dt = lir.getPortStockInDetailByPortId(id); return new FormatedResult(dt, (int)result, result.ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getZhiTongOrderDetail(string flowNo) { try { return new FormatedResult(lir.getZhiTongOrderDetail(flowNo)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getZhiTongOrderByCust(string preNo, string barcode, string orderBy) { try { return new FormatedResult(lir.getZhiTongOrderByCust(preNo, orderBy, barcode)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.zhiTongSeedOut(int outDetailId, int inDetailId, decimal seedCnt, string flowNo) { try { enumRepResult result = lir.zhiTongSeedOut(outDetailId, inDetailId, seedCnt, flowNo); return new FormatedResult(result.ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.newPackBarcode(string goodsId, string barcode, decimal packingQty, decimal chang, decimal kuan, decimal gao, decimal weight) { try { enumRepResult result = lir.newBarcode(goodsId, barcode, packingQty, chang, kuan, gao, weight); return new FormatedResult(result.ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.stackDone(string preInNo, string flowNo) { try { enumRepResult result = lir.stackDone(preInNo, flowNo); return new FormatedResult(result.ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.preInDone(string preInNo,bool isZhitongAuto) { try { return new FormatedResult(lir.preInDone(preInNo, isZhitongAuto).ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } //stock out -------begin----------- private static lWmsOutPickRequest _lop; private static lWmsOutPickPort _lport; lWmsOutPickRequest lop { get { if (_lop == null || _lop.operId != getOperId()) { _lop = new lWmsOutPickRequest(getOperId()); } return _lop; } } lWmsOutPickPort lport { get { if (_lport == null || _lport.operId != getOperId()) { _lport = new lWmsOutPickPort(getOperId()); } return _lport; } } FormatedResult IAndroid.getStockInPortDetail(int portId) { try { throw new NotImplementedException(); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getStockInDetails(string flowNo) { try { throw new NotImplementedException(); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getBatchPickOrders4Valid() { try { return new FormatedResult(lop.getBatchPickOrders4Validate()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getPickOrderDetails(string orderNo) { try { throw new NotImplementedException(); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getPickDetail(int id, bool isAssignToMe) { try { DataTable dt = lop.getPortOutPickOrderDetail(id, isAssignToMe); dt.Columns.Remove("id128"); return new FormatedResult(dt); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.finishPickItem(string flowNo, string waveNo, string pickOrderNo, int id, decimal pickCount) { try { return new FormatedResult(lop.finishPickItem(flowNo, waveNo, pickOrderNo, id, pickCount) + ""); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.finishBatchValidateItem(string pickOrderNo, int id, int operId, int checkBy2, string token) { try { throw new NotImplementedException(); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } int IAndroid.batchPickCount4Valid(string pickOrderNo) { try { throw new NotImplementedException(); } catch (Exception e) { log.Error(e); return 2; } } FormatedResult IAndroid.repTodayDetails4Pick(int userId) { try { throw new NotImplementedException(); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.repInDetailsByFlowNo(string flowNo) { try { throw new NotImplementedException(); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getTaskAssigned(int operId,string locationId, int partion, int lineId, bool batchOnly, int orderType, int taskId,int state) { try { DataTable dt = lport.getAssignedOutTasks(operId,locationId, partion, lineId, batchOnly, (enumOrderType)orderType,taskId,state); dt.Columns.Remove("id128"); return new FormatedResult(dt); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.taskAssign(int takeBy, int partion, int lineId, bool batchOnly, int orderType) { try { lport.taskAssignByJob(takeBy, partion, lineId, 0, 0, WmsConstants.OUT_TASK_ASSIGN_BATCH_ONLY, (enumOrderType)orderType); DataTable dt = lport.getAssignedOutTasks(getOperId(),"", partion, lineId, batchOnly, (enumOrderType)orderType); dt.Columns.Remove("id128"); return new FormatedResult(dt); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.taskResign(int partion, int lineId, bool batchOnly, int orderType) { try { throw new NotImplementedException(); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult taskAssignByLocation(string lastJobNo, string locationId, int warehouse) { try { lport.taskAssignByJob(lastJobNo, locationId,warehouse); DataTable dt = lport.getAssignedOutTasks(getOperId(), locationId); dt.Columns.Remove("id128"); return new FormatedResult(dt); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.getSeedsPickDetail(string flowNo, bool isOrderByCust) { try { return new FormatedResult(lport.getSeedsPickDetail(flowNo, isOrderByCust)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.seedsPickOut(string flowNo, int skuId, string productDate, string batch, int outDetailId, decimal seedCnt, string toFlowNo,int inDetailId,bool isForceClose) { try { enumRepResult result = lport.seedsPickOut(flowNo, skuId, productDate, batch, outDetailId, seedCnt, toFlowNo, inDetailId,isForceClose); return new FormatedResult(result.ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } FormatedResult IAndroid.seedsPickOut2(string flowNo, int skuId, string productDate, string batch, int outDetailId, decimal seedCnt, string toFlowNo, int inDetailId, bool isForceClose) { try { decimal seeded = new WmsOutPickDetail(outDetailId).seeded; enumRepResult rs = lport.seedsPickOut(flowNo, skuId, productDate, batch, outDetailId, seedCnt, toFlowNo, inDetailId, isForceClose); seeded = new WmsOutPickDetail(outDetailId).seeded - seeded; return new FormatedResult(rs.ToString(),0,seeded+""); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult upValidImage(string preNo, string goodsId, Stream fileContent) { /* try { byte[] buffer = new byte[1024]; FileStream fs = new FileStream(@"d:\test13.txt" , FileMode.Create, FileAccess.Write); int count = 0; while ((count = fileContent.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, count); } //清空缓冲区 fs.Flush(); //关闭流 fs.Close(); } catch (Exception ex) { log.Error(ex); } */ try { string date = string.Format("{0}{1:D2}", DateTime.Now.Year, DateTime.Now.Month); string sitePath = "c:/image/validation/" + date + "/"; if (!Directory.Exists(sitePath)) Directory.CreateDirectory(sitePath); var fileName = ""; string imgFileName = ""; //string.Format("{0}.{1}.{2}.jpg", preNo, purch_d_id, fileName); string imgPath = "";// Path.Combine(sitePath, imgFileName); using (var ms = new MemoryStream()) { fileContent.CopyTo(ms); ms.Position = 0; Encoding encoding = System.Text.Encoding.UTF8; var reader = new StreamReader(ms, encoding); var headerLength = 0; string firstLine = reader.ReadLine(); log.Debug("first lien is:-->" + firstLine); if (firstLine.Contains("--")) { headerLength += encoding.GetBytes(firstLine).Length + 2; //读第二行,含上传文件名称 var secondLine = reader.ReadLine(); log.Debug(secondLine); headerLength += encoding.GetBytes(secondLine).Length + 2; fileName = new System.Text.RegularExpressions.Regex("filename=\"(?.*)\"").Match(secondLine).Groups["fn"].Value; log.Debug("file name is " + fileName); imgFileName = string.Format("{0}.{1}.{2}", preNo, goodsId, fileName); imgPath = Path.Combine(sitePath, imgFileName); while (true) { var line = reader.ReadLine(); if (line == null) { break; } headerLength += encoding.GetBytes(line).Length + 2; if (line == "") { break; } } } ms.Position = headerLength;//正文开始 if (firstLine.Contains("--")) { ms.SetLength(ms.Length - encoding.GetBytes(firstLine).LongLength - 3 * 2); } else { ms.SetLength(ms.Length); } using (FileStream fs = new FileStream(imgPath, FileMode.Create, FileAccess.Write)) { ms.CopyTo(fs); fs.Close(); fs.Dispose(); } } string imgUrl = date + "/" + imgFileName; log.Debug("imgUrl is " + imgUrl); Erp_purch_receive_pre_valid preValid = new Erp_purch_receive_pre_valid(); preValid.preInOrderNo = preNo; preValid.goodsId = goodsId; preValid.imagePath = imgUrl; preValid.operater = operId; int id = preValid.Add(); return new FormatedResult(imgUrl); } catch (Exception er) { log.Error(er); return new FormatedResult(er); } } private byte[] readRequest(Stream fileContents, int bites) { System.IO.MemoryStream memStream = new System.IO.MemoryStream(); int BUFFER_SIZE = bites; int iRead = 0; int idx = 0; Int64 iSize = 0; memStream.SetLength(BUFFER_SIZE); while (true) { byte[] reqBuffer = new byte[BUFFER_SIZE]; try { iRead = fileContents.Read(reqBuffer, 0, BUFFER_SIZE); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } if (iRead == 0) { break; } iSize += iRead; memStream.SetLength(iSize); memStream.Write(reqBuffer, 0, iRead); idx += iRead; } byte[] content = memStream.ToArray(); memStream.Close(); return content; } Bitmap GetBitmap(byte[] buf) { Int16 width = BitConverter.ToInt16(buf, 18); Int16 height = BitConverter.ToInt16(buf, 22); Bitmap bitmap = new Bitmap(width, height); int imageSize = width * height * 4; int headerSize = BitConverter.ToInt16(buf, 10); System.Diagnostics.Debug.Assert(imageSize == buf.Length - headerSize); int offset = headerSize; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { bitmap.SetPixel(x, height - y - 1, Color.FromArgb(buf[offset + 3], buf[offset], buf[offset + 1], buf[offset + 2])); offset += 4; } } return bitmap; } public FormatedResult upValidImage(RemoteFileInfo request) { const string sitePath = "/image/validation/"; string imgFileName = string.Format("{0}.{1}.jpg", request.preNo, request.purch_d_id); string imgUrl = Path.Combine(sitePath, imgFileName); string path = System.Web.HttpContext.Current.Server.MapPath(sitePath); if (!Directory.Exists(path)) Directory.CreateDirectory(path); string imgFilePath = Path.Combine(path, imgFileName); Image bmp = Bitmap.FromStream(request.FileByteStream); bmp.Save(imgFilePath); Erp_purch_receive_pre_valid preValid = new Erp_purch_receive_pre_valid(); preValid.preInOrderNo = request.preNo; preValid.purch_d_id = request.purch_d_id; preValid.imagePath = imgUrl;// imgFilePath preValid.operater = operId; int id = preValid.Add(); return new FormatedResult((id > 0) + ""); } public FormatedResult upValidImageByStr(string preNo, string purch_d_id, string imagefile) { try { /* imagefile = imagefile.Replace(@"\n", ""); if (imagefile.Length % 4 != 0) // we may have 0, 1 or 2 padding '=' imagefile += new string('=', 4 - imagefile.Length % 4); */ byte[] buf = System.Convert.FromBase64String(imagefile); Bitmap bmp = GetBitmap(buf); const string sitePath = "C:/inetpub/wwwroot/restService/image/validation/"; string imgFileName = string.Format("{0}.{1}.{2}.jpg", preNo, purch_d_id, DateTime.Now.ToUniversalTime()); string imgUrl = Path.Combine(sitePath, imgFileName); Erp_purch_receive_pre_valid preValid = new Erp_purch_receive_pre_valid(); preValid.preInOrderNo = preNo; preValid.purch_d_id = Convert.ToInt32(purch_d_id); preValid.imagePath = imgUrl;// imgFilePath preValid.operater = operId; int id = preValid.Add(); return new FormatedResult(imgUrl); } catch (Exception er) { log.Error(er); return new FormatedResult(er); } } public FormatedResult validImages(string preNo, string goodsId) { try { List list = new List(); DataTable dt = new Erp_purch_receive_pre_valid().queryImages(preNo, goodsId); foreach (DataRow dr in dt.Rows) { list.Add(dr["imagePath"].ToString()); } return new FormatedResult(JsonConvert.SerializeObject(list)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } //-------------容器管理-------------------------------------- lWmsPlate _lplate = new lWmsPlate(); lWmsPlate lplate { get { if (_lplate == null || _lplate.operId != getOperId()) { _lplate = new lWmsPlate(getOperId()); } return _lplate; } } public FormatedResult getRegistedPlate(string flowNo) { try { return new FormatedResult(lplate.queryRegistedPlate(flowNo)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getFromPlate(string flowNo) { try { return new FormatedResult(lplate.getFromPlate(flowNo)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getPlateContents(string flowNo, bool isShowSubs) { try { return new FormatedResult(lplate.getPateJobsDt(flowNo, isShowSubs)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getUnLoadTruckStks(string toPlate, int cnt) { try { return new FormatedResult(lplate.getUnLoadTruckStks(toPlate,cnt) ); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getLoadContent(string flowNo) { try { return new FormatedResult(lplate.getLoadContent(flowNo)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getParentPlate(string flowNo) { try { return new FormatedResult(lplate.getWmsPlate.getParentPlate(flowNo)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getSubPlates(string flowNo) { try { return new FormatedResult(lplate.getWmsPlate.getSubPlateIds(flowNo)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult putPlateIntoPlate(string fromPlate, string toPlate) { try { return new FormatedResult(lplate.putPlateIntoPlate(fromPlate, toPlate).ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult mergePlate(string fromPlate, string toPlate) { try { return new FormatedResult(lplate.mergePlate(fromPlate, toPlate).ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult takeOutPlate(string fromPlate, string plate) { try { return new FormatedResult(lplate.takeOutPlate(fromPlate, plate).ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult plateValidation(string plateId,int portId, int skuId, string productDate, string validDate, string batch, decimal validationCnt, string validReason, bool finialValidation) { try { log.Debug(string.Format("do validation ..")); return new FormatedResult(lplate.plateValidation(plateId, portId, skuId, productDate, validDate, batch, validationCnt, validReason, finialValidation).ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult startTran(string plateId) { try { log.Debug(string.Format("do startTran ..")); return new FormatedResult(lplate.startTran(plateId).ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult loadTruck(string fromPlate, string toPlate) { try { log.Debug(string.Format("do loadTruck ..")); return new FormatedResult(lplate.loadTruck(fromPlate, toPlate).ToString()); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } public FormatedResult getLatestPlate(string custId, string goodsId) { try { return new FormatedResult(lplate.getLatestPlate(custId, goodsId) ); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } //-----------------light pick public FormatedResult getGoodsById(string goodsId) { try { return new FormatedResult(lplate.getGoodsById( goodsId)); } catch (Exception e) { log.Error(e); return new FormatedResult(e); } } } }