/// <summary> /// Inserts/updates item to DB and submits changes /// </summary> /// <param name="bi"></param> public void Save(BalanceItem bi) { try { var db = _dataContext.GetTable <BalanceItem>(); BalanceItem entity = db.SingleOrDefault <BalanceItem>(x => x.InternalCode == bi.InternalCode); //Log.DebugFormat("BalanceItem with code {0} already exists...", bi.InternalCode); if (entity == null) { bi.Status = Status.Approved; db.InsertOnSubmit(bi); } else { entity.Price = bi.Price; entity.Quantity = bi.Quantity; entity.ProductName = bi.ProductName; } db.Context.SubmitChanges(); } catch (Exception ex) { //Log.Error("Error saving BalanceItem!", ex); throw ex; } }
/// <summary> /// Inserts/updates item to DB and submits changes /// </summary> /// <param name="bi"></param> public void Save(BalanceItem bi) { try { var db = _dataContext.GetTable<BalanceItem>(); BalanceItem entity = db.SingleOrDefault<BalanceItem>(x => x.InternalCode == bi.InternalCode); //Log.DebugFormat("BalanceItem with code {0} already exists...", bi.InternalCode); if(entity == null) { bi.Status = Status.Approved; db.InsertOnSubmit(bi); } else { entity.Price = bi.Price; entity.Quantity = bi.Quantity; entity.ProductName = bi.ProductName; } db.Context.SubmitChanges(); } catch(Exception ex) { //Log.Error("Error saving BalanceItem!", ex); throw ex; } }
// // GET: /balance/dosyncfrompos/1234 public ActionResult DoSyncFromPos() { int temp; List<OnBalance.Models.BalanceItem> list = new List<OnBalance.Models.BalanceItem>(); StringBuilder sb = new StringBuilder(); //OnBalance.Models.BalanceItemRepository db = new OnBalance.Models.BalanceItemRepository(); try { string getBalanceUrl = "http://gjsportland.com/index.php/lt/balance/get?_token=12345"; InfoFormat("Going to download changes from POS: {0}", getBalanceUrl); WebClient wc = new WebClient(); string resp = wc.DownloadString(getBalanceUrl); DebugFormat("Changes: {0}", resp); Regex rx = new Regex(@"(\{)([^}]+)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Singleline); // ("uid"\:")([^""]+)([\"\,\ ]*)(code\"\:\")([^"]+)([\"\,\ ]*)(pr\"\:)(\d+)([,"\s]+)(posid"\:)(\d+)([\"\,\ ]*)(name\"\:\")([^"]+) Regex regex = new Regex(@"(""uid""\:"")([^""""]+)([\""\,\ ]*)(code\""\:\"")([^""]+)([\""\,\ ]*)(pr\""\:)(\d+)([,""\s]+)(posid""\:)(\d+)([\""\,\ ]*)(name\""\:\"")([^""]+)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.Singleline); Regex rxSizes = new Regex(@"([\d\.]+)(=)(\d)(\:)"); Match m = rx.Match(resp); // List all products in JSON while( m.Success ) { OnBalance.Models.BalanceItem bi = new OnBalance.Models.BalanceItem(); string line = m.Groups[2].Value; Match matchLine = regex.Match(line); string uid = matchLine.Groups[2].Value; bi.InternalCode = matchLine.Groups[5].Value; int.TryParse(matchLine.Groups[8].Value, out temp); bi.Price = temp / 100.0m; int.TryParse(matchLine.Groups[11].Value, out temp); bi.PosId = temp; bi.ProductName = matchLine.Groups[14].Value.Trim(); int start = line.IndexOf('[', matchLine.Groups[5].Index); int end = line.LastIndexOf(']'); string sizes = line.Substring(start, end - start); Match mSize = rxSizes.Match(sizes); while( mSize.Success ) { bi.QuantityForSizes[mSize.Groups[1].Value] = mSize.Groups[3].Value; mSize = mSize.NextMatch(); } //db.Save(bi); list.Add(bi); m = m.NextMatch(); } //Regex regex = new Regex(@"(\""uid\""\:\"")([^""]+)([\""\,\ ]*)(code\""\:\"")([^""]+)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.Singleline); //MatchCollection matchCollection = regex.Matches(resp); //foreach( Match match in matchCollection ) //{ // string uid = match.Groups[2].Value; // string code = match.Groups[5].Value; // Log4cs.Log("Uid: {0}, code: {1}", uid, code); //} } catch( Exception ex ) { throw ex; return Json(new { Status = (int)Status.Failed, Msg = "Error getting from POS!" }, JsonRequestBehavior.AllowGet); } return Json(new { Status = (int)Status.Completed, Msg = "Got from POS", Results = list.ToArray() }, JsonRequestBehavior.AllowGet); }
public ActionResult Delete(int id) { BalanceItem bi = null; try { bi = new BalanceItem(_balanceItemsRepository.BalanceItems.First(x => x.Id.Equals(id))); } catch (Exception ex) { SetErrorMessage("Error cancelling product change: {0}", ex.Message); Error("Error showing confirmation to delete from balance_item", ex); } return View("Delete", bi); }
private void ParseData(HtmlDocument document) { string[] ar; string tempName = "", tempCode, tempPrice; var td = document.DocumentNode.SelectNodes("//table/tbody/tr/td/p").FirstOrDefault(x => x.InnerText.IndexOf("kodas ir pavadinimas") > 0); _loaded.Clear(); if(td != null) { //Log4cs.Log("Got header of guns list..."); var tbody = td.ParentNode.ParentNode.ParentNode; if(tbody != null) { var trs = tbody.SelectNodes(".//tr"); //Log4cs.Log("Got {0} rows in guns table", trs == null ? "NO" : trs.Count.ToString()); // Skip first row - header for(int i = 1; i < trs.Count; i++) { var tds = trs[i].SelectNodes(".//td"); if(tds.Count > 2) { try { BalanceItem bi = new BalanceItem(); tempName = tds[0].InnerText.Replace(" ", "").Trim(); tempCode = tds[1].InnerText.Replace(" ", "").Trim(); tempPrice = tds[2].InnerText.Replace(" ", "").Trim(); //Log4cs.Log("Name: {0}, price: {1}, code: {2}", tempName, tempPrice, tempCode); ar = tempName.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); try { bi.Quantity = 1; bi.InternalCode = tempCode; bi.ProductName = tempName; //g.TypeOfGun = GetTypeByName(ar[1]); //g.Name = tempName; //g.Code = tempCode; } catch(KeyNotFoundException) { //g = ParseLineHarder(tempName); //if(g == null) //{ // sbIncorrectLines.AppendLine(tempName); // throw; //} } bi.Price = decimal.Parse(tempPrice); _loaded.Add(bi); //AddOrUpdate(g); } catch(Exception ex) { //Log4cs.Log(Importance.Error, "Error parsing and saving Gun object!"); //Log4cs.Log(Importance.Debug, ex.ToString()); } } } } } }
public ActionResult Index(BalanceItem model) { return RedirectToAction("Index"); }
// // GET: /balance/dosyncfrompos/1234 public ActionResult DoSyncFromPos() { int temp; List <OnBalance.Models.BalanceItem> list = new List <OnBalance.Models.BalanceItem>(); StringBuilder sb = new StringBuilder(); //OnBalance.Models.BalanceItemRepository db = new OnBalance.Models.BalanceItemRepository(); try { string getBalanceUrl = "http://gjsportland.com/index.php/lt/balance/get?_token=12345"; InfoFormat("Going to download changes from POS: {0}", getBalanceUrl); WebClient wc = new WebClient(); string resp = wc.DownloadString(getBalanceUrl); DebugFormat("Changes: {0}", resp); Regex rx = new Regex(@"(\{)([^}]+)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Singleline); // ("uid"\:")([^""]+)([\"\,\ ]*)(code\"\:\")([^"]+)([\"\,\ ]*)(pr\"\:)(\d+)([,"\s]+)(posid"\:)(\d+)([\"\,\ ]*)(name\"\:\")([^"]+) Regex regex = new Regex(@"(""uid""\:"")([^""""]+)([\""\,\ ]*)(code\""\:\"")([^""]+)([\""\,\ ]*)(pr\""\:)(\d+)([,""\s]+)(posid""\:)(\d+)([\""\,\ ]*)(name\""\:\"")([^""]+)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.Singleline); Regex rxSizes = new Regex(@"([\d\.]+)(=)(\d)(\:)"); Match m = rx.Match(resp); // List all products in JSON while (m.Success) { OnBalance.Models.BalanceItem bi = new OnBalance.Models.BalanceItem(); string line = m.Groups[2].Value; Match matchLine = regex.Match(line); string uid = matchLine.Groups[2].Value; bi.InternalCode = matchLine.Groups[5].Value; int.TryParse(matchLine.Groups[8].Value, out temp); bi.Price = temp / 100.0m; int.TryParse(matchLine.Groups[11].Value, out temp); bi.PosId = temp; bi.ProductName = matchLine.Groups[14].Value.Trim(); int start = line.IndexOf('[', matchLine.Groups[5].Index); int end = line.LastIndexOf(']'); string sizes = line.Substring(start, end - start); Match mSize = rxSizes.Match(sizes); while (mSize.Success) { bi.QuantityForSizes[mSize.Groups[1].Value] = mSize.Groups[3].Value; mSize = mSize.NextMatch(); } //db.Save(bi); list.Add(bi); m = m.NextMatch(); } //Regex regex = new Regex(@"(\""uid\""\:\"")([^""]+)([\""\,\ ]*)(code\""\:\"")([^""]+)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.Singleline); //MatchCollection matchCollection = regex.Matches(resp); //foreach( Match match in matchCollection ) //{ // string uid = match.Groups[2].Value; // string code = match.Groups[5].Value; // Log4cs.Log("Uid: {0}, code: {1}", uid, code); //} } catch (Exception ex) { throw ex; return(Json(new { Status = (int)Status.Failed, Msg = "Error getting from POS!" }, JsonRequestBehavior.AllowGet)); } return(Json(new { Status = (int)Status.Completed, Msg = "Got from POS", Results = list.ToArray() }, JsonRequestBehavior.AllowGet)); }