//组装item在前台的显示信息 private inventory scanItem_encodeItemInfo2front(ref LTS.Item stItem, ref LTS.Product stProduct) { Log.WriteLog(LogType.Trace, "come in scanItem_encodeItemInfo2front"); //组装显示信息 inventory stInv = new inventory(); if (null == stInv) { Log.WriteLog(LogType.Error, "error to get inventory memery"); return(null); } if (null == stItem) { Log.WriteLog(LogType.Error, "the item param is error"); return(null); } stInv.EPC = stItem.TagEPC; stInv.itemID = stItem.ItemID; if (stProduct != null) { stInv.ProductName = stProduct.ProductName; stInv.ProductDescription = stProduct.ProductDescription; } Log.WriteLog(LogType.Trace, "success to encode item[" + stInv.itemID + "] info into front:epc[" + stInv.EPC + "], product name[" + stInv.ProductName + "], product description[" + stInv.ProductDescription + "]"); return(stInv); }
//Tiaan private void StockOut_Load(object sender, EventArgs e) { try { List <LTS.Item> item = new List <LTS.Item>(); List <LTS.Barcode> barcode = new List <LTS.Barcode>(); List <LTS.BookOut> bookOut = new List <LTS.BookOut>(); List <LTS.Product> product = new List <LTS.Product>(); List <LTS.User> user = new List <LTS.User>(); item = DAT.DataAccess.GetItem().Where(y => y.ItemStatus == false).ToList(); barcode = DAT.DataAccess.GetBarcode().ToList(); bookOut = DAT.DataAccess.GetBookOut().ToList(); product = DAT.DataAccess.GetProduct(); user = DAT.DataAccess.GetUser().ToList(); for (int i = 0; i < bookOut.Count; i++) { LTS.Item it = item.Where(a => a.ItemID == bookOut[i].ItemID).FirstOrDefault(); LTS.Product p = product.Where(r => r.ProductID == it.ProductID).FirstOrDefault(); LTS.Barcode b = barcode.Where(q => q.BarcodeID == p.BarcodeID).FirstOrDefault(); LTS.User u = user.Where(w => w.UserID == bookOut[i].UserID).FirstOrDefault(); dataGridView1.Rows.Add(bookOut[i].BookOutID, it.TagEPC, b.BarcodeNumber, p.ProductName, bookOut[i].Reason, bookOut[i].Project, bookOut[i].Date, u.UserName, u.UserSurname); } dataGridView1.ClearSelection(); } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
public static LTS.Item GetItemItemByID(int?ItemID) { LTS.Item item = new LTS.Item(); try { using (LTS.LTSBase access = new LTS.LTSDC()) { item = access.Item.Where(o => o.ItemID == ItemID).FirstOrDefault(); } } catch (Exception ex) { } return(item); }
//显示指定store下所有的item到list中 private bool scanItem_item2List(int iStoreId, ref List <inventory> listInv) { Log.WriteLog(LogType.Trace, "come in scanItem_item2List"); listInv.Clear(); List <LTS.Item> listItem = DAT.DataAccess.GetItem().Where(i => i.StoreID == iStoreId && i.ItemStatus == true).ToList(); if (listItem != null) { Log.WriteLog(LogType.Trace, "success to get " + listItem.Count + " items from store[" + iStoreId + "]"); if (listItem.Count > 0) { for (int iIdx = 0; iIdx < listItem.Count; iIdx++) { LTS.Item stItem = listItem[iIdx]; LTS.Product stProduct = DAT.DataAccess.GetProduct().Where(p => p.ProductID == stItem.ProductID).FirstOrDefault(); if (stProduct != null) { Log.WriteLog(LogType.Trace, "success get product[" + stItem.ProductID + "] info: product name[" + stProduct.ProductName + "], product description[" + stProduct.ProductDescription + "]"); } else { Log.WriteLog(LogType.Error, "error to get product[" + stItem.ProductID + "] info ,it is impossible."); } //组装显示信息 inventory stInv = scanItem_encodeItemInfo2front(ref stItem, ref stProduct); if (stInv != null) { listInv.Add(stInv); Log.WriteLog(LogType.Trace, "success to add item[" + stInv.itemID + "] info into inventory list"); } else { Log.WriteLog(LogType.Error, "error to call scanItem_encodeItemInfo2front"); } } } return(true); } else { Log.WriteLog(LogType.Error, "error to get item list from store[" + iStoreId + "]"); return(false); } }
public static int AddItem(LTS.Item item) { int?ItemID = -1; try { using (LTS.LTSBase access = new LTS.LTSDC()) { access.InsertItem(item.ItemStatus, item.ProductID, item.StoreID, item.TagEPC, ref ItemID); } } catch (Exception ex) { } return(ItemID.Value); }
public static bool UpdateItem(LTS.Item item) { bool completed = false; try { using (LTS.LTSBase access = new LTS.LTSDC()) { access.UpdateItem(item.ItemStatus, item.ProductID, item.StoreID, item.TagEPC, item.ItemID); completed = true; } } catch (Exception ex) { completed = false; } return(completed); }
//Margo private void btnlogin_Click_1(object sender, EventArgs e) { try { int itemID = current.itemID; int bookOutID = current.BookOutID; LTS.Item i = DAT.DataAccess.GetItem().Where(u => u.ItemID == itemID).FirstOrDefault(); if (i != null) { i.ItemStatus = true; bool update = DAT.DataAccess.UpdateItem(i); if (update) { bool removed = DAT.DataAccess.RemoveBookOut(bookOutID); if (removed) { MessageBox.Show("The items out removal was succesful!"); ((Main)this.Parent.Parent).ChangeView <Pages.StockOut.StockOut>(); } else { MessageBox.Show("The items out removal was unsuccesful!"); i.ItemStatus = false; bool updateAgain = DAT.DataAccess.UpdateItem(i); } } else { MessageBox.Show("The items out removal was unsuccesful!"); } } else { MessageBox.Show("The items out removal was unsuccesful!"); } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
//Margo private void StockBookOutRemoval_Load(object sender, EventArgs e) { try { st = DAT.DataAccess.GetStore().ToList(); List <string> S = new List <string>(); for (int x = 0; x < st.Count; x++) { S.Add(st[x].StoreName); } comboBoxStore.DataSource = S; List <LTS.BookOut> bo = new List <LTS.BookOut>(); bo = DAT.DataAccess.GetBookOut().ToList(); for (int i = 0; i < bo.Count; i++) { BookOutMain b = new BookOutMain(); b.BookOutID = bo[i].BookOutID; b.itemID = bo[i].ItemID; b.UserID = bo[i].UserID; b.Reason = bo[i].Reason; b.Project = bo[i].Project; b.Date = bo[i].Date; LTS.Item it = new LTS.Item(); it = DAT.DataAccess.GetItem().Where(u => u.ItemID == b.itemID).FirstOrDefault(); b.ItemStatus = it.ItemStatus; b.EPC = it.TagEPC; b.ProductID = it.ProductID; b.StoreID = it.StoreID; //get the specific product and assign the info to the ItemMain object LTS.Product p = new LTS.Product(); p = DAT.DataAccess.GetProduct().Where(h => h.ProductID == b.ProductID).FirstOrDefault(); b.ProductName = p.ProductName; b.ProductDescription = p.ProductDescription; b.BrandID = p.BrandID; b.CategoryID = p.CategoryID; b.BarcodeID = p.BarcodeID; //get the specific store and assign the info to the ItemMain object LTS.Store s = new LTS.Store(); s = DAT.DataAccess.GetStore().Where(j => j.StoreID == b.StoreID).FirstOrDefault(); b.StoreName = s.StoreName; b.StoreLocation = s.StoreLocation; //get the specific brand and assign the info to the ItemMain object LTS.Brand br = new LTS.Brand(); br = DAT.DataAccess.GetBrand().Where(y => y.BrandID == b.BrandID).FirstOrDefault(); b.BrandName = br.BrandName; b.BrandDescription = br.BrandDescription; //get the sepcific category and assign the info to the ItemMain object LTS.Category c = new LTS.Category(); c = DAT.DataAccess.GetCategory().Where(z => z.CategoryID == b.CategoryID).FirstOrDefault(); b.CategoryName = c.CategoryName; b.CategoryDescription = c.CategoryDescription; //get the sepcific category and assign the info to the ItemMain object LTS.Barcode ba = new LTS.Barcode(); ba = DAT.DataAccess.GetBarcode().Where(a => a.BarcodeID == b.BarcodeID).FirstOrDefault(); b.BarcodeNumber = ba.BarcodeNumber; LTS.User us = new LTS.User(); us = DAT.DataAccess.GetUser().Where(h => h.UserID == b.UserID).FirstOrDefault(); b.UserIdentityNumber = us.UserIdentityNumber; b.UserName = us.UserName; b.UserSurname = us.UserSurname; bom.Add(b); dataGridView1.Rows.Add(b.BookOutID, b.EPC, b.BarcodeNumber, b.ProductName, b.Reason, b.Project, b.Date, b.UserName, b.UserSurname); } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
//Tiaan private void btnlogin_Click(object sender, EventArgs e) { try { bool ok = true; labelError1.Visible = false; labelError2.Visible = false; labelError3.Visible = false; //change item status to false //make bookOut record if (textBox1.Text == "") { labelError1.Text = "Please enter Booking Out Reason!"; labelError1.Visible = true; ok = false; } if (textBox2.Text == "") { labelError2.Text = "Please enter Project Name!"; labelError2.Visible = true; ok = false; } if (dataGridView1.SelectedRows.Count == 0) { labelError3.Text = "Please select a row from the list!"; labelError3.Visible = true; ok = false; } else if (ok) { LTS.BookOut checkOut = new LTS.BookOut(); LTS.Item p = new LTS.Item(); p = DAT.DataAccess.GetItem().Where(y => y.ItemID == current.itemID).FirstOrDefault(); if (p != null) { checkOut.Reason = textBox1.Text; checkOut.Project = textBox2.Text; checkOut.Date = DateTime.Today; checkOut.UserID = ((Form1)this.Parent.Parent.Parent.Parent).loggedIn.UserID; checkOut.ItemID = p.ItemID; int check = DAT.DataAccess.AddBookOut(checkOut); if (check != -1) { p.ItemStatus = false; bool itemUpdate = DAT.DataAccess.UpdateItem(p); if (itemUpdate) { MessageBox.Show("The product was successfully booked out!"); ((Main)this.Parent.Parent).ChangeView <Pages.StockOut.StockOut>(); } else { bool remove = DAT.DataAccess.RemoveBookOut(check); MessageBox.Show("Sorry something went wrong, the product was not booked out!"); } } else { MessageBox.Show("Sorry something went wrong, the product was not booked out!"); ((Main)this.Parent.Parent).ChangeView <BookStockOut>(); } } } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
private void updateItem_update_click(object sender, EventArgs e) { int iItemId, iStortId, iBarcodeId; int iStortIdx, iBarcodeIdx; label4.Visible = false; label7.Visible = false; iItemId = giItemId; Log.WriteLog(LogType.Trace, "come in updateItem_update_click"); //判断epc合法性 if (tbEpc.Text == "") { label4.Text = "Please enter the RFID Tag!"; label4.Visible = true; } iStortIdx = cbStore.SelectedIndex; iBarcodeIdx = cbBarcode.SelectedIndex; //判断store和barcode的合法性 if (iStortIdx == -1 || iBarcodeIdx == -1) { Log.WriteLog(LogType.Warning, "the store or the barcode has not change yet"); MessageBox.Show("the store or the barcode has not change yet, please change them."); label7.Visible = true; return; } iStortId = listS[iStortIdx].StoreID; iBarcodeId = listBar[iBarcodeIdx].BarcodeID; try { //判断barcode是否绑定了product LTS.Product stProduct = new LTS.Product(); stProduct = DAT.DataAccess.GetProduct().Where(f => f.BarcodeID == iBarcodeId).FirstOrDefault(); if (null == stProduct) { Log.WriteLog(LogType.Warning, "the barcode[" + iBarcodeId + "] has not band with product."); MessageBox.Show("the barcode[" + iBarcodeId + "] has not band with product, please change another barcode."); return; } Log.WriteLog(LogType.Trace, "success to get product[" + stProduct.ProductID + "] which band with barcode[" + iBarcodeId + "]"); //判断epc是否被使用 if (tbEpc.Text != oldEPC) { LTS.Item stTmpItem = DAT.DataAccess.GetItem().Where(i => i.TagEPC == tbEpc.Text).FirstOrDefault(); if (stTmpItem != null) { Log.WriteLog(LogType.Warning, "the ecp[" + tbEpc.Text + "] already been use by item[" + stTmpItem.ItemID + "].Please enter a different one."); label4.Text = "ecp[" + tbEpc.Text + "] already been use! Please enter a different one."; label4.Visible = true; return; } } //判断item是否存在 LTS.Item stItem = DAT.DataAccess.GetItem().Where(d => d.ItemID == iItemId).FirstOrDefault(); if (null == stItem) { Log.WriteLog(LogType.Error, "error to get item[" + iItemId + "] from database"); MessageBox.Show("error to get item[" + iItemId + "] from database"); return; } Log.WriteLog(LogType.Trace, "success to get item[" + iItemId + "] from database"); //更新item信息 stItem.ProductID = stProduct.ProductID; stItem.StoreID = iStortId; stItem.StoreID = iStortId; if (tbEpc.Text != oldEPC) { stItem.TagEPC = tbEpc.Text; } //信息保存到数据库 if (DAT.DataAccess.UpdateItem(stItem)) { Log.WriteLog(LogType.Trace, "success to change item[" + iItemId + "] ecp from[" + oldEPC + "]into[" + tbEpc.Text + "] witch band product with barcode[" + iBarcodeId + "] in store[" + iStortId + "]"); MessageBox.Show("Item has been updated!"); ((Main)this.Parent.Parent).ChangeView <Pages.Items.Items>(); } else { Log.WriteLog(LogType.Trace, "error to change item[" + iItemId + "] ecp from[" + oldEPC + "]into[" + tbEpc.Text + "] witch band product with barcode[" + iBarcodeId + "] in store[" + iStortId + "]"); MessageBox.Show("error to update item info!"); } } catch (Exception ex) { Log.WriteLog(LogType.Error, "there is something wrong during to update item. the error msg is " + ex.Message + ""); MessageBox.Show("there is something wrong during to update item!"); return; } }
//添加一个item,(一个epc只能对应一个item) private void addItem_add_click(object sender, EventArgs e) { Log.WriteLog(LogType.Trace, "addItem_add_click"); lStoreMsg.Visible = false; label16.Visible = false; lBarcodeMsg.Visible = false; lEpcMsg2.Visible = false; lEpcMsg1.Visible = false; try { //判断参数合法性 int storeIndex = cbStore.SelectedIndex; int barcodeIndex = cbBarcode.SelectedIndex; if (storeIndex == -1) { lStoreMsg.Visible = true; Log.WriteLog(LogType.Error, "the store is not select"); return; } if (barcodeIndex == -1) { label16.Visible = true; Log.WriteLog(LogType.Error, "the barcode is not select"); return; } if (textBox2.Text == "") { lEpcMsg1.Visible = true; Log.WriteLog(LogType.Error, "the ecp string is null"); return; } //判断barcode是否绑定了product int barcodeID = listBar[barcodeIndex].BarcodeID; LTS.Product p = DAT.DataAccess.GetProduct().Where(a => a.BarcodeID == barcodeID).FirstOrDefault(); if (p == null) { lBarcodeMsg.Visible = true; Log.WriteLog(LogType.Error, "the barcode[" + barcodeID + "] is not band any product"); return; } Log.WriteLog(LogType.Trace, "the barcode[" + barcodeID + "] is band with product[" + p.ProductID + "]"); //判断这个epc是否已经被使用,一个epc只能对应一个item LTS.Item stItem = DAT.DataAccess.GetItem().Where(b => b.TagEPC == textBox2.Text).FirstOrDefault(); if (stItem != null) { lEpcMsg2.Text = "epc[" + textBox2.Text + "] alreasy be use! Please enter a different one."; Log.WriteLog(LogType.Trace, "the ecp[" + textBox2.Text + "] has already exist, please enter a different one"); lEpcMsg2.Visible = true; return; } //保存item信息 LTS.Item stNewItem = new LTS.Item(); if (stNewItem == null) { Log.WriteLog(LogType.Error, "Error to get new item memery"); MessageBox.Show("error to get memery from system"); return; } stNewItem.StoreID = listS[storeIndex].StoreID; stNewItem.TagEPC = textBox2.Text; stNewItem.ProductID = p.ProductID; stNewItem.ItemStatus = true; int returnedID = DAT.DataAccess.AddItem(stNewItem); if (returnedID == -1) { Log.WriteLog(LogType.Trace, "errir to add item with epc[" + stNewItem.TagEPC + "] and produce[" + stNewItem.ProductID + "] into store[" + stNewItem.StoreID + "]"); MessageBox.Show("Item was not added to the database!"); } else { Log.WriteLog(LogType.Trace, "success to add item[" + returnedID + "] with epc[" + stNewItem.TagEPC + "] and produce[" + stNewItem.ProductID + "] into store[" + stNewItem.StoreID + "]"); MessageBox.Show("Item was succesfully added to the database"); ((Main)this.Parent.Parent).ChangeView <Pages.Items.Items>(); } return; } catch (Exception ex) { Log.WriteLog(LogType.Error, "error to add item into database, the error msg is " + ex.Message + ""); MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
//Devon private void button3_Click(object sender, EventArgs e) { try { lblSelect.Visible = false; label16.Visible = false; label4.Visible = false; label7.Visible = false; if (current.itemID != 0) { if (textBox2.Text == oldEPC) { int itemID = Int32.Parse(label5.Text); LTS.Item olditem = DAT.DataAccess.GetItem().Where(d => d.ItemID == itemID).FirstOrDefault(); bool status = olditem.ItemStatus; int sIndex = comboBoxStore.SelectedIndex; int bIndex = comboBox1.SelectedIndex; if (sIndex == -1 || bIndex == -1) { label7.Visible = true; } else { label7.Visible = false; int storeID = listS[sIndex].StoreID; int barID = listBar[bIndex].BarcodeID; LTS.Product p = new LTS.Product(); p = DAT.DataAccess.GetProduct().Where(f => f.BarcodeID == barID).FirstOrDefault(); int productID; LTS.Item checkTag = DAT.DataAccess.GetItem().Where(b => b.TagEPC == textBox2.Text).FirstOrDefault(); if (p != null) { try { if (textBox2.Text == "") { label4.Text = "Please enter the RFID Tag!"; label4.Visible = true; } else { label4.Visible = false; productID = p.ProductID; LTS.Item newitem = new LTS.Item(); newitem.ItemID = itemID; newitem.ItemStatus = status; newitem.ProductID = productID; newitem.TagEPC = textBox2.Text; newitem.StoreID = storeID; bool check = DAT.DataAccess.UpdateItem(newitem); if (check) { MessageBox.Show("Item has been updated!"); ((Main)this.Parent.Parent).ChangeView <Pages.Items.Items>(); } else { MessageBox.Show("Item has not been updated!"); } } } catch { MessageBox.Show("Item has not been updated!"); } } } } else { LTS.Item ite = DAT.DataAccess.GetItem().Where(i => i.TagEPC == textBox2.Text).FirstOrDefault(); if (ite == null) { int itemID = Int32.Parse(label5.Text); LTS.Item olditem = DAT.DataAccess.GetItem().Where(d => d.ItemID == itemID).FirstOrDefault(); bool status = olditem.ItemStatus; int sIndex = comboBoxStore.SelectedIndex; int bIndex = comboBox1.SelectedIndex; if (sIndex == -1 || bIndex == -1) { label7.Visible = true; } else { label7.Visible = false; int storeID = listS[sIndex].StoreID; int barID = listBar[bIndex].BarcodeID; LTS.Product p = new LTS.Product(); p = DAT.DataAccess.GetProduct().Where(f => f.BarcodeID == barID).FirstOrDefault(); int productID; LTS.Item checkTag = DAT.DataAccess.GetItem().Where(b => b.TagEPC == textBox2.Text).FirstOrDefault(); if (p != null) { try { if (textBox2.Text == "") { label4.Text = "Please enter the RFID Tag!"; label4.Visible = true; } else { label4.Visible = false; productID = p.ProductID; LTS.Item newitem = new LTS.Item(); newitem.ItemID = itemID; newitem.ItemStatus = status; newitem.ProductID = productID; newitem.TagEPC = textBox2.Text; newitem.StoreID = storeID; bool check = DAT.DataAccess.UpdateItem(newitem); if (check) { MessageBox.Show("Item has been updated!"); ((Main)this.Parent.Parent).ChangeView <Pages.Items.Items>(); } else { MessageBox.Show("Item has not been updated!"); } } } catch { MessageBox.Show("Item has not been updated!"); } } } } else { label4.Visible = true; label4.Text = "TAG alreasy exists! Please enter a different one."; } } } else { lblSelect.Visible = true; } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
//Devon private void btnlogin_Click(object sender, EventArgs e) { try { LTS.Item i = new LTS.Item(); int storeIndex = comboBoxStore.SelectedIndex; if (storeIndex == -1) { label45.Visible = true; } else { int storeID = listS[storeIndex].StoreID; i.StoreID = storeID; label45.Visible = false; } int barcodeIndex = comboBox1.SelectedIndex; if (barcodeIndex == -1) { label16.Visible = true; } else { int barcodeID = listBar[barcodeIndex].BarcodeID; LTS.Product p = DAT.DataAccess.GetProduct().Where(a => a.BarcodeID == barcodeID).FirstOrDefault(); LTS.Item checkTag = DAT.DataAccess.GetItem().Where(b => b.TagEPC == textBox2.Text).FirstOrDefault(); label6.Visible = false; if (p != null && checkTag == null) { if (textBox2.Text != "") { i.TagEPC = textBox2.Text; label6.Visible = false; } else { label6.Visible = true; } i.ProductID = p.ProductID; i.ItemStatus = true; label16.Visible = false; int returnedID = DAT.DataAccess.AddItem(i); if (returnedID == -1) { MessageBox.Show("Item was not added to the database!"); } else { MessageBox.Show("Item was succesfully added to the database"); ((Main)this.Parent.Parent).ChangeView <Pages.Items.Items>(); } } else { label6.Visible = true; label6.Text = "TAG alreasy exists! Please enter a different one."; } } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }