示例#1
0
        public void ConectionNav()
        {
            string codeSucursal = "";

            //Datos Sucursal
            GetCodeSucursal(ref codeSucursal);
            DataTable salesdetailtable = new DataTable();
            DataTable SalesHeader      = new DataTable();

            // Create Service Reference
            WS_NAV.SalesOrder_Service service = new WS_NAV.SalesOrder_Service();
            string            userconfigsfile = System.Configuration.ConfigurationManager.AppSettings["UserNav"];
            string            passconfigsfile = System.Configuration.ConfigurationManager.AppSettings["PasswordNav"];
            string            CustomerCodeNAV = System.Configuration.ConfigurationManager.AppSettings["customercode"];
            NetworkCredential Creden          = new NetworkCredential(userconfigsfile, passconfigsfile);

            service.Credentials = Creden;
            //service.UseDefaultCredentials = true;
            bool Navsyn = false;

            test2110.Credentials = Creden;
            foreach (DataGridViewRow rows in SalesSync2.Rows)
            {
                bool   SalesHeaderRegCorrect = false;
                string roowbool = rows.Cells[5].Value.ToString();
                if (roowbool != "")
                {
                    Navsyn = bool.Parse(roowbool);
                }
                // Create the Order header
                if (Navsyn)
                {
                    if (CheckAccessNet())
                    {
                        SalesOrder newOrder = new SalesOrder();

                        // Update Order header

                        try
                        {
                            newOrder.Status = WS_NAV.Status.Open;
                            string DocExtern = "";

                            service.Create(ref newOrder);

                            newOrder.Sell_to_Customer_No = CustomerCodeNAV;
                            SalesHeader.Clear();
                            SalesHeader = GetSalesHeader(rows);
                            DateTime DateReg = new DateTime();
                            #region salesheader
                            foreach (DataRow rowss in SalesHeader.Rows)
                            {
                                string dateregsales = rowss[0].ToString();
                                DateReg   = DateTime.ParseExact(dateregsales, "MM/dd/yyyy", null);
                                DocExtern = rowss[2].ToString();
                            }
                            #endregion

                            newOrder.External_Document_No = DocExtern;
                            newOrder.Document_Date        = DateReg;
                            //Detalles de linea
                            salesdetailtable.Clear();
                            salesdetailtable = GetSalesHeaderDetail(rows);

                            int lines = Convert.ToInt32(salesdetailtable.Rows.Count.ToString());
                            WS_NAV.Sales_Order_Line[] SalesOrderLines = new Sales_Order_Line[lines];
                            //Llenar lineas venta
                            int     salesline = 1000;
                            int     line      = 0;
                            decimal quantity  = 0M;
                            if (CheckAccessNet())
                            //bool linesCorrects = false;
                            #region DetailLines
                            {
                                foreach (DataRow row in salesdetailtable.Rows)
                                {
                                    //Sales Lines NAV
                                    SalesOrderLines[line] = new Sales_Order_Line();
                                    quantity = Convert.ToDecimal(row[1].ToString());
                                    SalesOrderLines[line].Line_No       = salesline;
                                    SalesOrderLines[line].Type          = WS_NAV.Type.Item;
                                    SalesOrderLines[line].TypeSpecified = true;
                                    string codeItemNo = test2110.GetNoItem(row[0].ToString());
                                    SalesOrderLines[line].No = codeItemNo;
                                    SalesOrderLines[line].Cross_Reference_No   = row[0].ToString();
                                    SalesOrderLines[line].Document_No          = newOrder.No;
                                    SalesOrderLines[line].Location_Code        = codeSucursal;
                                    SalesOrderLines[line].Quantity             = quantity;
                                    SalesOrderLines[line].QuantitySpecified    = true;
                                    SalesOrderLines[line].Unit_of_Measure_Code = row[2].ToString();
                                    newOrder.SalesLines = SalesOrderLines;
                                    salesline          += 1000;
                                    line++;
                                }
                            }
                            #endregion
                            service.Update(ref newOrder);
                            //Actualizar datos de facturacion
                            if (CheckAccessNet())
                            {
                                bool allcorrect = false;
                                if (CheckAccessNet())
                                {
                                    service.Update(ref newOrder);
                                    allcorrect = service.IsUpdated(newOrder.Key);
                                }

                                if ((allcorrect == false) && (CheckAccessNet()))
                                {
                                    SalesHeaderRegCorrect = test2110.Registrar2(newOrder.No);
                                    if (SalesHeaderRegCorrect)
                                    {
                                        UpdeteSalesHeader(rows);
                                    }
                                    else
                                    {
                                        errors++;
                                    }
                                }
                            }
                        }
                        catch (SqlException sqlex)
                        {
                            MessageBox.Show(sqlex.Message);
                        }
                        catch (HttpListenerException httpex)
                        {
                            MessageBox.Show(httpex.Message);
                        }
                        catch (TimeoutException timex)
                        {
                            MessageBox.Show(timex.Message);
                        }
                        catch (WebException wex)
                        {
                            MessageBox.Show(wex.Message);
                            bool noconec = false;
                            do
                            {
                                ErrorConectionSync();
                                noconec = CheckAccessNet();
                            } while (noconec == false);

                            MessageBox.Show("El registro no se se sincronizo" + Environment.NewLine, "Vulva a sincronizar el registro faltante");
                            if (newOrder.Key != null)
                            {
                                //service.Update(ref newOrder);
                                test2110.Credentials = Creden;
                                if (newOrder.No != null)
                                {
                                    bool access = CheckAccessNet();
                                    if (access)
                                    {
                                        test2110.DeleteBadPost(newOrder.No);
                                    }
                                }
                                //service.Delete(newOrder.Key);
                            }
                            errors++;
                        }
                    }
                    else
                    {
                        ErrorConection();
                        break;
                    }
                }
                ProgressSyncNav.PerformStep();
            }
        }
示例#2
0
        private static void CreateNAVSalesOrder()
        {
            //Here we have to call our NAV web service for creating a Sales Order
            //Web Service instantiation
            SalesOrder_Service ws = new SalesOrder_Service();

            ws.Url = Properties.Settings.Default.NAVWSURL;
            ws.UseDefaultCredentials = true;

            //Create the Sales Header
            SalesOrder order = new SalesOrder();

            ws.Create(ref order);

            //Here the Sales Order is created and we have the order no.


            //Update the Sales Header with details
            order.Sell_to_Customer_No = "10000";
            order.Order_Date          = DateTime.Now;
            //order.Activity_Code = "123458";

            //Create the Sales Lines array and initialize the lines
            order.SalesLines = new Sales_Order_Line[2];
            for (int i = 0; i < 2; i++)
            {
                order.SalesLines[i] = new Sales_Order_Line();
            }

            ws.Update(ref order);

            //List<Sales_Order_Line> lines = new List<Sales_Order_Line>();

            //First line
            //Sales_Order_Line line = new Sales_Order_Line();
            Sales_Order_Line line = order.SalesLines[0];

            line.Type     = NAVWS.Type.Item;
            line.No       = "1000";
            line.Quantity = 5;

            //Add the line to the order lines collection
            //lines.Add(line);

            //Second line
            //line = new Sales_Order_Line();
            line          = order.SalesLines[1];
            line.Type     = NAVWS.Type.Item;
            line.No       = "1001";
            line.Quantity = 10;

            //Add the line to the order lines collection
            //lines.Add(line);

            //Add the lines to the order
            //order.SalesLines = lines.ToArray();

            //Update the order lines with all the informations
            ws.Update(ref order);

            Console.WriteLine("Order {0} created successfully.", order.No);
        }
        public void CreateNAVSalesOrder(ShopSalesOrder ExternalOrder)
        {
            try
            {
                //Here we have to call our NAV web service for creating a Sales Order
                //Web Service instantiation
                SalesOrder_Service ws = new SalesOrder_Service();
                ws.Url = Properties.Settings.Default.NAVWSURL;
                ws.UseDefaultCredentials = true;

                //Create the Sales Header
                SalesOrder order = new SalesOrder();
                ws.Create(ref order);

                //Here the Sales Order is created and we have the order no.

                //Update the Sales Header with details
                order.Sell_to_Customer_No = ExternalOrder.CustomerNo;
                order.Order_Date          = ExternalOrder.OrderDate;
                order.Activity_Code       = "123458";

                int _rows = 0;
                if (ExternalOrder.Lines != null)
                {
                    _rows = ExternalOrder.Lines.Count();
                }

                if (_rows > 0)
                {
                    //Create the Sales Lines array and initialize the lines
                    order.SalesLines = new Sales_Order_Line[_rows];
                    for (int i = 0; i < _rows; i++)
                    {
                        order.SalesLines[i] = new Sales_Order_Line();
                    }
                }

                ws.Update(ref order);

                //Loads the data into the Lines
                if (_rows > 0)
                {
                    int rowindex = 0;
                    foreach (ShopSalesOrderLine _shopOrderLine in ExternalOrder.Lines)
                    {
                        Sales_Order_Line line = order.SalesLines[rowindex];
                        line.Type     = NAVSalesOrderWS.Type.Item;
                        line.No       = _shopOrderLine.ItemNo;
                        line.Quantity = _shopOrderLine.Quantity;
                        rowindex++;
                    }

                    //Update the order lines with all the informations
                    ws.Update(ref order);
                }

                Console.WriteLine("Order {0} created successfully.", order.No);
            }
            catch (Exception)
            {
                //Handle exceptions here...
            }
        }