private InventoryHead GetInventoryHead(SqlDataReader dr)
        {
            InventoryHead result = null;

            try
            {
                result                 = new InventoryHead();
                result.guid            = Guid.NewGuid();
                result.customsCode     = Convert.ToString(dr["customsCode"]);//"0810"
                result.appType         = (int)AppType.Add;
                result.appTime         = DateTime.Now;
                result.appStatus       = (int)AppStatus.Storage;
                result.appUid          = Convert.ToString(dr["appUid"]);          // "8910000308599";
                result.appUname        = Convert.ToString(dr["appUname"]);        // "张钟芮";
                result.copNo           = Convert.ToString(dr["customs_OrderNo"]); // "20150501102414909";
                result.preNo           = null;
                result.orderNo         = Convert.ToString(dr["customs_OrderNo"]);
                result.ebpCode         = Convert.ToString(dr["ebpCode"]);       // "2117960080";
                result.ebpName         = Convert.ToString(dr["ebpName"]);       // "兴城市天浪电子商务信息有限公司";
                result.logisticsNo     = Convert.ToString(dr["logisticsNo"]);
                result.logisticsCode   = Convert.ToString(dr["logisticsCode"]); // "2101980101";
                result.logisticsName   = Convert.ToString(dr["logisticsName"]); // "辽宁省邮政公司";
                result.invtNo          = null;
                result.ieFlag          = OrderType.E;
                result.portCode        = Convert.ToString(dr["portCode"]);// "0803";
                result.ieDate          = DateTime.Now.ToString("yyyyMMdd");
                result.ownerCode       = result.ebpCode;
                result.ownerName       = result.ebpName;
                result.tradeCode       = Convert.ToString(dr["tradeCode"]); // "2114930090";
                result.tradeName       = Convert.ToString(dr["tradeName"]); // "葫芦岛德容(集团)制衣有限公司";
                result.agentCode       = Convert.ToString(dr["agentCode"]); // "2114980005";
                result.agentName       = Convert.ToString(dr["agentName"]); // "葫芦岛誉悦国际货运代理有限责任公司";
                result.tradeMode       = Convert.ToString(dr["tradeMode"]); // "9610";
                result.trafMode        = "9";                               // "6";
                result.trafName        = Convert.ToString(dr["trafName"]);  // "邮政车";
                result.voyageNo        = Convert.ToString(dr["voyageNo"]);  // "辽P0028B";
                result.billNo          = Convert.ToString(dr["billNo"]);    //????????????????????
                result.loctNo          = null;
                result.licenseNo       = null;
                result.country         = Convert.ToString(dr["destinationCountry"]);
                result.destinationPort = Convert.ToString(dr["destinationPort"]);
                result.freight         = Convert.ToSingle(dr["loginticsFreight"]);
                result.freightCurr     = "142";
                result.freightMark     = "3";
                result.insuredFee      = Convert.ToSingle(dr["insuredFee"]);
                result.insuredFeeCurr  = "142";
                result.insuredFeeMark  = "3";
                result.wrapType        = Convert.ToString(dr["wrapType"]);
                result.packNo          = Convert.ToSingle(dr["packNo"]);
                result.weight          = Convert.ToSingle(dr["orderWeight"]);
                result.netWeight       = Convert.ToSingle(dr["orderNetWeight"]);
                result.note            = null;
            }
            catch (Exception ex)
            {
                throw new Exception("GetInventoryHead Exception:" + ex.ToString());
            }
            return(result);
        }
Beispiel #2
0
        public bool CreateMessage601(string logisticsNo)
        {
            bool                 success        = true;
            InventoryHead        inventoryHead  = null;
            List <InventoryList> inventoryLists = null;
            BaseSubscribe        baseSubscribe  = null;
            XElement             xele           = null;
            XNamespace           ns             = null;
            MessageSql           mssql          = null;
            MessageService       msService      = null;

            try
            {
                inventoryHead  = new InventoryHead();
                inventoryLists = new List <InventoryList>();
                baseSubscribe  = new BaseSubscribe();
                mssql          = new MessageSql();
                mssql.QueryDate601(logisticsNo, ref inventoryHead, ref inventoryLists, ref baseSubscribe);
                if (inventoryHead.guid != new Guid())
                {
                    ns   = "http://www.chinaport.gov.cn/ceb";
                    xele = new XElement(ns + "CEB601Message");
                    xele.SetAttributeValue(XNamespace.Xmlns + "ceb", ns);
                    xele = inventoryHead.ToXElememt(xele, ns);
                    foreach (var a in inventoryLists)
                    {
                        xele = a.ToXElememt(xele, ns);
                    }
                    xele = baseSubscribe.ToXElememt(xele, ns);
                    FileUtilities.CreateFolder(ConfigurationInfo.PathSend);
                    xele.Save(ConfigurationInfo.PathSend + "\\" + FileUtilities.GetNewFileName(inventoryHead.orderNo) + "_601.xml");

                    string destPath = FileUtilities.GetNewFolderName(true, ConfigurationInfo.PathBackUp, "601") + "\\" + FileUtilities.GetNewFileName(inventoryHead.orderNo, "Create") + ".xml";

                    msService = new MessageService();
                    msService.DealMessage601(false, true, inventoryHead.guid.ToString(), inventoryHead.copNo, destPath);

                    xele.Save(destPath);
                }
                else
                {
                    Logs.Info("Does not exist in database:" + logisticsNo);
                    success = false;
                }
            }
            catch (Exception ex)
            {
                Logs.Error("Create301Message Exception:" + ex.ToString());
                success = false;
            }
            return(success);
        }
        public bool Post(string InventoryNo)
        {
            InventoryHead inventoryHead = _db.InventoryHead.Where(e => e.InventoryNo == InventoryNo).FirstOrDefault();

            if (inventoryHead.IsSummary == "0" || inventoryHead.IsSummary == "N")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void QueryDate601(string logisticsNo, ref InventoryHead inventoryHead, ref List <InventoryList> inventoryLists, ref BaseSubscribe baseSubscribe)
        {
            InventoryList inventoryList = null;
            SqlDataReader dr            = null;

            try
            {
                dr = a_sqlServer.ExePROC("MessageCenterQuery", ConvertToSqlParameters(601, "", logisticsNo));
                if (dr.HasRows)
                {
                    int i = 1;
                    while (dr.Read())
                    {
                        if (i == 1)
                        {
                            inventoryHead = GetInventoryHead(dr);
                        }
                        inventoryList = GetInventoryList(dr, i++);
                        InventoryList exist = inventoryLists.Find(o => o.gno.Equals(inventoryList.gno));
                        if (exist == null)
                        {
                            inventoryLists.Add(inventoryList);
                        }
                        else
                        {
                            exist.qty   += inventoryList.qty;
                            exist.total += inventoryList.total;
                            exist.qty1  += inventoryList.qty1;
                            exist.qty2  += inventoryList.qty2;
                        }
                        baseSubscribe = GetBaseSubscribe(dr);
                    }
                    foreach (var list in inventoryLists)
                    {
                        var f = inventoryHead.netWeight / inventoryLists.Count;
                        list.qty2 = ((float?)((int)(f * 100))) / 100;
                    }
                    //a_sqlServer.ExePROCNonQuery("MessageReceipt", ConvertToSqlParameters("601", inventoryHead.orderNo, logisticsNo, "0", "", inventoryHead.copNo, "", ""));
                }
            }
            catch (Exception ex)
            {
                Logs.Error("Query601DataByOrderNo Exception:" + ex.ToString());
            }
            finally
            {
                dr.Close();
            }
        }
        public string Post(string InventoryDate, string InventoryNo)
        {
            try
            {
                InventoryHead Inventory    = _db.InventoryHead.Where(e => e.InventoryNo == InventoryNo && e.InventoryDate == InventoryDate).FirstOrDefault();
                string        InventoryMan = (from a in _db.InventoryBody.Where(e => e.InventoryNo == InventoryNo) select new { a.InventoryMan }).First().InventoryMan;
                if (Inventory.IsSummary == "N" || Inventory.IsSummary == "0")
                {
                    //應盤項目
                    var Should = (from a in _db.vRecords
                                  join b in (from w in _db.InventoryBody.Where(e => e.InventoryNo == InventoryNo)
                                             group w by new { w.StockNo } into Stock
                                             select new
                    {
                        Stock.Key.StockNo
                    })
                                  on a.WarehouseNo equals b.StockNo
                                  join c in _db.PackingLists
                                  on a.BagNo equals c.BagNo
                                  select new
                    {
                        a.BagNo,
                        c.CaseNo,
                        c.PalletsNo,
                        a.Lot,
                        StockNo = a.WarehouseNo
                    }).Distinct().ToList();
                    //實盤項目
                    var Actual = (from a in _db.InventoryBody.Where(e => e.InventoryNo == InventoryNo)

                                  select new
                    {
                        a.BagNo,
                        a.CaseNo,
                        a.PalletsNo,
                        a.Lot,
                        a.StockNo
                    }).ToList();

                    var Loss = Should.Except(Actual);
                    List <InventoryAdjust> LossAdj = (from a in Loss
                                                      select new InventoryAdjust
                    {
                        InventoryNo = InventoryNo,
                        BagNo = a.BagNo,
                        CaseNo = a.CaseNo,
                        PalletsNo = a.PalletsNo,
                        Lot = a.Lot,
                        StockNo = a.StockNo,
                        OriQty = 1,
                        InventoryQty = 0,
                        AdjQty = 1,
                        InventoryDate = Inventory.InventoryDate,
                        InventoryTime = Inventory.InventoryTime,
                        InventoryMan = InventoryMan
                    }).ToList();

                    var Surplus = Actual.Except(Should);
                    List <InventoryAdjust> SurplusAdj = (from b in Surplus
                                                         select new InventoryAdjust
                    {
                        InventoryNo = InventoryNo,
                        BagNo = b.BagNo,
                        CaseNo = b.CaseNo,
                        PalletsNo = b.PalletsNo,
                        Lot = b.Lot,
                        StockNo = b.StockNo,
                        OriQty = 0,
                        InventoryQty = 1,
                        AdjQty = 1,
                        InventoryDate = Inventory.InventoryDate,
                        InventoryTime = Inventory.InventoryTime,
                        InventoryMan = InventoryMan,
                    }).ToList();
                    using (var dbContextTransaction = _db.Database.BeginTransaction())
                    {
                        try
                        {
                            foreach (InventoryAdjust Insert_loss in LossAdj)
                            {
                                _db.InventoryAdjust.Add(Insert_loss);
                            }
                            foreach (InventoryAdjust Insert_loss in SurplusAdj)
                            {
                                _db.InventoryAdjust.Add(Insert_loss);
                            }
                            Inventory.IsSummary = "Y";
                            _db.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            dbContextTransaction.Rollback();
                            return(ex.Message);
                        }
                    }
                }
                else
                {
                    return("盤點底稿-" + InventoryNo + "已彙總,無法再彙總!");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return("success");
        }