Exemplo n.º 1
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (_serPort != null)
            {
                Cursor.Current = Cursors.WaitCursor;
                try
                {
                    if (!_serPort.IsOpen)
                    {
                        _serPort.Open();
                    }
                    _serPort.WriteTimeout = 15000;
                    //send layout once per session
                    if (!res._bLayoutSended)
                    {
                        string sLayout = res.getLayoutPRN();
                        if (sLayout.Length == 0)
                        {
                            throw new NullReferenceException("LayoutPRN is empty!");
                        }
                        byte[] bLayout = Encoding.UTF8.GetBytes(sLayout);
                        _serPort.Write(bLayout, 0, bLayout.Length);
                        res._bLayoutSended = true;
                    }

                    //string sSample = res.getSamplePRN();
                    string sSample = res.getPriceMark(txtPriceOld.Text, txtPriceNew.Text, _iLang);
                    if (sSample.Length == 0)
                    {
                        throw new NullReferenceException("Print data is empty!");
                    }

                    byte[] bSample = Encoding.UTF8.GetBytes(sSample);
                    _serPort.Write(bSample, 0, bSample.Length);
                }
                catch (Exception ex)
                {
                    Cursor.Current = Cursors.Default;
                    System.Diagnostics.Debug.WriteLine("Exception in print(): " + ex.Message);
                    Helpers.logError("Exception in print(): " + ex.Message);
                    MessageBox.Show("Printing failed. Please restart. " + ex.Message);
                    _serPort.Close();
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
        }