private void onSaveShopItemdata(object sender, OnShopItemSaveEvtArgs e)
        {
            bool result = false;
            //create the db helper class
            var dbhelper = new DBHelper(DBGlobal.DatabasebFilePath,this);
            switch( e.operate )
            {
                case dboperations.insert_from_src:
                case dboperations.insert_manually:
                    ShopItem item_info1 = new ShopItem
                    {
                        ItemBrief = e.item_brief,
                        ItemCost = e.item_Cost,
                        ItemDescription = e.item_description,
                        ItemPriority = e.item_priority
                    };
                    result = dbhelper.insert_update_data(item_info1);
                    break;
                case dboperations.update_table:
                    ShopItem item_info2 = new ShopItem
                    {
                        ID = e.ID,
                        ItemBrief = e.item_brief,
                        ItemCost = e.item_Cost,
                        ItemDescription = e.item_description,
                        ItemPriority = e.item_priority
                    };
                    result = dbhelper.update_data(item_info2);
                    break;
            }
            
            var records = dbhelper.get_total_records();
            Console.WriteLine("DB Update :" + result + " Number of records : ", records);

            dbupdateUI(scrolloptions.scroll_to_bottom);
        }
        //------------------------------------------------------------------------//
        //Dialog options - TBD common interface
        private void showItemInputDlg(dboperations opt, ShopItem item = null)
        {
            //Pull up input dialog
            FragmentTransaction transaction = FragmentManager.BeginTransaction();
            dialog_getitem_info input_dialog = new dialog_getitem_info();

            input_dialog.this_shopitem = item;
            input_dialog.this_operation = opt;

            input_dialog.Show(transaction, "dialog_fragment");
            input_dialog.mOnShopItemAdded += onSaveShopItemdata;
            input_dialog.mOnError += OnErrorHandler;
            input_dialog.mOnDismissEvt += OnDlgDismiss;
        }
        private void SlowMethod(ShopItem item)
        {
            try
            {
                RunOnUiThread(() =>
                {
                    //Toast.MakeText(this, "Toast within progress dialog.", ToastLength.Long).Show();
                    mProgressDialog.Hide();

                    showItemInputDlg(dboperations.insert_from_src, item);
                    Console.WriteLine("UI thread execution :)");
                });
            }
            catch(Exception ex)
            {
                Console.WriteLine("ExceptioHandled:{0}" + ex.Message);
            }

        }
        private void do_url_processing(string rawString)
        {
            mProgressDialog = ProgressDialog.Show(this, "Please wait...", "Loading this item's info...", true);
            WebClient webClient = new WebClient();
            string url_match = "";
            try
            {
                Regex linkParser = new Regex(@"\b(?:https?://)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                foreach (Match m in linkParser.Matches(rawString))
                {
                    Console.WriteLine("URL : {0}", m);
                    url_match = m.ToString();
                }
                var url = new Uri(url_match); // Html home page
                webClient.Encoding = Encoding.UTF8;
                webClient.DownloadStringAsync(url);

                webClient.DownloadStringCompleted += (s, e) =>
                {
                    var text = e.Result; // get the downloaded text
                    HtmlDocument doc = new HtmlDocument();
                    try
                    {
                        doc.LoadHtml(text);
                        double minvalue = double.PositiveInfinity;
                        ShopItem temp_item = new ShopItem();

                        var all_prices = findPrice(url_match, doc);
                        int maxcount = all_prices.Count > 2 ? 2 : all_prices.Count;

                        for (int i = 0; i < maxcount; i++)
                        {
                            Console.WriteLine("PRICE:" + all_prices[i]);
                            string tp = all_prices[i].Replace("$", "");
                            if (!string.IsNullOrEmpty(tp))
                            {
                                double temp = Double.Parse(tp.ToString());
                                if (minvalue > temp)
                                {
                                    minvalue = temp;
                                }
                            }
                        }
                        if (!double.IsInfinity(minvalue))
                            temp_item.ItemCost = minvalue;
                        else
                            temp_item.ItemCost = 0;

                        foreach (var node in doc.DocumentNode.Descendants("meta"))
                        {
                            if (node != null &&
                            node.Attributes["name"] != null &&
                            node.Attributes["name"].Value == "description")
                            {
                                HtmlAttribute desc;
                                desc = node.Attributes["content"];
                                string fulldescription = desc.Value;
                                temp_item.ItemDescription = fulldescription;
                                Console.WriteLine("DESCRIPTION:{0}", fulldescription.ToString());
                            }
                            if (node != null &&
                            node.Attributes["name"] != null &&
                            node.Attributes["name"].Value == "title")
                            {
                                HtmlAttribute desc;
                                desc = node.Attributes["content"];
                                string title = desc.Value;
                                Console.WriteLine("TITLE:{0}", title.ToString());
                                temp_item.ItemBrief = title;
                            }
                            else if (node != null &&
                                node.Attributes["property"] != null &&
                                node.Attributes["property"].Value.Contains("title"))
                            {
                                HtmlAttribute desc;
                                desc = node.Attributes["content"];
                                string title = desc.Value;
                                Console.WriteLine("TITLE:{0}", title.ToString());
                                temp_item.ItemBrief = title;
                            }
                        }
                        temp_item.ItemPriority = 2.5; //average

                    if (null == temp_item.ItemBrief)
                        {
                            temp_item.ItemBrief = temp_item.ItemDescription;
                            temp_item.ItemDescription = "";
                        }
                    if( temp_item.ItemBrief.Contains(temp_item.ItemDescription) )
                        {
                            temp_item.ItemDescription = "";
                        }
                        ThreadPool.QueueUserWorkItem(o => SlowMethod(temp_item));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ExceptionHandled:{0}" + ex.Message);
                    }
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine("Crashed / ExceptionHandled:{0}" + ex.Message);
            }
        }
Esempio n. 5
0
 //------------------------------------------------------------------------//
 //used to replace an existing row
 public bool update_data(ShopItem data)
 {
     try
     {
         var db = new SQLiteConnection(m_db_path);
         //returns the number of rows affected
         if ( 0 == db.InsertOrReplace(data) )
         {
             return false;
         }
         return true;
     }
     catch (SQLiteException ex)
     {
         Console.WriteLine("exception handled while replacing data:{0}", ex.Message);
         return false;
     }
 }
Esempio n. 6
0
 //------------------------------------------------------------------------//
 //all addition / insertion are performed using this function
 public bool insert_update_data(ShopItem data)
 {
     try
     {
         var db = new SQLiteConnection(m_db_path);
             if (0 != db.Insert(data))
                 db.Update(data);
         return true;
     }
     catch (SQLiteException ex)
     {
         Console.WriteLine("exception handled while inserting data:{0}", ex.Message);
         return false;
     }
 }