Exemplo n.º 1
0
        public OrderGoodsResult GetFreshFoods(string ekOrg, string ekGrp, string werks, string buDat, string perNo)
        {
            ManageOrderOfferProgramInClient soapClient = new ManageOrderOfferProgramInClient();

            soapClient.ClientCredentials.UserName.UserName = System.Configuration.ConfigurationManager.AppSettings["SAP_WEBSERVICE_USERNAME"];
            soapClient.ClientCredentials.UserName.Password = System.Configuration.ConfigurationManager.AppSettings["SAP_WEBSERVICE_PASSWORD"];

            int year;
            int month;
            int day;

            int.TryParse(buDat.Substring(0, 4), out year);
            int.TryParse(buDat.Substring(4, 2), out month);
            int.TryParse(buDat.Substring(6, 2), out day);

            DateTime dt = new DateTime(year, month, day);

            FreshFoodOrderQuery_sync typeMParam = new FreshFoodOrderQuery_sync()
            {
                EKGRP          = ekGrp,
                WERKS          = werks,
                BUDAT          = dt,
                BUDATSpecified = true,
                PERNO          = perNo,
                ZTYPE          = "M"
            };

            FreshFoodOrderResponse_sync typeMResult = soapClient.FreshFoodOrderQueryResponse_In(typeMParam);
            ////FreshFoodOrder typeMFreshFoodOrder = new FreshFoodOrder();
            ////typeMFreshFoodOrder.E_SUBRC = typeMResult.Flag; // 0 정상, 4 에러
            ////typeMFreshFoodOrder.E_ZTEXT = typeMResult.ReturnMessage;

            //if (typeMResult.Flag == "E" || typeMResult.Flag == "4")
            //    throw new Exception(typeMResult.ReturnMessage);
            //// second call
            FreshFoodOrderQuery_sync typeAParam = new FreshFoodOrderQuery_sync()
            {
                EKGRP                   = ekGrp,
                WERKS                   = werks,
                BUDAT                   = dt,
                BUDATSpecified          = true,
                PERNO                   = perNo,
                ZTYPE                   = "A",
                MATNRFreshFoodOrderList = typeMResult.MATNRFreshFoodOrderList
            };

            FreshFoodOrderResponse_sync typeAResult = soapClient.FreshFoodOrderQueryResponse_In(typeAParam);

            //if (typeAResult.Flag == "E" || typeAResult.Flag == "4")
            //    throw new Exception(typeAResult.ReturnMessage);

            QueryMaterialPriceInfoClient client = new QueryMaterialPriceInfoClient();

            client.ClientCredentials.UserName.UserName = System.Configuration.ConfigurationManager.AppSettings["SAP_WEBSERVICE_USERNAME"];
            client.ClientCredentials.UserName.Password = System.Configuration.ConfigurationManager.AppSettings["SAP_WEBSERVICE_PASSWORD"];

            List <Matnr> matnrList = new List <Matnr>();
            MaterialVendorInfoQuery_sync mParam           = null;
            OrderGoodsResult             orderGoodsResult = new OrderGoodsResult();
            List <OrderGoods>            orderGoodsList   = new List <OrderGoods>();
            OrderGoods goods = null;
            MaterialVendorInfoResponse_sync q = null;

            orderGoodsResult.Flag          = typeAResult.Flag;
            orderGoodsResult.ReturnMessage = typeAResult.ReturnMessage;
            orderGoodsResult.orderGoods    = new List <OrderGoods>();

            if (typeAResult.FreshFoodOrderList != null)
            {
                foreach (var item in typeAResult.FreshFoodOrderList)
                {
                    goods = new OrderGoods();

                    goods.LIFNR = item.LIFNR;
                    goods.MATNR = item.MATNR;
                    goods.MAKTX = item.MAKTX;
                    goods.MENGE = item.MENGE;
                    goods.UMREZ = item.UMREZ;
                    ////goods.LFDAT = item.LFDAT.ToString("MMdd");
                    goods.LFDAT = item.LFDAT;
                    goods.NETPR = item.NETPR;
                    goods.LABST = item.LABST;

                    goods.ICON  = item.ICON;
                    goods.ICON1 = item.ICON1;

                    goods.NAME1 = item.NAME1;

                    goods.MEINS = item.MEINS;
                    goods.WAKFG = item.WAKFG;
                    goods.MSTAE = item.MSTAE;
                    goods.TDYMG = item.TDYMG;
                    goods.MENG1 = item.MENG1;
                    goods.MENG2 = item.MENG2;
                    goods.MENG3 = item.MENG3;
                    goods.MENG0 = item.MENG0;

                    goods.TNETPR = item.TNETPR;
                    goods.BANFN  = item.BANFN;
                    goods.EBELN1 = item.EBELN1;
                    goods.REMARK = item.REMARK;
                    goods.LQTY7  = item.LQTY7;
                    goods.LQTY6  = item.LQTY6;
                    goods.LQTY5  = item.LQTY5;
                    goods.LQTY4  = item.LQTY4;
                    goods.LQTY3  = item.LQTY3;
                    goods.WEQTY  = item.WEQTY;
                    goods.YEQTY  = item.YEQTY;
                    goods.TOQTY  = item.TOQTY;

                    goods.TOTAL = item.TOTAL;
                    goods.EISBE = item.EISBE;
                    goods.DDATE = item.DDATE;
                    goods.WERKS = item.WERKS;
                    goods.EKGRP = item.EKGRP;

                    foreach (var matnr in typeAResult.MATNRFreshFoodOrderList)
                    {
                        if (item.MATNR == matnr.MATNR)
                        {
                            mParam       = new MaterialVendorInfoQuery_sync();
                            mParam.EKORG = ekOrg;
                            mParam.MATNR = matnr.MATNR;

                            matnrList = new List <Matnr>();
                            q         = client.MaterialVendorInfoQueryResponse_In(mParam);

                            foreach (var innerItem in q.MaterialVendorList)
                            {
                                matnrList.Add(new Matnr()
                                {
                                    MATNR   = innerItem.MATNR,
                                    LIFNR_N = string.Format("{0}-{1}", innerItem.LIFNR_N, innerItem.LIFNR),
                                    LIFNR   = innerItem.LIFNR
                                });
                            }

                            break;
                        }
                    }

                    goods.MATNRLIST = matnrList;

                    orderGoodsList.Add(goods);
                }
            }
            orderGoodsResult.orderGoods = orderGoodsList;

            return(orderGoodsResult);
        }