示例#1
0
        public override Int64 Set(string parametersArr)
        {
            try
            {
                // List<Item> Lst_ItemsAll = new GenericeDAO<Item>().GetWhere("  inactive=0 and  (Foodics_Id in (select ItemFoodics_Id from ItemCompnent))   and Item_Type=" + (int)Item_Type.AssemblyItem).Take(200).ToList();
                //List<Item> Lst_ItemsAll = new GenericeDAO<Item>().GetWhere(" id >= 1238  and inactive=0 and  (Foodics_Id in (select ItemFoodics_Id from ItemCompnent))   and Item_Type=" + (int)Item_Type.AssemblyItem);

                List <Item> Lst_ItemsUpdateAll = new GenericeDAO <Item>().GetWhere(" isnull(Netsuite_Id,0) >0 and FoodicsUpdateDate >= SyncDate and  Item_Type=" + (int)Item_Type.AssemblyItem);
                List <Item> Lst_ItemsNew       = new GenericeDAO <Item>().GetWhere("  isnull(Netsuite_Id,0) =0 and inactive=0 and  (Foodics_Id in (select ItemFoodics_Id from ItemCompnent)) and  Item_Type=" + (int)Item_Type.AssemblyItem).Take(200).ToList();



                // Send order list to netsuite
                if (Lst_ItemsNew.Count > 0)
                {
                    com.netsuite.webservices.AssemblyItem[] ItemArrNew = GenerateNetSuitelst(Lst_ItemsNew);

                    WriteResponseList wrNew = Service(true).addList(ItemArrNew);
                    bool result             = wrNew.status.isSuccess;
                    if (result)
                    {
                        //Update database with returned Netsuite ids
                        UpdatedLst(Lst_ItemsNew, wrNew);
                    }
                }

                int Exe_length = 100;
                int lstend     = Exe_length;
                if (Lst_ItemsUpdateAll.Count > 0)
                {
                    for (int Index = 0; Index < Lst_ItemsUpdateAll.Count; Index += Exe_length)
                    {
                        if (Index + Exe_length >= Lst_ItemsUpdateAll.Count)
                        {
                            lstend = Lst_ItemsUpdateAll.Count - Index;
                        }
                        List <Item> Lst_ItemsUpdate = Lst_ItemsUpdateAll.GetRange(Index, lstend);

                        // Send order list to netsuite
                        if (Lst_ItemsUpdate.Count > 0)
                        {
                            com.netsuite.webservices.AssemblyItem[] ItemArrUpdate = GenerateNetSuitelst(Lst_ItemsUpdate);

                            WriteResponseList wr = Service(true).updateList(ItemArrUpdate);
                            UpdatedLst(Lst_ItemsUpdate, wr);
                            //    bool result = wr.status.isSuccess;
                        }
                    }
                }
                new CustomDAO().UpdateProductCompnent();
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }

            return(0);
        }
        public override Int64 Set(string parametersArr)
        {
            new CustomDAO().InvoiceRelatedUpdate();
            new CustomDAO().SetItemClass();

            //List<Item> Lst_ItemsAll = new GenericeDAO<Item>().GetWhere(" FoodicsUpdateDate >= UpdateDate and inactive=0 and  Item_Type=" + (int)Item_Type.InventoryItem).Take(200).ToList();

            List <Item> Lst_ItemsUpdateAll = new GenericeDAO <Item>().GetWhere(" isnull(Netsuite_Id,0) >0 and FoodicsUpdateDate >= SyncDate and  Item_Type=" + (int)Item_Type.InventoryItem + " order by FoodicsUpdateDate desc");
            List <Item> Lst_ItemsNew       = new GenericeDAO <Item>().GetWhere("  isnull(Netsuite_Id,0) =0 and inactive=0 and  Item_Type=" + (int)Item_Type.InventoryItem).Take(200).ToList();

            // Send order list to netsuite
            if (Lst_ItemsNew.Count > 0)
            {
                com.netsuite.webservices.InventoryItem[] ItemArrNew = GenerateNetSuitelst(Lst_ItemsNew);
                WriteResponseList wrNew = Service(true).addList(ItemArrNew);
                bool result             = wrNew.status.isSuccess;
                if (result)
                {
                    //Update database with returned Netsuite ids
                    UpdatedLst(Lst_ItemsNew, wrNew);
                }
            }

            int Exe_length = 100;
            int lstend     = Exe_length;

            if (Lst_ItemsUpdateAll.Count > 0)
            {
                for (int Index = 0; Index < Lst_ItemsUpdateAll.Count; Index += Exe_length)
                {
                    if (Index + Exe_length >= Lst_ItemsUpdateAll.Count)
                    {
                        lstend = Lst_ItemsUpdateAll.Count - Index;
                    }
                    List <Item> Lst_ItemsUpdate = Lst_ItemsUpdateAll.GetRange(Index, lstend);
                    if (Lst_ItemsUpdate.Count > 0)
                    {
                        com.netsuite.webservices.InventoryItem[] ItemArrAdd = GenerateNetSuitelst(Lst_ItemsUpdate);
                        WriteResponseList wrNew = Service(true).updateList(ItemArrAdd);
                        bool result             = wrNew.status.isSuccess;
                        if (result)
                        {
                            //Update database with returned Netsuite ids
                            UpdatedLst(Lst_ItemsUpdate, wrNew);
                        }
                    }
                }
            }



            return(0);
        }
        public override Int64 Set(string parametersArr)
        {
            new CustomDAO().InvoiceRelatedUpdate();
            new CustomDAO().GenerateAssemblyBuild();

            List <Foodics.NetSuite.Shared.Model.AssemblyBuild> lstitemsAll = new GenericeDAO <Foodics.NetSuite.Shared.Model.AssemblyBuild>().GetWhere(" item_id >0 and ISNULL(Netsuite_Id,0) =0 ").Take(1000).ToList();
            int Exe_length = 200;
            int lstend     = Exe_length;

            if (lstitemsAll.Count > 0)
            {
                for (int Index = 0; Index < lstitemsAll.Count; Index += Exe_length)
                {
                    if (Index + Exe_length >= lstitemsAll.Count)
                    {
                        lstend = lstitemsAll.Count - Index;
                    }
                    List <Foodics.NetSuite.Shared.Model.AssemblyBuild> ColLst = lstitemsAll.GetRange(Index, lstend);
                    try
                    {
                        bool result = true;
                        if (ColLst.Count > 0)
                        {
                            #region variables
                            com.netsuite.webservices.AssemblyBuild[]    AssemblyArr = new com.netsuite.webservices.AssemblyBuild[ColLst.Count];
                            Foodics.NetSuite.Shared.Model.AssemblyBuild Obj_info;
                            com.netsuite.webservices.AssemblyBuild      AssemblyBuildObject;
                            RecordRef Mainitem, subsid, location;
                            #endregion
                            for (int i = 0; i < ColLst.Count; i++)
                            {
                                try
                                {
                                    Obj_info                              = ColLst[i];
                                    AssemblyBuildObject                   = new com.netsuite.webservices.AssemblyBuild();
                                    AssemblyBuildObject.quantity          = Obj_info.Quantity;
                                    AssemblyBuildObject.quantitySpecified = true;

                                    Mainitem                 = new RecordRef();
                                    Mainitem.internalId      = Obj_info.Item_Id.ToString(); //objSetting.Location_Netsuite_Id.ToString();
                                    Mainitem.type            = RecordType.assemblyItem;
                                    AssemblyBuildObject.item = Mainitem;

                                    AssemblyBuildObject.tranDateSpecified = true;
                                    //AssemblyBuildObject.tranDate = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now, TimeZoneInfo.Local);
                                    //AssemblyBuildObject.tranDate = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2021, 03, 01), TimeZoneInfo.Local);
                                    AssemblyBuildObject.tranDate = TimeZoneInfo.ConvertTimeToUtc(Utility.ConvertToDateTime(ConfigurationManager.AppSettings["InvoiceDate"]), TimeZoneInfo.Local);

                                    location                     = new RecordRef();
                                    location.internalId          = Obj_info.Location_Id.ToString(); //objSetting.Location_Netsuite_Id.ToString();
                                    location.type                = RecordType.location;
                                    AssemblyBuildObject.location = location;

                                    subsid            = new RecordRef();
                                    subsid.internalId = Obj_info.Subsidiary_Id.ToString();
                                    subsid.type       = RecordType.subsidiary;
                                    AssemblyBuildObject.subsidiary = subsid;

                                    AssemblyArr[i] = AssemblyBuildObject;
                                }
                                catch (Exception ex)
                                {
                                    ColLst.RemoveAt(i);
                                    LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                                }
                            }
                            // Send invoice list to netsuite
                            WriteResponseList wr = Service(true).addList(AssemblyArr);
                            result = wr.status.isSuccess;
                            if (result)
                            {
                                //Update database with returned Netsuite ids
                                Updatedlst(ColLst, wr);
                            }
                        }

                        // post customerPayment to netsuite
                        //  bool postPayments = PostCustomerPayment();
                    }
                    catch (Exception ex)
                    {
                        LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                    }
                }
            }
            return(0);
        }
        public override Int64 Set(string parametersArr)
        {
            try
            {
                List <Foodics.NetSuite.Shared.Model.Customer> Lst_CustomAll = new GenericeDAO <Foodics.NetSuite.Shared.Model.Customer>().GetWhere("Netsuite_Id IS NULL or Netsuite_Id =0").Take(2000).ToList();

                //List<Foodics.NetSuite.Shared.Model.Customer> Lst_CustomAll = new GenericeDAO<Foodics.NetSuite.Shared.Model.Customer>().GetWhere(" (Netsuite_Id IS NULL or Netsuite_Id =0) and  (Foodics_UpdateDate >= '"+ ConfigurationManager.AppSettings["InvoiceDate"] + "')").Take(2000).ToList();
                int Exe_length = 200;
                int lstend     = Exe_length;
                if (Lst_CustomAll.Count > 0)
                {
                    for (int Index = 0; Index < Lst_CustomAll.Count; Index += Exe_length)
                    {
                        if (Index + Exe_length >= Lst_CustomAll.Count)
                        {
                            lstend = Lst_CustomAll.Count - Index;
                        }
                        List <Foodics.NetSuite.Shared.Model.Customer> Lst_Items = Lst_CustomAll.GetRange(Index, lstend);

                        List <com.netsuite.webservices.Customer> ItemArr = new List <com.netsuite.webservices.Customer>();

                        for (int i = 0; i < Lst_Items.Count; i++)
                        {
                            Foodics.NetSuite.Shared.Model.Customer Obj = Lst_Items[i];
                            try
                            {
                                CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");

                                com.netsuite.webservices.Customer NewItemObject = new com.netsuite.webservices.Customer();
                                string   Custname = Obj.name;
                                string[] Fullname = Custname.Split(' ');
                                if (Fullname.Length > 0)
                                {
                                    NewItemObject.firstName = Fullname[0];
                                }
                                else
                                {
                                    NewItemObject.firstName = Custname;
                                }
                                if (Fullname.Length > 1)
                                {
                                    string lastName = Custname.Remove(0, NewItemObject.firstName.Length);
                                    NewItemObject.lastName = lastName.Length > 30 ? lastName.Substring(0, 30) : lastName;
                                }
                                else
                                {
                                    NewItemObject.lastName = "-";
                                }


                                NewItemObject.isPerson          = true;
                                NewItemObject.isPersonSpecified = true;
                                NewItemObject.email             = Obj.email;
                                NewItemObject.phone             = Obj.phone;

                                RecordRef subsidiary = new RecordRef();
                                subsidiary.internalId    = Obj.Subsidiary_Id.ToString();
                                subsidiary.type          = RecordType.subsidiary;
                                NewItemObject.subsidiary = subsidiary;

                                if (Obj.InActive)
                                {
                                    NewItemObject.isInactive          = true;
                                    NewItemObject.isInactiveSpecified = true;
                                }
                                ItemArr.Add(NewItemObject);
                            }
                            catch (Exception ex)
                            {
                                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error in customer Name: " + Obj.name + " error: " + ex.Message);
                                Lst_Items.RemoveAt(i);
                            }
                        }
                        try
                        {
                            // Send order list to netsuite
                            WriteResponseList wr = Service(true).addList(ItemArr.ToArray());
                            bool result          = wr.status.isSuccess;
                            if (result)
                            {
                                UpdatedLst(Lst_Items, wr);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogDAO.Integration_Exception(LogIntegrationType.Error, this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Error " + ex.Message);
            }
            return(0);
        }