public List <StockShow> ShowStock() { List <StockShow> stockShows = new List <StockShow>(); Connect(); query = @"SELECT Code, Name, Category, ReorderLevel, Opening = ((SELECT COALESCE(SUM(QtyIn), 0) from StockIn where StockIn.Name = ProductsView.Name AND PurchaseDate < '" + DateTime.MinValue + "') -(SELECT COALESCE(SUM(QtyOut), 0) from StockOut where StockOut.Name = ProductsView.Name AND SalesDate < '" + DateTime.MinValue + "')), QtyIn = (SELECT COALESCE(SUM(QtyIn), 0) from StockIn where StockIn.Name = ProductsView.Name AND PurchaseDate BETWEEN '" + DateTime.MinValue + "' AND '" + DateTime.Today + "'), QtyOut = (SELECT COALESCE(SUM(QtyOut), 0) from StockOut where StockOut.Name = ProductsView.Name AND SalesDate BETWEEN '" + DateTime.MinValue + "' AND '" + DateTime.Today + "') FROM ProductsView"; _sqlCommand = new SqlCommand { CommandText = query, Connection = DatabaseConnection.sqlConnection }; _sqlDataReader = _sqlCommand.ExecuteReader(); while (_sqlDataReader.Read()) { if (Convert.ToInt32(_sqlDataReader["Opening"]) == 0 && Convert.ToInt32(_sqlDataReader["QtyIn"]) == 0 && Convert.ToInt32(_sqlDataReader["QtyOut"]) == 0) { continue; } else { StockShow aStockShow = new StockShow { // ExpireDate = Convert.ToDateTime(_sqlDataReader["ExpiredDate"]), Code = _sqlDataReader["Code"].ToString(), Category = _sqlDataReader["Category"].ToString(), Product = _sqlDataReader["Name"].ToString(), Reorder = Convert.ToInt32(_sqlDataReader["ReorderLevel"]), OpeningBalance = Convert.ToInt32(_sqlDataReader["Opening"]), QuantityIn = Convert.ToInt32(_sqlDataReader["QtyIn"]), QuantityOut = Convert.ToInt32(_sqlDataReader["QtyOut"]) }; aStockShow.ClosingBalance = aStockShow.OpeningBalance + aStockShow.QuantityIn - aStockShow.QuantityOut; stockShows.Add(aStockShow); } } DatabaseConnection.sqlConnection.Close(); return(stockShows); }
/// <summary> /// Sample code to hande a couple of different cards based on the identification process /// </summary> /// <returns>None</returns> private async Task HandleCard(SmartCard card, SmartCardReader sender) { string UID = ""; Int64 id = 0; try { // Connect to the card using (SmartCardConnection connection = await card.ConnectAsync()) { // Try to identify what type of card it was IccDetection cardIdentification = new IccDetection(card, connection); await cardIdentification.DetectCardTypeAync(); LogMessage("Connected to card\r\nPC/SC device class: " + cardIdentification.PcscDeviceClass.ToString()); LogMessage("Card name: " + cardIdentification.PcscCardName.ToString()); LogMessage("ATR: " + BitConverter.ToString(cardIdentification.Atr)); if ((cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass) && (cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightC || cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralight || cardIdentification.PcscCardName == Pcsc.CardName.MifareUltralightEV1)) { // Handle MIFARE Ultralight MifareUltralight.AccessHandler mifareULAccess = new MifareUltralight.AccessHandler(connection); // Each read should get us 16 bytes/4 blocks, so doing // 4 reads will get us all 64 bytes/16 blocks on the card for (byte i = 0; i < 4; i++) { byte[] response = await mifareULAccess.ReadAsync((byte)(4 * i)); LogMessage("Block " + (4 * i).ToString() + " to Block " + (4 * i + 3).ToString() + " " + BitConverter.ToString(response)); } byte[] responseUid = await mifareULAccess.GetUidAsync(); UID = BitConverter.ToString(responseUid); //await Notify("UID: " + BitConverter.ToString(responseUid)); } else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.MifareDesfire) { // Handle MIFARE DESfire Desfire.AccessHandler desfireAccess = new Desfire.AccessHandler(connection); Desfire.CardDetails desfire = await desfireAccess.ReadCardDetailsAsync(); LogMessage("DesFire Card Details: " + Environment.NewLine + desfire.ToString()); } else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass && cardIdentification.PcscCardName == Pcsc.CardName.FeliCa) { // Handle Felica LogMessage("Felica card detected"); var felicaAccess = new Felica.AccessHandler(connection); var uid = await felicaAccess.GetUidAsync(); UID = BitConverter.ToString(uid); //await Notify("UID: " + BitConverter.ToString(uid)); } else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass && (cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard1K || cardIdentification.PcscCardName == Pcsc.CardName.MifareStandard4K)) { // Handle MIFARE Standard/Classic LogMessage("MIFARE Standard/Classic card detected"); var mfStdAccess = new MifareStandard.AccessHandler(connection); var uid = await mfStdAccess.GetUidAsync(); UID = BitConverter.ToString(uid);; //await Notify("UID: " + BitConverter.ToString(uid)); ushort maxAddress = 0; switch (cardIdentification.PcscCardName) { case Pcsc.CardName.MifareStandard1K: maxAddress = 0x3f; break; case Pcsc.CardName.MifareStandard4K: maxAddress = 0xff; break; } await mfStdAccess.LoadKeyAsync(MifareStandard.DefaultKeys.FactoryDefault); for (ushort address = 0; address <= maxAddress; address++) { var response = await mfStdAccess.ReadAsync(address, Pcsc.GeneralAuthenticate.GeneralAuthenticateKeyType.MifareKeyA); LogMessage("Block " + address.ToString() + " " + BitConverter.ToString(response)); } } else if (cardIdentification.PcscDeviceClass == Pcsc.Common.DeviceClass.StorageClass && (cardIdentification.PcscCardName == Pcsc.CardName.ICODE1 || cardIdentification.PcscCardName == Pcsc.CardName.ICODESLI || cardIdentification.PcscCardName == Pcsc.CardName.iCodeSL2)) { // Handle ISO15693 LogMessage("ISO15693 card detected"); var iso15693Access = new Iso15693.AccessHandler(connection); var uid = await iso15693Access.GetUidAsync(); UID = BitConverter.ToString(uid); //await Notify("UID: " + BitConverter.ToString(uid)); } else { // Unknown card type // Note that when using the XDE emulator the card's ATR and type is not passed through, so we'll // end up here even for known card types if using the XDE emulator // Some cards might still let us query their UID with the PC/SC command, so let's try: var apduRes = await connection.TransceiveAsync(new Pcsc.GetUid()); if (!apduRes.Succeeded) { LogMessage("Failure getting UID of card, " + apduRes.ToString()); } else { LogMessage("UID: " + BitConverter.ToString(apduRes.ResponseData)); UID = BitConverter.ToString(apduRes.ResponseData); } } // START MANAGING SUP STOCK // UID if (UID != "") { id = ToUID(UID); bool found = false; int i = 0; // check if ID is in left list foreach (var it in AwaySUP) { i++; if (it.IsSameID(id)) { found = true; // set price according to dT int Price = it.GetPrice(); //wait for validation, then move from left to stock await Notify("! Arrivé, durée = " + it.strTime + " Prix: " + Price + " CHF"); //move from Left to Stock try { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Your UI update code goes here StockSUP.Add(it); AwaySUP.Remove(it); StockShow.UpdateLayout(); LeftShow.UpdateLayout(); } ); } catch (Exception ex) { await Notify("Error swapping from away to stock" + ex.ToString()); } } } i = 0; // check if ID is in stock list if (!found) { foreach (var it in StockSUP) { i++; if (it.IsSameID(id)) { found = true; // start time await Notify("! Valide, près à partir !", "Départ"); i = 0; it.StartTimer(); //move from stock to left list try { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Your UI update code goes here! AwaySUP.Add(it); StockSUP.Remove(it); StockShow.UpdateLayout(); LeftShow.UpdateLayout(); } ); } catch (Exception ex) { await Notify("Error swapping from stock to away" + ex.ToString()); } } } } // else, adding to stock list if (!found) { if (isNewTagNewSUP) { await Notify("! Nouvelle planche ajoutée."); isNewTagNewSUP = false; try { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Your UI update code goes here! StockSUP.Add(new SUP(id, SUPCategory[selN])); } ); } catch (Exception ex) { await Notify("Error adding to stock" + ex.ToString()); } showNbStock.Text = StockSUP.Count.ToString(); StockShow.UpdateLayout(); LeftShow.UpdateLayout(); } else { await Notify("! Cette planche n'est pas répértoriée !"); } } } } } catch (Exception ex) { LogMessage("Exception handling card: " + ex.ToString(), NotifyType.ErrorMessage); } }