private void InitializeFiscalPrinter() { var device = Program.UserDevices.FirstOrDefault(x => x.DeviceType == DeviceType.FiscalPrinter); if (device != null && !device.IsConnected) { return; } try { if (_fiscalPrinter == null) { if (device == null) { device = new Device(); device.DeviceType = DeviceType.FiscalPrinter; device.IsConnected = true; Program.UserDevices.Add(device); } HardwareConfigurationSection config; HardwareConfigurationElementCollection hardwareIdsConfig; List <KeyValuePair <string, string> > hardware; config = HardwareConfigurationSection.GetConfiguration(); hardwareIdsConfig = config.HardwareIds; hardware = new List <KeyValuePair <string, string> >(); foreach (HardwareConfigurationElement hardwareId in hardwareIdsConfig) { hardware.Add(new KeyValuePair <string, string>(hardwareId.Name, hardwareId.Id)); } string VID = hardware.FirstOrDefault(x => x.Key == "SerialDevice").Value.Split('&')[0].Replace("VID_", ""); string PID = hardware.FirstOrDefault(x => x.Key == "SerialDevice").Value.Split('&')[1].Replace("PID_", ""); var ports = Common.Helpers.DeviceHelper.GetPortByVPid(VID, PID).Distinct(); //("067B", "2303") var portName = SerialPort.GetPortNames().Intersect(ports).FirstOrDefault(x => !Program.UserDevices.Any(y => y.PortName == x)); this.CheckPort(portName); _fiscalPrinter = new SY50(portName); device.PortName = portName; //MessageBox.Show("Успешно поврзување со касата, на port :: " + portName); } } catch (Exception ex) { device.IsConnected = false; MessageBox.Show(this, "Неуспешно поврзување со Фискалната каса, проверете дали е приклучена!\n\nOpening serial port result :: " + ex.Message, "Информација!"); } }
public FiscalPrinter(Form form) { IntPtr hwnd; if (form == null) { throw new ArgumentNullException("form"); } hwnd = form.Handle; _fiscalPrinter = ((BaseForm)form)._fiscalPrinter; this.InitializeFiscalPrinter(); ((BaseForm)form)._fiscalPrinter = _fiscalPrinter; //HookRawInput(hwnd); //this.HookHandleEvents(form); //this.AssignHandle(hwnd); }
public Sale(SerialPort serialPort, SY50 fiscalPrinter, CustomerType currentCustomer) { InitializeComponent(); this.updateFont(); this._currentCustomer = currentCustomer; this._serialPort = serialPort; this._fiscalPrinter = fiscalPrinter; //if (Program.ActiveForms.Count == 0) this._listener = new BarcodeListener(this); this.SerialEventListener_Start(); this.InitializeFiscalPrinter(); this.KeyPreview = true; this.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyEvent); dataGridView1.AutoGenerateColumns = false; dataGridView1.Columns["Quantity"].DefaultCellStyle.Format = "n"; //dataGridView1.EditMode = DataGridViewEditMode.EditOnKeystroke; //dataGridView1.Columns["Quantity"].ReadOnly = false; //dataGridView1.Columns["UnitPrice"].ReadOnly = false; lblCurrentProduct.Text = string.Empty; lblTotalValue.Text = "0.00"; this.nfi = new NumberFormatInfo(); this.nfi.NumberDecimalSeparator = "."; convertor = new ISO9TransliterationProvider(); myCurrentLanguage = InputLanguage.CurrentInputLanguage; orderDetails = new List <Product>(); this.ActiveControl = dataGridView1; if (this._currentCustomer == CustomerType.HOME) { this.panelTotal.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); } }