예제 #1
0
        public static bool SendFileToPrinter(string szPrinterName, string szFileName)
        {
            FileStream   fileStream   = new FileStream(szFileName, FileMode.Open);
            BinaryReader binaryReader = new BinaryReader(fileStream);

            byte[] array  = new byte[fileStream.Length];
            IntPtr intPtr = new IntPtr(0);
            int    num    = Convert.ToInt32(fileStream.Length);

            byte[] source  = binaryReader.ReadBytes(num);
            IntPtr intPtr2 = Marshal.AllocCoTaskMem(num);

            Marshal.Copy(source, 0, intPtr2, num);
            bool result = RawPrinterHelper.SendBytesToPrinter(szPrinterName, intPtr2, num);

            Marshal.FreeCoTaskMem(intPtr2);
            fileStream.Close();
            return(result);
        }
예제 #2
0
        public void retestare_angajat(string nr_cartela)
        {
            string data  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string data2 = DateTime.Now.ToString("dd-MM-yyyy HH:mm");
            string data3 = data2.Substring(0, 10);
            string ora   = data2.Substring(data2.Length - 5);

            myConnection.Open();
            SqlDataReader sqlDataReader2 = new SqlCommand("SELECT DISTINCT t2.nr_marca, t2.nr_telefon_superv FROM scanare t1 LEFT JOIN personal t2 ON t2.nr_cartela = t1.nr_cartela WHERE t2.plecat != 'da' AND t1.nr_cartela='" + nr_cartela + "'", myConnection).ExecuteReader();
            bool          flag2          = sqlDataReader2.Read();

            if (flag2)
            {
                nr_marca          = sqlDataReader2.GetValue(0).ToString();
                nr_telefon_superv = sqlDataReader2.GetValue(1).ToString();
            }
            myConnection.Close();

            StreamWriter streamWriter = new StreamWriter("textToPrinter.txt", false);

            streamWriter.WriteLine("e PCX;*");
            streamWriter.WriteLine("e IMG;*");
            streamWriter.WriteLine("mm");
            streamWriter.WriteLine("zO");
            streamWriter.WriteLine("J");
            streamWriter.WriteLine("O R,P");
            streamWriter.WriteLine("H100,0,T");
            streamWriter.WriteLine("D 0.0,0.0");
            streamWriter.WriteLine("Sl1;0.0,0.0,10.0,10.0,25.0,25.0,1");
            streamWriter.WriteLine("T4.2,4.0,0,-3,x1,y1;" + nr_marca);
            streamWriter.WriteLine("T2.6,6.6,0,-3,x1,y1;" + data3);
            streamWriter.WriteLine("T6.1,9.2,0,-3,x1,y1;" + ora);
            streamWriter.WriteLine("B17.0,2.5,0,DATAMATRIX,0.50;" + nr_telefon_superv);
            streamWriter.WriteLine("A 1");
            streamWriter.Close();
            RawPrinterHelper.SendFileToPrinter(new PrintDocument().PrinterSettings.PrinterName, "textToPrinter.txt");

            myConnection.Open();
            SqlDataReader sqlDataReader = new SqlCommand("SELECT nr_cartela FROM rezultat WHERE nr_cartela='" + nr_cartela + "'", myConnection).ExecuteReader();
            bool          flag          = sqlDataReader.Read();

            if (flag)
            {
                myConnection.Close();
                myConnection.Open();
                string     query     = "UPDATE rezultat SET data_testare = '" + data + "', rezultat = 'rapid negativ', alte_motive = '' WHERE nr_cartela = '" + nr_cartela + "'";
                SqlCommand myCommand = new SqlCommand(query, this.myConnection);
                myCommand.ExecuteNonQuery();
                myConnection.Close();
                populateGrid();
            }
            else
            {
                myConnection.Close();
                myConnection.Open();
                string     query     = "INSERT INTO rezultat (nr_cartela, data_testare, rezultat, alte_motive) VALUES ('" + nr_cartela + "', '" + data + "', 'rapid negativ' , '')";
                SqlCommand myCommand = new SqlCommand(query, this.myConnection);
                myCommand.ExecuteNonQuery();
                myConnection.Close();
                populateGrid();
            }
            myConnection.Close();
            this.textBox1.Focus();
        }