示例#1
0
        private IList <Product> GetProducts(string sWhere)
        {
            Product         tmpData  = null;
            IList <Product> list     = new List <Product>();
            IList <Unit>    unitList = GetAllUnits();
            IList <Unit>    curList  = unitList;
            Unit            curUnit;
            ProductCategory curCategory;
            string          flag = "";


            try
            {
                //Lamar los documents que necesita del Erp usando econnect
                //sWhere = string.IsNullOrEmpty(sWhere) ? "ITEMTYPE=1" : "ITEMTYPE=1 AND " + sWhere;

                ds = DynamicsGP_ec.GetDataSet(DynamicsGP_ec.RetreiveData("Item", false, 2, 0, sWhere, true));

                Console.WriteLine(ds.Tables.Count.ToString());

                if (ds.Tables.Count == 0)
                {
                    return(list);
                }

                //Company company = WType.GetDefaultCompany();
                //Status status = WType.GetStatus(new Status { StatusID = EntityStatus.Active });

                //En el dataset, Tables: 1 - Item
                foreach (DataRow dr in ds.Tables[1].Rows)
                {
                    try
                    {
                        //Map Properties
                        tmpData = new Product();

                        flag = "BASE";

                        tmpData.Company     = CurCompany;
                        tmpData.Name        = dr["ITEMDESC"].ToString();
                        tmpData.ProductCode = dr["ITEMNMBR"].ToString();
                        tmpData.Description = dr["ITEMDESC"].ToString();
                        tmpData.IsKit       = (dr["ITEMTYPE"].ToString() == "4") ? true : false;
                        tmpData.ErpTrackOpt = short.Parse(dr["ITMTRKOP"].ToString());

                        tmpData.Manufacturer = dr["ITMSHNAM"].ToString();
                        tmpData.Reference    = dr["ITMGEDSC"].ToString();


                        try { tmpData.CountRank = short.Parse(dr["ABCCODE"].ToString()); }
                        catch { }

                        try { tmpData.ProductCost = double.Parse(dr["CURRCOST"].ToString()); }
                        catch { }

                        tmpData.Status = GetProductStatus(int.Parse(dr["ITEMTYPE"].ToString()));
                        try { tmpData.Weight = double.Parse(dr["ITEMSHWT"].ToString()) / 100; }
                        catch { }

                        //Basic Unit
                        flag                 = "BASEUNIT";
                        curUnit              = new Unit();
                        curUnit.Company      = CurCompany;
                        curUnit.ErpCodeGroup = dr["UOMSCHDL"].ToString();
                        curUnit.BaseAmount   = 1;
                        tmpData.BaseUnit     = WType.GetUnit(curUnit);
                        tmpData.IsFromErp    = true;
                        tmpData.PrintLabel   = true;


                        //Product Category
                        if (!string.IsNullOrEmpty(dr["ITMCLSCD"].ToString()))
                        {
                            flag = "CATEGORY";
                            try
                            {
                                curCategory         = new ProductCategory();
                                curCategory.Company = CurCompany;
                                curCategory.ErpCode = dr["ITMCLSCD"].ToString();
                                tmpData.Category    = WType.GetProductCategory(curCategory);
                            }
                            catch { }
                        }

                        //Purchase Units
                        if (!string.IsNullOrEmpty(dr["PRCHSUOM"].ToString()))
                        {
                            try
                            {
                                curUnit              = new Unit();
                                curUnit.Company      = CurCompany;
                                curUnit.ErpCodeGroup = dr["UOMSCHDL"].ToString();
                                curUnit.ErpCode      = dr["PRCHSUOM"].ToString();
                                tmpData.PurchaseUnit = WType.GetUnit(curUnit);
                            }
                            catch { }
                        }

                        //Sale Unit
                        if (!string.IsNullOrEmpty(dr["SELNGUOM"].ToString()))
                        {
                            try
                            {
                                curUnit              = new Unit();
                                curUnit.Company      = CurCompany;
                                curUnit.ErpCodeGroup = dr["UOMSCHDL"].ToString();
                                curUnit.ErpCode      = dr["SELNGUOM"].ToString();
                                tmpData.SaleUnit     = WType.GetUnit(curUnit);
                            }
                            catch { }
                        }

                        //Obteniendo las unidades que ese producto puede tener
                        flag    = "UNITLIST";
                        curList = unitList.Where(unit => unit.ErpCodeGroup == dr["UOMSCHDL"].ToString()).ToList();

                        flag = "PRODUCT_TRACK";
                        tmpData.ProductTrack = GetProductTrack(int.Parse(dr["ITMTRKOP"].ToString()), tmpData);

                        flag = "PRODUCT_UNITS";
                        tmpData.ProductUnits = GetProductUnits(tmpData, curList);

                        flag = "VENDORS";
                        tmpData.ProductAccounts = GetProductVendors(tmpData);

                        //Productos Alternos.
                        flag = "ALTERN";
                        try
                        {
                            tmpData.AlternProducts = GetAlternateProducts(tmpData, dr["ALTITEM1"].ToString().Trim(),
                                                                          dr["ALTITEM2"].ToString().Trim());
                        }
                        catch (Exception ex) { Console.WriteLine(flag + " " + ex.Message); }

                        list.Add(tmpData);
                    }
                    catch (Exception ex) {
                        Console.WriteLine(flag + " " + ex.Message);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetProducts" + tmpData.ProductCode + "," + flag, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
示例#2
0
        private IList <DocumentLine> GetReceivingDocumentLines(Document doc, Company company, DataRow[] dLines)
        {
            DocumentLine         tmpData;
            IList <DocumentLine> list = new List <DocumentLine>();
            //Status lineStatus = WType.GetStatus(new Status { StatusID = DocStatus.New });

            int    curLine   = 0;
            string curMaster = "";

            try
            {
                foreach (DataRow dr in dLines)
                {
                    tmpData       = new DocumentLine();
                    tmpData.Date1 = doc.Date1;
                    curMaster     = "";

                    tmpData.Date2       = DateTime.Parse(dr["REQDATE"].ToString());
                    tmpData.Date3       = DateTime.Parse(dr["PRMSHPDTE"].ToString());
                    tmpData.Date4       = DateTime.Parse(dr["PRMDATE"].ToString());
                    tmpData.LineNumber  = int.Parse(dr["ORD"].ToString());
                    tmpData.AccountItem = dr["VNDITNUM"].ToString();
                    tmpData.Sequence    = tmpData.LineNumber;

                    curLine              = tmpData.LineNumber;
                    tmpData.Document     = doc;
                    tmpData.IsDebit      = false;
                    tmpData.Quantity     = double.Parse(dr["QTYORDER"].ToString(), ListValues.DoubleFormat());
                    tmpData.QtyCancel    = double.Parse(dr["QTYCANCE"].ToString(), ListValues.DoubleFormat());
                    tmpData.QtyPending   = double.Parse(dr["QTYUNCMTBASE"].ToString(), ListValues.DoubleFormat());
                    tmpData.CreatedBy    = WmsSetupValues.SystemUser;
                    tmpData.CreationDate = DateTime.Now;

                    curMaster          = "Status:" + dr["POLNESTA"].ToString();
                    tmpData.LineStatus = GetReceivingStatus(int.Parse(dr["POLNESTA"].ToString())); //doc.DocStatus;
                    curMaster          = "Location:" + dr["LOCNCODE"].ToString();
                    tmpData.Location   = WType.GetLocation(new Location {
                        Company = company, ErpCode = dr["LOCNCODE"].ToString()
                    });

                    try
                    {
                        curMaster       = "Product:" + dr["ITEMNMBR"].ToString();
                        tmpData.Product = WType.GetProduct(new Product {
                            Company = company, ProductCode = dr["ITEMNMBR"].ToString()
                        });
                        tmpData.LineDescription = dr["ITEMDESC"].ToString();

                        curMaster    = "Uom:" + dr["UOFM"].ToString();
                        tmpData.Unit = WType.GetUnit(new Unit {
                            ErpCode = dr["UOFM"].ToString(), ErpCodeGroup = tmpData.Product.BaseUnit.ErpCodeGroup
                        });
                    }
                    catch (Exception ex)
                    {
                        ExceptionMngr.WriteEvent("GetReceiptDocumentLines: " + doc.DocNumber + "," + curLine.ToString() + "," + curMaster,
                                                 ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                        continue;

                        //    //Pone el Default Product
                        //    tmpData.Product = WType.GetProduct(new Product { Company = company, ProductCode = WmsSetupValues.DEFAULT });
                        //    tmpData.LineDescription = "Unknown: " + dr["ITEMNMBR"].ToString() + ", " + dr["ITEMDESC"].ToString();

                        //    curMaster = "Uom:" + dr["UOFM"].ToString();
                        //    tmpData.Unit = WType.GetUnit(new Unit { ErpCode = dr["UOFM"].ToString() });
                    }

                    //Unit - Price, Cost
                    tmpData.UnitCost     = double.Parse(dr["UNITCOST"].ToString(), ListValues.DoubleFormat());
                    tmpData.ExtendedCost = double.Parse(dr["EXTDCOST"].ToString(), ListValues.DoubleFormat());

                    //SOP POP Link
                    object[] sop_popLink = GetSOP_POPLink(doc.DocNumber, tmpData.LineNumber, doc.DocType.DocTypeID);
                    if (sop_popLink != null)
                    {
                        tmpData.LinkDocNumber     = sop_popLink[0].ToString();
                        tmpData.LinkDocLineNumber = int.Parse(sop_popLink[1].ToString());
                    }


                    list.Add(tmpData);
                }

                return((list.Count > 0) ? list : null);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetReceiptDocumentLines: " + doc.DocNumber + "," + curLine.ToString() + "," + curMaster,
                                         ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
示例#3
0
        private IList <Product> GetProducts(string sWhere)
        {
            Product         tmpData  = null;
            IList <Product> list     = new List <Product>();
            IList <Unit>    unitList = GetAllUnits();
            IList <Unit>    curList  = unitList;
            Unit            curUnit;
            ProductCategory curCategory;
            string          flag   = "";
            Status          active = WType.GetStatus(new Status {
                StatusID = EntityStatus.Active
            });

            try
            {
                Command.Connection = new SqlConnection(CurCompany.ErpConnection.CnnString);

                Query = "select i.ITEMNO,i.DESCRIPT,i.CATEGORY, i.MATRIX_ITEM_TYPE,i.SERIALIZE,i.FORCE_LOT,i.LINK_SERIAL, i.COST, 'EACH' as SALEUNIT,'EACH' as PURCHUNIT, isNull(m.DESCRIPT,'') AS Manuf " +
                        " from items i LEFT OUTER JOIN MANUFACT m ON i.MANUCODE = m.code where i.ACTIVE ='T' "; // AND m.ACTIVE ='T'

                ds = ReturnDataSet(Query, sWhere, "items", Command.Connection);

                Console.WriteLine(ds.Tables.Count.ToString());

                if (ds == null || ds.Tables.Count == 0)
                {
                    return(null);
                }

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    try
                    {
                        //Map Properties
                        tmpData = new Product();

                        flag = "BASE";

                        tmpData.Company     = CurCompany;
                        tmpData.Name        = dr["DESCRIPT"].ToString();
                        tmpData.ProductCode = dr["ITEMNO"].ToString();
                        tmpData.Description = dr["DESCRIPT"].ToString();
                        tmpData.IsKit       = (dr["MATRIX_ITEM_TYPE"].ToString() == "3") ? true : false;

                        // CAA ????
                        tmpData.ErpTrackOpt  = IsTrackOpt(dr["FORCE_LOT"].ToString(), dr["SERIALIZE"].ToString());
                        tmpData.Manufacturer = dr["Manuf"].ToString();
                        // tmpData.Reference = dr["f120_rowid"].ToString();

                        /*
                         * try { tmpData.CountRank = ;
                         * catch { }
                         */

                        // ???   AVG_COST ???
                        try { tmpData.ProductCost = double.Parse(dr["COST"].ToString()); }
                        catch { }

                        tmpData.Status = active;
                        //tmpData.Status = GetProductStatus(int.Parse(dr["ITEMTYPE"].ToString()));

                        /*
                         * try { tmpData.Weight = double.Parse(dr["ITEMSHWT"].ToString()) / 100; }
                         * catch { }
                         * // ???
                         */

                        //Basic Unit
                        flag                 = "BASEUNIT";
                        curUnit              = new Unit();
                        curUnit.Company      = CurCompany;
                        curUnit.ErpCodeGroup = WmsSetupValues.DEFAULT;
                        curUnit.BaseAmount   = 1;
                        try
                        {
                            tmpData.BaseUnit = WType.GetUnit(curUnit);
                        }
                        catch { }
                        tmpData.IsFromErp  = true;
                        tmpData.PrintLabel = true;


                        //Product Category
                        if (!string.IsNullOrEmpty(dr["CATEGORY"].ToString()))
                        {
                            flag = "CATEGORY";
                            try
                            {
                                curCategory         = new ProductCategory();
                                curCategory.Company = CurCompany;
                                curCategory.ErpCode = dr["CATEGORY"].ToString();
                                tmpData.Category    = WType.GetProductCategory(curCategory);
                            }
                            catch { }
                        }

                        //Purchase Units
                        try
                        {
                            curUnit              = new Unit();
                            curUnit.Company      = CurCompany;
                            curUnit.ErpCodeGroup = WmsSetupValues.DEFAULT;
                            curUnit.ErpCode      = dr["PURCHUNIT"].ToString();
                            tmpData.PurchaseUnit = WType.GetUnit(curUnit);
                        }
                        catch { }


                        //Sale Unit
                        try
                        {
                            curUnit              = new Unit();
                            curUnit.Company      = CurCompany;
                            curUnit.ErpCodeGroup = WmsSetupValues.DEFAULT;
                            curUnit.ErpCode      = dr["SALEUNIT"].ToString();
                            tmpData.SaleUnit     = WType.GetUnit(curUnit);
                        }
                        catch { }

                        //Obteniendo las unidades que ese producto puede tener
                        flag    = "UNITLIST";
                        curList = unitList;  // .Where(unit => unit.ErpCodeGroup == dr["f120_id_unidad_inventario"].ToString()).ToList();

                        flag = "PRODUCT_TRACK";
                        tmpData.ProductTrack = GetProductTrack(tmpData.ErpTrackOpt, tmpData);

                        flag = "PRODUCT_UNITS";
                        tmpData.ProductUnits = GetProductUnits(tmpData, curList);

                        // CAA ??
                        flag = "VENDORS";
                        tmpData.ProductAccounts = GetProductVendors(tmpData);

                        // CAA ???
                        //Productos Alternos.

                        /*
                         * flag = "ALTERN";
                         * try
                         * {
                         *  tmpData.AlternProducts = GetAlternateProducts(tmpData);
                         * }
                         * catch (Exception ex) { Console.WriteLine(flag + " " + ex.Message); }
                         */

                        list.Add(tmpData);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(flag + " " + ex.Message);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetProducts" + tmpData.ProductCode + "," + flag, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
        private IList <DocumentLine> GetReceivingDocumentLines(Document doc, Company company, string docID)
        {
            DocumentLine         tmpData;
            IList <DocumentLine> list = new List <DocumentLine>();
            //Status lineStatus = WType.GetStatus(new Status { StatusID = DocStatus.New });

            int    curLine   = 0;
            string curMaster = "";

            try
            {
                Query = GetErpQuery("PURCHASEORDER_LINE").Replace("__DOCUMENT", docID);

                DataSet ds = ReturnDataSet(Query, null, "PURCHASEORDER_LINE", Command.Connection);

                if (ds == null || ds.Tables.Count == 0)
                {
                    return(null);
                }



                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    tmpData       = new DocumentLine();
                    tmpData.Date1 = doc.Date1;
                    curMaster     = "";

                    try { tmpData.Date2 = DateTime.Parse(dr["f421_fecha_entrega"].ToString()); }
                    catch { }

                    //tmpData.Date3 = DateTime.Parse(dr["PRMSHPDTE"].ToString());
                    //tmpData.Date4 = DateTime.Parse(dr["PRMDATE"].ToString());
                    tmpData.LineNumber  = int.Parse(dr["f421_rowid"].ToString());
                    tmpData.AccountItem = dr["f421_cod_item_prov"].ToString();
                    tmpData.Sequence    = tmpData.LineNumber;

                    curLine          = tmpData.LineNumber;
                    tmpData.Document = doc;
                    tmpData.IsDebit  = false;
                    tmpData.Quantity = double.Parse(dr["f421_cant_pedida"].ToString(), new NumberFormatInfo {
                        NumberDecimalSeparator = Separator
                    });
                    tmpData.UnitBaseFactor = double.Parse(dr["fact_adicional"].ToString(), new NumberFormatInfo {
                        NumberDecimalSeparator = Separator
                    });


                    tmpData.CreatedBy    = WmsSetupValues.SystemUser;
                    tmpData.CreationDate = DateTime.Now;

                    curMaster          = "Status:" + dr["f421_ind_estado"].ToString();
                    tmpData.LineStatus = GetReceivingStatus(int.Parse(dr["f421_ind_estado"].ToString())); //doc.DocStatus;

                    curMaster        = "Location:" + dr["cod_bodega"].ToString();
                    tmpData.Location = WType.GetLocation(new Location {
                        Company = company, ErpCode = dr["cod_bodega"].ToString()
                    });

                    try
                    {
                        curMaster       = "Product:" + dr["f121_rowid_item"].ToString();
                        tmpData.Product = WType.GetProduct(new Product {
                            Company = company, ProductCode = dr["f121_rowid_item"].ToString()
                        });
                        tmpData.LineDescription = dr["f120_descripcion"].ToString();

                        curMaster    = "Uom:" + dr["f421_id_unidad_medida"].ToString();
                        tmpData.Unit = WType.GetUnit(new Unit {
                            ErpCode = dr["f421_id_unidad_medida"].ToString(), ErpCodeGroup = tmpData.Product.BaseUnit.ErpCodeGroup
                        });
                    }
                    catch (Exception ex)
                    {
                        ExceptionMngr.WriteEvent("GetReceiptDocumentLines: " + doc.DocNumber + "," + curLine.ToString() + "," + curMaster,
                                                 ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                        continue;

                        //    //Pone el Default Product
                        //    tmpData.Product = WType.GetProduct(new Product { Company = company, ProductCode = WmsSetupValues.DEFAULT });
                        //    tmpData.LineDescription = "Unknown: " + dr["ITEMNMBR"].ToString() + ", " + dr["ITEMDESC"].ToString();

                        //    curMaster = "Uom:" + dr["UOFM"].ToString();
                        //    tmpData.Unit = WType.GetUnit(new Unit { ErpCode = dr["UOFM"].ToString() });
                    }

                    //Unit - Price, Cost
                    tmpData.UnitPrice = double.Parse(dr["f421_precio_unitario"].ToString(), new NumberFormatInfo {
                        NumberDecimalSeparator = Separator
                    });
                    tmpData.ExtendedPrice = double.Parse(dr["subtotal"].ToString(), new NumberFormatInfo {
                        NumberDecimalSeparator = Separator
                    });

                    //SOP POP Link
                    //object[] sop_popLink = GetSOP_POPLink(doc.DocNumber, tmpData.LineNumber, doc.DocType.DocTypeID);
                    //if (sop_popLink != null)
                    //{
                    //    tmpData.LinkDocNumber = sop_popLink[0].ToString();
                    //    tmpData.LinkDocLineNumber = int.Parse(sop_popLink[1].ToString());
                    //}


                    list.Add(tmpData);
                }

                return((list.Count > 0) ? list : null);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetReceiptDocumentLines: " + doc.DocNumber + "," + curLine.ToString() + "," + curMaster,
                                         ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }
示例#5
0
        public IList <Label> CreateEmptyPackLabel(Location location, int numLabels, Product product, string printSession,
                                                  SysUser user)
        {
            Factory.IsTransactional = true;

            Node recNode = WType.GetNode(new Node {
                NodeID = NodeType.Stored
            });
            Status status = WType.GetStatus(new Status {
                StatusID = EntityStatus.Active
            });
            DocumentType labelType = WType.GetLabelType(new DocumentType {
                DocTypeID = LabelType.ProductLabel
            });
            Unit logisticUnit = WType.GetUnit(new Unit {
                Company = location.Company, Name = WmsSetupValues.CustomUnit
            });
            Bin destLocation = WType.GetBin(new Bin {
                Location = location, BinCode = DefaultBin.PUTAWAY
            });


            IList <Label> listLabel = new List <Label>();

            //Generate new logistig labels located in MAIN
            //Labels shouldbe activated the next transaction
            try {
                //Funcion para obtener siguiente Label
                //DocumentTypeSequence initSequence = GetNextDocSequence(location.Company, labelType);
                Label fatherLabel = null;

                for (int i = 0; i < (int)numLabels; i++)
                {
                    fatherLabel              = new Label();
                    fatherLabel.Node         = recNode;
                    fatherLabel.Bin          = destLocation;
                    fatherLabel.Product      = product;
                    fatherLabel.CreatedBy    = user.UserName;
                    fatherLabel.Status       = status;
                    fatherLabel.LabelType    = labelType;
                    fatherLabel.CreationDate = DateTime.Now;
                    fatherLabel.Printed      = false;

                    fatherLabel.Unit        = logisticUnit;
                    fatherLabel.IsLogistic  = false;
                    fatherLabel.FatherLabel = null;
                    fatherLabel.LabelCode   = ""; //(initSequence.NumSequence + i).ToString() + GetRandomHex(user.UserName, initSequence.NumSequence + i);
                    fatherLabel.CurrQty     = 0;
                    //Aqui guardan las logisitcas las hijas que contienen unas vez se imprimen
                    fatherLabel.StartQty    = 0;
                    fatherLabel.Notes       = "Empty Label";
                    fatherLabel.PrintingLot = printSession;
                    fatherLabel             = Factory.DaoLabel().Save(fatherLabel);

                    //Registra el movimiento del nodo
                    fatherLabel.LabelCode = fatherLabel.LabelID.ToString();

                    SaveNodeTrace(
                        new NodeTrace
                    {
                        Node      = recNode,
                        Document  = null,
                        Label     = fatherLabel,
                        Quantity  = fatherLabel.CurrQty,
                        IsDebit   = false,
                        CreatedBy = user.UserName
                    }
                        );

                    listLabel.Add(fatherLabel);
                }

                //Ajustando la sequencia
                //initSequence.NumSequence += numLabels;

                //Factory.DaoDocumentTypeSequence().Update(initSequence);

                Factory.Commit();

                return(listLabel);
            }
            catch (Exception ex)
            {
                Factory.Rollback();
                ExceptionMngr.WriteEvent("CreateEmptyLabel:", ListValues.EventType.Fatal, ex, null, ListValues.ErrorCategory.Business);
                throw new Exception(WriteLog.GetTechMessage(ex));
            }
        }
        private IList <Product> GetProducts(string sWhere)
        {
            Product         tmpData  = null;
            IList <Product> list     = new List <Product>();
            IList <Unit>    unitList = GetAllUnits();
            IList <Unit>    curList  = unitList;
            Unit            curUnit;
            ProductCategory curCategory;
            string          flag   = "";
            Status          active = WType.GetStatus(new Status {
                StatusID = EntityStatus.Active
            });

            try
            {
                Command.Connection = new SqlConnection(CurCompany.ErpConnection.CnnString);

                Query = GetErpQuery("ITEMS");

                ds = ReturnDataSet(Query, sWhere, "ITEMS", Command.Connection);

                Console.WriteLine(ds.Tables.Count.ToString());

                if (ds == null || ds.Tables.Count == 0)
                {
                    return(null);
                }

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    try
                    {
                        //Map Properties
                        tmpData = new Product();

                        flag = "BASE";

                        tmpData.Company = CurCompany;

                        //ID de la tabla t120_item
                        tmpData.ProductCode = dr["f120_id"].ToString();
                        tmpData.Name        = dr["f120_referencia"].ToString().Trim() + " - " + dr["f120_descripcion_corta"].ToString();
                        tmpData.Description = dr["f120_descripcion"].ToString();
                        tmpData.IsKit       = (dr["f120_ind_tipo_item"].ToString() == "3") ? true : false;

                        tmpData.ErpTrackOpt  = IsTrackOpt(dr["f120_ind_lote"].ToString(), dr["f120_ind_serial"].ToString());
                        tmpData.Manufacturer = "";

                        //ID de la tabla t121_item_ext
                        tmpData.UpcCode   = dr["extid"].ToString();
                        tmpData.Reference = dr["f120_referencia"].ToString();


                        tmpData.Status = active;

                        //Basic Unit
                        flag                 = "BASEUNIT";
                        curUnit              = new Unit();
                        curUnit.Company      = CurCompany;
                        curUnit.ErpCodeGroup = WmsSetupValues.DEFAULT; //dr["f120_id_unidad_inventario"].ToString();
                        curUnit.BaseAmount   = 1;
                        try
                        {
                            tmpData.BaseUnit = WType.GetUnit(curUnit);
                        }
                        catch { }
                        tmpData.IsFromErp  = true;
                        tmpData.PrintLabel = true;


                        //Product Category
                        if (!string.IsNullOrEmpty(dr["f120_id_tipo_inv_serv"].ToString()))
                        {
                            flag = "CATEGORY";
                            try
                            {
                                curCategory         = new ProductCategory();
                                curCategory.Company = CurCompany;
                                curCategory.ErpCode = dr["f120_id_tipo_inv_serv"].ToString();
                                tmpData.Category    = WType.GetProductCategory(curCategory);
                            }
                            catch { }
                        }

                        //Purchase Units
                        try
                        {
                            curUnit              = new Unit();
                            curUnit.Company      = CurCompany;
                            curUnit.ErpCodeGroup = WmsSetupValues.DEFAULT;
                            curUnit.ErpCode      = dr["f120_id_unidad_inventario"].ToString();
                            tmpData.PurchaseUnit = WType.GetUnit(curUnit);
                        }
                        catch { }


                        //Sale Unit
                        try
                        {
                            curUnit              = new Unit();
                            curUnit.Company      = CurCompany;
                            curUnit.ErpCodeGroup = WmsSetupValues.DEFAULT;
                            curUnit.ErpCode      = dr["f120_id_unidad_orden"].ToString();
                            tmpData.SaleUnit     = WType.GetUnit(curUnit);
                        }
                        catch { }

                        //Obteniendo las unidades que ese producto puede tener
                        flag    = "UNITLIST";
                        curList = unitList;  // .Where(unit => unit.ErpCodeGroup == dr["f120_id_unidad_inventario"].ToString()).ToList();

                        flag = "PRODUCT_TRACK";
                        tmpData.ProductTrack = GetProductTrack(tmpData.ErpTrackOpt, tmpData);

                        flag = "PRODUCT_UNITS";
                        tmpData.ProductUnits = GetProductUnits(tmpData, curList);

                        /*
                         * flag = "VENDORS";
                         * tmpData.ProductAccounts = GetProductVendors(tmpData);
                         */

                        //Productos Alternos.
                        flag = "ALTERN";
                        try
                        {
                            tmpData.AlternProducts = GetAlternateProducts(tmpData);
                        }
                        catch (Exception ex) { Console.WriteLine(flag + " " + ex.Message); }

                        list.Add(tmpData);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(flag + " " + ex.Message);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("GetProducts" + tmpData.ProductCode + "," + flag, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                //throw;
                return(null);
            }
        }