Ejemplo n.º 1
0
        //kjo eshte vetem per kasat e vjetra kur ngel tastiera e bllokuar
        private void button4_Click(object sender, EventArgs e)
        {
            if (Model.Contains("W"))
            {
                return;
            }

            IFiscalPrinter fp     = PrinterFactory.Create(Model);
            int            answer = fp.OpenPort(Model, Key, ComPort, Baud);

            if (answer == 1)
            {
                fp.WriteLine("T,1,______,_,__;");

                if (activeKeyb)
                {
                    fp.WriteLine("F,1,______,_,__;");
                }
            }

            fp.Dispose();
        }
Ejemplo n.º 2
0
        private void testInv()
        {
            int length = 2; //nr rreshtave test qe duam te printojme si test

            loadPrinterSettings();

            //nese nuk po punojme me active keyboard, checkstatus nuk ka kuptim
            if (!activeKeyb)
            {
                checkStatus = false;
            }

            IFiscalPrinter fp = PrinterFactory.Create(Model, checkStatus, activeKeyb);

            try
            {
                if (string.IsNullOrEmpty(txtKey.Text))
                {
                    MessageBox.Show("Ju lutemi te vendosni numrin e licences!", "Kujdes!");
                    return;
                }
                int answer = fp.OpenPort(Model, Key, ComPort, Baud); //nese ku ka lidhje me kasen kjo then NULL dhe nuk kemi fare objekt fiskal
                if (answer == 1)
                {
                    try
                    {
                        string[] inv = { };
                        //read
                        if (!File.Exists("sample.txt"))
                        {
                            MessageBox.Show("Mungon file me komandat");
                            return;
                        }
                        inv = File.ReadAllLines("sample.txt");
                        // check the length of the file
                        if (inv.Length == 0)
                        {
                            MessageBox.Show("Mungon sample.txt file qe ka komenadat e kases");
                            return;
                        }
                        //print
                        string line, nextline = "";
                        for (int i = 0; i < inv.Length; i++)
                        {
                            line = inv[i];
                            //check if next line is discount
                            if (i < inv.Length - 1) //nese ka akoma rreshta
                            {
                                nextline = inv[i + 1];
                            }

                            //nese kemi hapur nje fature jotatimore me komanden J atehere duhet mbyllyr me cript dhe jo tek per tek
                            //pra e mira eshte nese kemi file me info jotatimore i gjithe file te excecutohet si nje script dhe jo tek per tek
                            if (inv[0].StartsWith(("J,1,______,_,__;")))
                            {
                                fp.ExecuteScript(inv);
                                return;
                            }

                            //nese rreshti dyte eshte me C qe nenkupton zbritje dergo te dy rreshtat bashke qe te aplikohet zbritja
                            if (nextline.StartsWith("C,1,______,_,__;", StringComparison.Ordinal))
                            {
                                fp.ExecuteScript(new string[] { line, nextline });
                                i++;                                 //i should be increased as two lines have been printed by the script
                            }

                            else if (fp.WriteLine(inv[i]) == 0)
                            {
                                Console.WriteLine("err: " + inv[i]);
                                MessageBox.Show($"Gabim kominikim me kasen!\rRreshti: {inv[i]}"
                                                , "Konfirmo!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                                return;
                            } //end check if next line is discount
                        }     //end loop
                    }         //end try
                    catch (Exception err)
                    {
                        Console.WriteLine(err.Message);
                    }
                    finally
                    {
                        //fp.stopReading = true;
                        Console.WriteLine("Port disconnected!");
                    }
                }
                else
                {
                    //MessageBox.Show(getError(answer), "Kujdes!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    MessageBox.Show(fp.getError(answer), "Cant Connect");
                    return;
                }
            }
            catch (Exception ex) { MessageBox.Show("Nuk ka lidhje me kasen. Ose kasa fikur ose COM port jo i rregullt. Err: " + ex.ToString()); } //ne kete rast FP nuk eshte inicaizluar fare si objekt se nuk ka patur lidhje me kasen dhe kthen null error
            finally { fp.Dispose(); }
        }