public byte[] HandlerClientData(byte[] buff) { byte[] buffResp = { 0 }; DbTableDbContext db = new DbTableDbContext(); ProductInfo outInfo = this.DecodeData(buff); Models.ProductInfo lastInfo = db.ProductInfo.OrderByDescending(tmpItem => tmpItem.ID).FirstOrDefault(item => item.MachineId == outInfo.MachineId); Machines machine = db.Machines.Find(outInfo.MachineId); Models.ProductInfo innerInfo = this.exchangeData(outInfo, machine); //记录原始数据 db.ProductInfo.Add(innerInfo); db.SaveChanges(); //记录统计表 if (outInfo.MsgStatus == enumProductType.LoginOut) { if (lastInfo == null || lastInfo.MsgType != (byte)enumProductType.LoginIn) { db.RecordErrorInfo(enumSystemErrorCode.ProductOutWithoutIn, innerInfo.ToString(), null); return(buffResp); } if (lastInfo.staffNumber != outInfo.StaffNumber) { db.RecordErrorInfo(enumSystemErrorCode.ProductOutInDiff, lastInfo.ToString() + "\r\n" + innerInfo.ToString(), null); } int currentFinishCount = (outInfo.ChannelFinish1 + outInfo.ChannelFinish2 + outInfo.ChannelFinish3 + outInfo.ChannelFinish4 + outInfo.ChannelFinish5 + outInfo.ChannelFinish6 - lastInfo.ChannelFinish1 - lastInfo.ChannelFinish2 - lastInfo.ChannelFinish3 - lastInfo.ChannelFinish4 - lastInfo.ChannelFinish5 - lastInfo.ChannelFinish6); RecordStatisticsInfo(lastInfo, innerInfo.ID, outInfo, machine, currentFinishCount, db); } buffResp[0] = 0; return(buffResp); }
public ActionResult Product(int?pid) { if (pid == null) { pid = 1; } DB.DB mydb = new DB.DB(); DB.IProduct ip = new DB.Impl_Product(mydb.Connection); Dictionary <string, object> dp = ip.GetSingleProduct(pid.Value); if (dp == null || (int)dp["proState"] == 0) { RedirectToAction("Product"); } Models.ProductInfo pi = new Models.ProductInfo(); pi.ID = (int)dp["proID"]; pi.Name = dp["proName"].ToString(); pi.PTName = dp["PTName"].ToString(); pi.Note = dp["proNote"].ToString(); pi.Price = Convert.ToInt32(dp["proPrice"]); pi.Stock = Convert.ToInt32(dp["proStock"]); pi.Pic = dp["proPic"].ToString(); ViewData["proTypes"] = Session["proTypes"]; return(View(pi)); }
public ActionResult AddProduct(Models.ProductInfo product) { DB.DB mydb = new DB.DB("SQLAdmin", "admin1234"); DB.IProduct ip = new DB.Impl_Product(mydb.Connection); ip.AddNewProduct(product.Name, product.PTID, product.Price, product.Note, product.Stock, product.State, product.Pic); return(RedirectToAction("ManageProduct")); }
public ActionResult SearchByProductCode(Models.ProductInfo Pc) { try { return(View()); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "HG", "SearchByProductCode"))); } }
public ActionResult ShowProductDetailListing(Models.ProductInfo pc) { try { Session["ShowProductDetailListing"] = null; string pcodesearch = pc.productCode.ToString(); if (String.IsNullOrEmpty(pcodesearch) == false) { var pCodeSearchList = ((from e in db.iICE_Staging where e.ItemCode == pcodesearch select e)).ToList(); int counterFoundProducts = pCodeSearchList.Count(); if (counterFoundProducts > 0) { Session["ShowProductDetailListing"] = true; ViewBag.CounteriICE = counterFoundProducts; ViewBag.productsiice = ViewBag.CounteriICE + " " + "Products found in iice on the" + " " + ViewBag.Date; return(View(pCodeSearchList)); } else { Session["ShowProductDetailListing"] = null; ViewBag.CounteriICE = counterFoundProducts; ViewBag.productsiice = ViewBag.CounteriICE + " " + "Products found in iice on the" + " " + ViewBag.Date; return(View()); } } else { Session["ShowProductDetailListing"] = null; return(View()); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "iICEStaging", "ShowProductDetailListing"))); } }
public ActionResult ShowDetailsByProductCode(Models.ProductInfo pcode) { try { Session["ShowHGProductListing"] = null; string pcodesearch = pcode.productCode.ToString(); if (String.IsNullOrEmpty(pcodesearch) == false) { var pCodeSearchList = ((from e in hg.HG_PDM where e.ProductCode == pcodesearch select e)).ToList(); int counterFoundProducts = pCodeSearchList.Count(); if (counterFoundProducts > 0) { Session["ShowHGProductListing"] = true; ViewBag.CounterHG = counterFoundProducts; ViewBag.productsHG = ViewBag.CounterHG + " " + "Products found in FPI-HG for Product Code" + " " + pcodesearch; return(View(pCodeSearchList)); } else { Session["ShowHGProductListing"] = null; ViewBag.CounterHG = counterFoundProducts; ViewBag.productsHG = ViewBag.CounterHG + " " + "Products found in FPI-HG for Product Code" + " " + pcodesearch; return(View()); } } else { Session["ShowHGProductListing"] = null; return(View()); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "HG", "ShowDetailsByProductCode"))); } }
private void RecordStatisticsInfo(Models.ProductInfo lastInfo, int currInfoId, ProductInfo outInfo, Machines machine, int finishCount, DbTableDbContext db) { Schedules tempSchedule = db.Schedules.First(item => item.Number == outInfo.ScheduleNumber); StatisticInfo statistics = new StatisticInfo() { ProductIdStart = lastInfo.ID, DateStart = lastInfo.DateCreate, ProductIdOut = currInfoId, DateOut = DateTime.Now, ExceptionCount = outInfo.UnusualCount, FinishCount = finishCount, MachineId = machine.ID, MachineName = machine.Name, OrderNumber = tempSchedule.OrderNumber, ScheduleID = tempSchedule.ID, ScheduleNumber = tempSchedule.Number, StaffName = outInfo.StaffName, StaffNumber = outInfo.StaffNumber, RoomID = machine.RoomID, RoomName = machine.RoomName, Factory = "振德敷料" }; db.Statistics.Add(statistics); //施工单生产记录 db.Schedules.Attach(tempSchedule); tempSchedule.FinishCount += finishCount; tempSchedule.Status = tempSchedule.FinishCount >= tempSchedule.ProductCount ? enumStatus.Finished : enumStatus.Working; //订单生产记录 Orders tempOrder = db.Orders.Find(tempSchedule.OrderId); db.Orders.Attach(tempOrder); tempOrder.ProductFinishedCount += finishCount; tempOrder.Status = tempOrder.ProductFinishedCount >= tempOrder.ProductCount ? enumStatus.Finished : enumStatus.Working; db.SaveChanges(); }
public IHttpActionResult getProductInfo(string UPC, double latitude, double longitude) { Models.ProductInfo p = new Models.ProductInfo(); if (UPC!= string.Empty) { // Validate UPC if (UPC.Length > 12 && UPC.StartsWith("0")) UPC = UPC.Remove(0, 1); //if (UPC.Length > 12 && UPC.EndsWith("0")) // UPC = UPC.Remove(UPC.Length - 1, 1); // end Validate UPC //0085976033931 //5410316442930 p= productService.GetByUPC(UPC, latitude, longitude); if (p.IsFoundInDatabase!=0) { //TODO:store in database p = productService.getProductUsingAPI(UPC); } } return Ok(p); }
public Models.ProductInfo getProductUsingAPI(string UPC) { String UPCAPIKey = appSettingsService.GetUPCAPIKey(); //HttpClient httpUPCClient = new HttpClient(); //HttpResponseMessage UPC_Response = httpUPCClient.GetAsync("http://api.upcdatabase.org/json/" + UPCAPIKey + "/" + UPC).Result; //if (UPC_Response.IsSuccessStatusCode) //{ // string upcResult = UPC_Response.Content.ReadAsStringAsync().Result.ToString(); // // parsing Data out of JSON result from google places API // JObject json = Newtonsoft.Json.Linq.JObject.Parse(upcResult); // string productName = json["itemname"].ToString(); // if (productName == string.Empty) // { // productName = json["description"].ToString(); // } // return productName; //} _proxy = XmlRpcProxyGen.Create<IUPCDatabase>(); XmlRpcStruct request = new XmlRpcStruct(); XmlRpcStruct response = new XmlRpcStruct(); Models.ProductInfo pi = new Models.ProductInfo(); request.Add("rpc_key", UPCAPIKey); request.Add("upc", UPC); response = _proxy.Lookup(request); try { if (response["status"].ToString() != "fail") { string size = response["size"].ToString(); pi.ProductName = response["description"].ToString(); if (size.Trim() != "") { pi.Volume = (double)Convert.ToDecimal(Regex.Replace(size, @"[^0-9\.]", string.Empty)); pi.VolumeUnit = size.Replace(pi.Volume.ToString(), string.Empty).Trim(); } else { pi.Volume = -1; pi.VolumeUnit = "N/A"; } pi.UPC = UPC; pi.ProductTypeId = 4; pi.IsFoundInDatabase = 1; Product pr = new Product(); pr.Name = pi.ProductName; pr.UPC = UPC; pr.Volume = (decimal)pi.Volume; pr.VolumeUnit = pi.VolumeUnit; pr.TypeDetailsId = 4; pi.ProductId = repository.addProduct(pr); pi.ContainerType = "-1"; pi.ContainerQty = -1; } else { pi.IsFoundInDatabase = 2; } } catch (Exception ex) { pi.IsFoundInDatabase = 2; } return pi; }
public ActionResult ProductType(int?type, int?page) { if (page == null) { page = 1; } if (type == null) { type = 0; } DB.DB mydb = new DB.DB("SQLAdmin", "admin1234"); DB.IProduct ip = new DB.Impl_Product(mydb.Connection); DataTable tt = ip.GetProductListByType(type.Value); if (tt == null) { tt = new DataTable(); } int count = tt.Rows.Count; int totalPage = 1; if (count > 5) { totalPage = (int)Math.Ceiling(count / 5.0); } if (page > totalPage) { return(RedirectToAction("ProductType", new { type })); } List <Models.ProductInfo> ps = new List <Models.ProductInfo>(); foreach (DataRow r in tt.Rows) { int countID = Convert.ToInt32(r["countID"]); if (countID <= 5 * (page.Value - 1) || countID > 5 * page.Value) { continue; } Models.ProductInfo pi = new Models.ProductInfo(); pi.ID = (int)r["proID"]; pi.Name = r["proName"].ToString(); pi.Note = r["proNote"].ToString(); pi.PTName = r["PTName"].ToString(); pi.Price = Convert.ToInt32(r["proPrice"]); pi.Stock = Convert.ToInt32(r["proStock"]); pi.Pic = r["proPic"].ToString(); ps.Add(pi); } //頁碼 System.Text.StringBuilder sb2 = new System.Text.StringBuilder(); for (int i = 1; i <= totalPage; i++) { if (i == page.Value) { sb2.Append(i).Append(" "); } else { sb2.Append(string.Format("<a style=\"text-decoration:underline\" href='{0}'>{1}</a> ", Url.Action("ProductType", new { type, page = i }), i)); } } ViewData["PageLink"] = sb2.ToString(); ViewData["proTypes"] = Session["proTypes"]; return(View(ps)); }
// GET: Home public ActionResult Index() { #region 光顧數量 //記錄光顧數量 string path = Server.MapPath("~/App_Data/VisitCount.txt"); string text = System.IO.File.ReadAllText(path); int nn = int.Parse(text) + 1; System.IO.File.WriteAllText(path, nn.ToString()); //印出光顧數量 System.Text.StringBuilder sb1 = new System.Text.StringBuilder(); for (int i = 1; i <= 5 - nn.ToString().Length; i++) { sb1.Append("<img src='/images/number/0.gif' />"); } for (int i = 0; i < nn.ToString().Length; i++) { sb1.Append(string.Format("<img src='/images/number/{0}.gif' />", nn.ToString().Substring(i, 1))); } ViewData["VisitNum"] = sb1.ToString(); #endregion #region 列出商品 DB.DB mydb = new DB.DB(); DB.IProduct ip = new DB.Impl_Product(mydb.Connection); DataTable tt = ip.GetProductList(); List <Models.ProductInfo> ps = new List <Models.ProductInfo>(); if (tt != null) { foreach (DataRow r in tt.Rows) { Models.ProductInfo pi = new Models.ProductInfo(); pi.ID = (int)r["proID"]; pi.Name = r["proName"].ToString(); pi.PTName = r["PTName"].ToString(); pi.Pic = r["proPic"].ToString(); ps.Add(pi); } } #endregion #region 列出分類 if (Session["proTypes"] == null) { System.Text.StringBuilder sb2 = new System.Text.StringBuilder(); sb2.Append("<table>"); DB.DB mydb2 = new DB.DB(); DB.IProduct ip2 = new DB.Impl_Product(mydb2.Connection); DataTable tt2 = ip2.GetProductType(); if (tt2 != null) { foreach (DataRow r in tt2.Rows) { sb2.Append(string.Format("<tr><td><a style=\"text-align:center\" href=\"/Home/ProductType?type={0}\">", r["PTID"].ToString())); sb2.Append(string.Format("<img src='/images/shop/{0}' />", r["PTPic"].ToString())); sb2.Append("</a></td></tr>"); } } sb2.Append("</table>"); Session["proTypes"] = sb2.ToString(); } ViewData["proTypes"] = Session["proTypes"]; #endregion return(View(ps)); }