public static void SaveLastDocket(LocalDocket currentDocket) { string DPDBLocation = Properties.Settings.Default.DPDBLocation; try { OleDbConnection DPDBconnection = null; DPDBconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data Source=" + DPDBLocation); DPDBconnection.Open(); OleDbCommand docketCmd = DPDBconnection.CreateCommand(); string commandText = @"INSERT INTO Dockets (docket_id, docket_date, raw_content) VALUES ($docket_id, $docket_date,$raw_content)"; commandText = commandText.Replace("$docket_id", currentDocket.local_id.ToString()); commandText = commandText.Replace("$docket_date", "'" + currentDocket.creation_datetime.ToString() + "'"); commandText = commandText.Replace("$raw_content", "'" + currentDocket.receipt_content + "'"); //Save latest transaction. docketCmd.CommandText = commandText; int numRowsAffected = docketCmd.ExecuteNonQuery(); DPDBconnection.Close(); } catch { throw; } }
private void axSerialPortMonitorAx_OnOpenClose(object sender, AxspsnifferLib._ISerialPortMonitorAxEvents_OnOpenCloseEvent e) { AddLog("====================================",false); AddLog("Serial port " + (e.bOpen ? "opened." : "closed"),false); AddLog("====================================",false); string POSapp = e.szPath; if (e.bOpen) { AddLog("Application: " + e.szPath,false); if (POSapp != "" && !POSapp.Contains("DocketPlaceClient")) { is_realapp = true; } } else { if (is_realapp && !String.IsNullOrEmpty(cleanContent)) { AddLog("DocketPlace Footer", true); is_realapp = false; ClearErrorMessages(); //Stop Sniffing. SniffSwitch(); if (Properties.Settings.Default.POSSoftware == "Microsoft") { TriggerCashDrawer(); } if (SendSalesDataCheckBox.Checked) { try { LocalDocket currentDocket = null; switch (Properties.Settings.Default.POSSoftware) { case "MYOB": currentDocket = MYOBRewards.GetLastDocket(rawContent); break; case "Microsoft": currentDocket = MicrosoftRewards.GetLastDocket(rawContent); break; } if (currentDocket != null) { try { AdRequest newRewardsRequest = HydrateAdRequest(); currentDocket.receipt_content = Helpers.EncodeToBase64(cleanContent); newRewardsRequest.currentDocket = currentDocket; printCoupon(false, cleanContent, newRewardsRequest); } catch (System.Net.WebException ex) { RewardsHelper.SaveLastDocket(currentDocket); AddLog(ex.Status.ToString(), true); PrintDefaulltLocalAd(); } } } catch (Exception ex) { AddLog(ex.ToString(), true); PrintDefaulltLocalAd(); } } else { try { AdRequest newRequest = HydrateAdRequest(); LocalDocket nonRewardsDocket = new LocalDocket(); nonRewardsDocket.creation_datetime = DateTime.Now; nonRewardsDocket.receipt_content = Helpers.EncodeToBase64(cleanContent); newRequest.currentDocket = nonRewardsDocket; printCoupon(false, cleanContent, newRequest); } catch (System.Net.WebException ex) { PrintDefaulltLocalAd(); } } //Clear the content in case theres any weird non receipt commands sent to printer afterwards. rawContent = ""; cleanContent = ""; AddLog("DocketPlace Footer Printed", true); //Start Sniffing again. SniffSwitch(); } } }
public static List<LocalDocket> GetStoredDockets() { string DPDBLocation = Properties.Settings.Default.DPDBLocation; List<LocalDocket> unsentDockets = new List<LocalDocket>(); try { OleDbConnection DPDBconnection = null; OleDbDataReader DPdbReader = null; DPDBconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data Source=" + DPDBLocation); DPDBconnection.Open(); OleDbCommand DPdocketCmd = DPDBconnection.CreateCommand(); //Get latest transaction. DPdocketCmd.CommandText = "SELECT docket_id, raw_content from Dockets"; DPdbReader = DPdocketCmd.ExecuteReader(); while (DPdbReader.Read()) { LocalDocket latestDocket = new LocalDocket(); latestDocket.local_id = (int)DPdbReader.GetValue(0); latestDocket.receipt_content = (string)DPdbReader.GetValue(1); unsentDockets.Add(latestDocket); } DPdbReader.Close(); DPDBconnection.Close(); } catch { throw; } return unsentDockets; }