Beispiel #1
0
        private void PopulateStateComboBox(Country objCountry)
        {
            Logger.WriteToLogFile(Utilities.GetCurrentMethod());

            List <State> lstate = DBGetInterface.GetAllState(objCountry);

            comboState.Items.Clear();

            foreach (State state in lstate)
            {
                ComboboxItem objItem = new ComboboxItem();
                objItem.Text = state.Name;
                comboState.Items.Add(objItem);
            }
        }
Beispiel #2
0
        public void InitializeComponentsFromDatabase()
        {
            //Get the list of countries from the databse
            List <Country> lcountry = DBGetInterface.GetAllCountry();

            comboCountry.Items.Clear();

            foreach (Country country in lcountry)
            {
                ComboboxItem objItem = new ComboboxItem();
                objItem.Text = country.Name;
                comboCountry.Items.Add(objItem);
            }

            comboCountry.SelectedIndex = 0;

            PopulateStateComboBox(lcountry.First());
        }
Beispiel #3
0
        public void RunExcel(string fileName, string inputFolder, string outputFolder)
        {
            try
            {
                //Get store id
                string storeid = fileName.Split('-').First();

                //create csv with column names
                ExcelStructure objExcel = new ExcelStructure();
                Logger.WriteToCSVFile(CommonMethods.GetCommaSeperatedColumnNames(objExcel), fileName, outputFolder);

                Store objStore = DBGetInterface.GetStore(storeid);
                if (objStore == null)
                {
                    throw new Exception("Store id is null for excel : " + fileName);
                }

                //Run the query
                List <ExcelStructure> lobjExcel = new List <ExcelStructure>();
                CommonMethods.PopulateExcelData(inputFolder + "\\" + fileName, ref lobjExcel, objStore);

                foreach (ExcelStructure objExcelStruct in lobjExcel)
                {
                    SubCategory objSubCateogry = DBGetInterface.GetSubCategoryNode(objExcelStruct.SubCategory);
                    Brand       objBrand       = DBGetInterface.GetBrandNode(objSubCateogry, objExcelStruct.Brand);

                    ExcelStructure objexcelpop = CommonMethods.SaveToDB(objExcelStruct, objStore, objSubCateogry, objBrand, m_xmlNode.AppServer.Server, m_xmlNode.AppServer.Port);

                    Logger.WriteToCSVFile(CommonMethods.GetCommaSepearatedString(objexcelpop), fileName, outputFolder);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteToLogFile(ex.Message, Constants.FTPSERVER_OUTPUT_ERROR_LOGS, outputFolder);
            }
        }
Beispiel #4
0
        public static ExcelStructure SaveToDB(ExcelStructure objExcelStruct, Store objStore, SubCategory objSubCategory, Brand objBrand, string server, string port, GridViewRowInfo row = null)
        {
            try
            {
                if (objStore == null)
                {
                    throw new Exception("Please select a store .....");
                }
                if (objSubCategory == null)
                {
                    throw new Exception("Subcateogry do not match or is empty");
                }
                if (objBrand == null)
                {
                    throw new Exception("Please add brand for this subcategory ir brand is null or not matching");
                }


                ItemDescription objItemDescr = DBGetInterface.GetItemDescription(objBrand, objExcelStruct.ModelNumber);

                if (objItemDescr == null)
                {
                    //Call flipkart scrapper

                    CFlipkartScrapper objscrapper = new CFlipkartScrapper();
                    ItemDescription   objItemdesc = ItemFactory.GetItem(objSubCategory);

                    if (String.IsNullOrEmpty(objExcelStruct.FlipKart))
                    {
                        //check if the item link is already scrapped, find in csv
                        string strFilePath = m_ResourcesFolder + "//" + m_CategoryMappingTxt;
                        if (System.IO.File.Exists(strFilePath))
                        {
                            //File exists
                            //read the file and check for that file in LinkFodler
                            try
                            {
                                using (System.IO.StreamReader sw = new System.IO.StreamReader(strFilePath))
                                {
                                    string line = String.Empty;
                                    while ((line = sw.ReadLine()) != null)
                                    {
                                        bool     bflag = false;
                                        string[] cat   = line.Split(' ');
                                        if (cat[0].Equals(objSubCategory.SubCategoryID.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            //search model number in that subcategory file
                                            string file = Constants.LINK_EXTRACTED_FOLDER + "//" + cat[1] + ".csv";

                                            //search in this csv file
                                            List <List <string> > lmap = Utilities.GetCSVSheet(file);
                                            foreach (List <string> product in lmap)
                                            {
                                                if (product.ElementAt(0).Equals(objExcelStruct.ModelNumber, StringComparison.InvariantCultureIgnoreCase))
                                                {
                                                    objExcelStruct.FlipKart = product.ElementAt(2);
                                                    bflag = true;
                                                    break;
                                                }
                                            }
                                        }

                                        if (bflag)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }

                    objscrapper.SetHTMLDocument(objExcelStruct.FlipKart);
                    objscrapper.ExtractData(ref objItemdesc);

                    string image = objItemdesc.image;
                    objItemdesc.image = null;

                    //Now do the following
                    //Create item, create item description.
                    Item objItem = new Item();
                    objItem.Price            = Convert.ToUInt32(objExcelStruct.Price);
                    objItem.OfferDescription = objExcelStruct.Offer;

                    ItemWrapper objWrap = new ItemWrapper();
                    objWrap.objBrand           = objBrand;
                    objWrap.objStore           = objStore;
                    objWrap.objItemDescription = objItemdesc;
                    objWrap.objItem            = objItem;
                    DBAddinterface.CreateItemNode(objWrap);

                    //Copy image
                    //Create a seperate thread for it as image copying is a tedious process
                    //Copy image to local machine and then copy it to tomcat machine
                    //build path
                    string imageDir = Utilities.GetImageDir(objItemdesc.getLabel());
                    Utilities.CreateFolder(imageDir);
                    string imagePath = Utilities.GetImagePath(imageDir, objItemdesc.id);
                    ImageController.GetImageFromUrlAndSave(image, imagePath);


                    //Create a seperate thread for this to do
                    Thread SaveImageThread = new Thread(() => SaveImageToRemoteMachineThread(imageDir, Utilities.AppendImageType(objItemdesc.id), server, port));
                    SaveImageThread.Start();


                    objExcelStruct.Completed = Constants.COMPLETED_DONE;
                    objExcelStruct.Comment   = String.Empty;
                }
                else
                {
                    objExcelStruct.Comment = Constants.ALREADY_IN_DB;
                    //Just update the price and offer of the item
                    Item objItem = DBGetInterface.GetItem(objStore, objItemDescr);
                    if (objItem == null)
                    {
                        //Add this node
                        objItem                  = new Item();
                        objItem.Price            = Convert.ToUInt32(objExcelStruct.Price);
                        objItem.OfferDescription = objExcelStruct.Offer;

                        ItemWrapper objWrap = new ItemWrapper();
                        objWrap.objBrand           = objBrand;
                        objWrap.objStore           = objStore;
                        objWrap.objItemDescription = objItemDescr;
                        objWrap.objItem            = objItem;
                        DBAddinterface.CreateItemNode(objWrap);

                        objExcelStruct.Completed = Constants.COMPLETED_ADDED;
                    }
                    else
                    {
                        //Check for any updates
                        bool bUpdate = false;
                        if (objItem.Price != Convert.ToUInt32(objExcelStruct.Price))
                        {
                            objItem.Price = Convert.ToUInt32(objExcelStruct.Price);
                            bUpdate       = true;
                        }

                        string offer = String.Empty;
                        if (objExcelStruct.Offer != null)
                        {
                            offer = objExcelStruct.Offer;
                        }

                        if (!objItem.OfferDescription.Equals(offer, StringComparison.InvariantCultureIgnoreCase))
                        {
                            objItem.OfferDescription = objExcelStruct.Offer;
                            bUpdate = true;
                        }

                        if (bUpdate)
                        {
                            objItem.lastUpdated = Utilities.GetDateTimeInUnixTimeStamp();
                            DBUpdateInterface.UpdateNode <Item>(objItem);
                            objExcelStruct.Completed = Constants.COMPLETED_UPDATED;
                        }
                        else
                        {
                            objExcelStruct.Completed = Constants.COMPLETED_NOUPDATES;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                objExcelStruct.Completed = Constants.COMPLETED_ERROR;
                objExcelStruct.Comment   = ex.Message;
            }

            if (row != null)
            {
                row.Cells["Completed"].Value = objExcelStruct.Completed;
                row.Cells["Comment"].Value   = objExcelStruct.Comment;
            }

            return(objExcelStruct);
        }
Beispiel #5
0
        private void buttonFind_Click(object sender, EventArgs e)
        {
            StoreWrapper objWrap = DBGetInterface.GetStoreWrapper(textBoxFind.Text);

            PopulateAllControls(objWrap);
        }