Exemple #1
0
        //static uint Curr_number = 0; // счетчик
        //static byte status;
        //static byte result;
        static void Main(string[] args)
        {
            //    10 02 46 00 ba 10 03 a8 a8                        ..F.є..ЁЁ

            FPIKS.FPIKS ics = new FPIKS.FPIKS();
            bool connect = ics.FPInit((byte)11,9600,500,500);
            ////ics.FPNullCheck();
            if (connect)
            {
                var info = ics.FPSetCashier(0, "Darth Vader", 0, false);
                Console.WriteLine("Darth Vader:{0}", info);

                info = ics.FPNullCheck();
                Console.WriteLine("FPNullCheck:{0}", info);
                info = ics.FPNullCheck();
                Console.WriteLine("FPNullCheck:{0}", info);
                info = ics.FPInToCash(5000);
                Console.WriteLine("FPNullCheck:{0}", info);
                info = ics.FPComment("far far away", true);
                Console.WriteLine("FPComment:{0}", info);
                info = ics.FPSaleEx(1, 0, true, 5000, 1, false, "0 - Lightsaber", "0");
                Console.WriteLine("FPSaleEx:{0}", info);
                info = ics.FPSaleEx(1, 0, true, 60000, 1, false, "1 - Armor", "1");
                Console.WriteLine("FPSaleEx:{0}", info);
                info = ics.FPComment("in a galaxy", true);
                Console.WriteLine("FPSaleEx:{0}", info);
                info = ics.FPPayment(3, 100000, true, true, "Star Wars");
                Console.WriteLine("FPPayment:{0}", info);
                //ics.FPDayReport(0);
                //Dictionary<string, object> getinfo = ics.getDicInfo;

                //Console.WriteLine(getinfo["Error"]);

                //Dictionary<string, object> KlefMem = ics.getKlefInfo;
                //    Dictionary<string, object> info = ics.getDicInfo;
                //    //if (Convert.ToBoolean(info["SmenaOpened"]) && Convert.ToBoolean(info["BitStatus5"]) && Convert.ToByte(info["ByteStatus"]) == 32)
                //    //{
                //Console.WriteLine(KlefMem["PacketFirst"]);
                //Console.WriteLine(KlefMem["PacketLast"]);
                //Console.WriteLine(KlefMem["FreeMem"]);
                //    //}
                //    //UInt16 tempt = ics.getBeginKLEF;
                //    //UInt16 EndKlef = ics.getEndKLEF;
                //    //bool i = ics.FPGetTaxRates;
                //    //Console.WriteLine("Состояние обрезчика:{0}", ics.GetFPCplCutter);
                //    //Console.WriteLine("Перевод обрезчика:{0}", ics.FPCplCutter());
                //    //Console.WriteLine("Состояние обрезчика:{0}", ics.GetFPCplCutter);
                //    //Console.WriteLine("Перевод обрезчика:{0}", ics.FPCplCutter());
            }
            ics.FPClose();

            Console.ReadKey();
        }
Exemple #2
0
        public void TestConnection(object mu)
        {
            //Mutex mu
            try
            {
                ((Mutex)mu).WaitOne();
                using (SqlConnection con = new SqlConnection(ConnectionString))
                {
                    //con.ConnectionString = ConnectionString;
                    con.Open();
                    ErrorInfo = "";
                    ErrorCode = 0;
                    Error = false;
                    if (con.State == ConnectionState.Closed)
                        con.Open();
                    else if (con.State == ConnectionState.Broken)
                    {
                        con.Close();
                        con.Open();
                    }
                    else if (con.State != ConnectionState.Open)
                    {
                        Thread.Sleep(1000);
                    }

                    if (con.State != ConnectionState.Open)
                    {
                        Error = true;
                        ErrorInfo = "Подключение к SQL не выполнено";
                        ErrorCode = 9997;
                        SetError(Error, ErrorCode, ErrorInfo);
                        if (ics != null)
                            ics.FPClose();
                        ics = null;
                        if (mu!=null)
                            ((Mutex)mu).ReleaseMutex();
                        return;
                    }

                    ics = new FPIKS.FPIKS();

                    Thread.Sleep(1000);
                    //string CurrDir = Path.GetDirectoryName(Assembly.GetAssembly(typeof(FPIKSWork)).CodeBase);
                    //XmlDocument xdoc = new XmlDocument();
                    //xdoc.Load(CurrDir + "\\ConnectionString.xml");
                    //XmlNode list = xdoc.SelectSingleNode("/root/ConnectionString");

                    //ConnectionString = list.InnerText;

                    try
                    {
                        connect = ics.FPInit((byte)Port, 9600, 500, 500);
                    }
                    catch
                    {
                        connect = false;
                    }

                    if (!connect)
                    {
                        Thread.Sleep(1000);
                        Error = true;
                        ErrorInfo = "Подключение не выполнено, не возможно подключиться через COM порт";
                        ErrorCode = 9999;
                        SetError(Error, ErrorCode, ErrorInfo);
                        if (ics != null)
                            ics.FPClose();
                        ics = null;
                        if (mu != null)
                            ((Mutex)mu).ReleaseMutex();
                        return;
                    }

                    Dictionary<string, object> getinfo = ics.getDicInfo;

                    this.FPNumber = Convert.ToInt32(getinfo["SerialNumber"]);//Convert.ToInt32(ics.GetSerialNumber);
                    this.FPVersion = getinfo["HardwareVersion"].ToString();//ics.GetVersion;
                    this.SmenaOpened = Convert.ToBoolean(getinfo["SmenaOpened"]); //ics.GetSmenaOpened;
                    //this.Port = ComPort;

                    if (this.SmenaOpened && Convert.ToBoolean(getinfo["BitStatus5"]) && Convert.ToByte(getinfo["ByteStatus"]) == 032)
                    {
                        ics.FPDayClrReport(0);
                        Error = true;
                    }

                    if (Convert.ToBoolean(getinfo["BitReserv6"]))
                    {
                        ics.FPResetOrder();
                    }
                    getinfo = ics.getDicInfo;
                    setErrorFromGetInfo(getinfo);
                    Dictionary<string, object> KlefInfo = ics.getKlefInfo;
                    setKlef(KlefInfo);

                    //SetError(getinfo, Error, ErrorCode, ErrorInfo);
                    //if (connect)
                    //{
                      //  ics.FPResetOrder();
                        //Error = !ics.FPLineFeed();
                        //if ((Error) && (ics.GetByteStatus==0))
                        //    ics.FPDayClrReport(0);
                    //}
                    con.Close();
                    con.Dispose();
                }
            }
            catch (Exception ex)
            {
                EventLog m_EventLog = new EventLog("");
                m_EventLog.Source = "FPIKSErrors";
                m_EventLog.WriteEntry("Ошибка в работе сервиса::TestConnection:" + ex.Message +"Port:"+Port.ToString(),
                    EventLogEntryType.Warning);
                m_EventLog = null;
                Error = true;
                ErrorCode = 9999;
                ErrorInfo = "Ошибка в работе сервиса::TestConnection:" + ex.Message;
            }
            finally
            {

                SetError(Error, ErrorCode, ErrorInfo);
                if (ics!=null)
                    ics.FPClose();
                ics = null;

                //if((con!=null)&&(con.State==ConnectionState.Open))
                //    con.Close();
                //con.Dispose();
                //con = null;
                //Thread.Sleep(1000);
                try
                {
                    if (mu != null)
                        ((Mutex)mu).ReleaseMutex();
                }
                catch (Exception ex)
                {
                    mu = null;
                    EventLog m_EventLog = new EventLog("");
                    m_EventLog.Source = "FPIKSErrors";
                    m_EventLog.WriteEntry("Ошибка в работе сервиса::TestConnection:((Mutex)mu).ReleaseMutex()" + ex.Message + "Port:" + Port.ToString(),
                        EventLogEntryType.Warning);
                    m_EventLog = null;
                    Error = true;
                    ErrorCode = 9999;
                    ErrorInfo = "Ошибка в работе сервиса::TestConnection:" + ex.Message;
                }
            }
               // return !Error;
        }
Exemple #3
0
        public void Startjob(object mu)
        {
            ((Mutex)mu).WaitOne();
            TimeSpan diff = DateTime.Now - lastTime;
            if (diff.Seconds<=2)
            {
                Random xrnd = new Random();
                Thread.Sleep(xrnd.Next(5, 20) * 1000);
            }
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                con.ConnectionString = ConnectionString;
                con.Open();

                if (con.State == ConnectionState.Closed)
                    con.Open();
                else if (con.State == ConnectionState.Broken)
                {
                    con.Close();
                    Thread.Sleep(1000);
                    con.Open();
                }
                else if (con.State != ConnectionState.Open)
                {
                    Thread.Sleep(1000);
                }
                if (con.State != ConnectionState.Open)
                {
                    //Если что-то с SQL просто подождем следующий раз.
                    //_SetErrorVersion();
                    if (ics != null)
                        ics.FPClose();
                    ics = null;
                    ((Mutex)mu).ReleaseMutex();
                    return;
                }

                ics = new FPIKS.FPIKS();
                try
                {
                    connect = ics.FPInit((byte)Port, 9600, 50, 50);
                }
                catch
                {
                    connect = false;
                }

                if (!connect)
                {
                    //Thread.Sleep(1000);
                    Error = true;
                    ErrorInfo = "Подключение не выполнено, не возможно подключиться через COM порт";
                    ErrorCode = 9999;
                    SetError(Error, ErrorCode, ErrorInfo);
                    if (ics != null)
                        ics.FPClose();
                    ics = null;

                    ((Mutex)mu).ReleaseMutex();
                    return;
                }
                Dictionary<string, object> getinfo = null;
                try
                {
                    getinfo  = ics.getDicInfo;
                }
                catch(Exception ex)
                {
                    Error = true;
                    ErrorCode = 9999;
                    ErrorInfo = "Ошибка в работе сервиса::Startjob::getDicInfo:" + ex.Message;
                    SetError(Error, ErrorCode, ErrorInfo);
                    if (ics != null)
                        ics.FPClose();
                    ics = null;
                    ((Mutex)mu).ReleaseMutex();
                    return;
                }

                this.FPNumber = Convert.ToInt32(getinfo["SerialNumber"]);//Convert.ToInt32(ics.GetSerialNumber);
                this.SmenaOpened = Convert.ToBoolean(getinfo["SmenaOpened"]); //ics.GetSmenaOpened;

                if (this.FPNumber == 0) //заглушка что бы не попадались нулевые
                {
                    Error = true;
                    ErrorCode = 9995;
                    ErrorInfo = "Запрещено 0 FPNumber::Startjob::getDicInfo:";
                    SetError(Error, ErrorCode, ErrorInfo);
                    ics.FPClose();
                    ics = null;
                    ((Mutex)mu).ReleaseMutex();
                    return;
                    //         }
                }

                this.FPVersion = getinfo["HardwareVersion"].ToString();

                if ((this.FPVersion != "ЕП-06") || (this.FPVersion == "")) //заглушка что бы не попадались нулевые
                {

                    _SetErrorVersion();
                    ics.FPClose();
                    ics = null;
                    ((Mutex)mu).ReleaseMutex();
                    return;
                    //         }
                }

                if (setErrorFromGetInfo(getinfo))
                {
                    ics.FPClose();
                    ics = null;
                    ((Mutex)mu).ReleaseMutex();
                    return;
                }

                try
                {
                    if (ics.GetNumZReport==null)
                    {
                        _SetErrorIcsConnection();
                        ics.FPClose();
                        ics = null;
                        ((Mutex)mu).ReleaseMutex();
                        return;
                    }
                }
                catch
                {
                    _SetErrorIcsConnection();
                    ics.FPClose();
                    ics = null;
                    ((Mutex)mu).ReleaseMutex();
                    return;
                }

                Dictionary<string, object> KlefInfo = ics.getKlefInfo;
                setKlef(KlefInfo);

                //}

                //this.Port = ComPort;
                //con = new SqlConnection(ConnectionString);

                //this.con.ConnectionString = ConnectionString;
                //con.Open();

                bool info = false;
                //DateTime now = DateTime.Now.AddDays(-1).AddSeconds(-30).AddHours(3); // по старому, по новому уже все в скуле
                DateTime now = DateTime.Now;

                _SetInfoAndPapStat(ics.GetPapStat, now, ics.CurrentDate, ics.CurrentTime,ics.GetByteStatus,ics.GetByteResult,ics.GetByteReserv);

                Int64 Time = Convert.ToInt64(now.ToString("yyyyMMddHHmmss"));

                using (SqlCommand command = new SqlCommand(@"
                                                            SELECT TOP 1
                                                            Operations.[id]
                                                            ,Operations.[NumSlave]
                                                            ,Operations.[DateTime]
                                                            ,Operations.[FPNumber]
                                                            ,Operations.[Operation]
                                                            ,Operations.[Closed]
                                                            ,ComInit.[DeltaTime]
                                                        FROM [FPWork].[dbo].[tbl_Operations] Operations with(rowlock)
                                                        inner join [FPWork].dbo.tbl_ComInit ComInit ON ComInit.[FPNumber]=Operations.FPNumber and Operations.[DateTime] between ComInit.DateTimeBegin and ComInit.DateTimeStop
                                                        where       [Closed]=0
                                                                and ComInit.FPNumber=@FPNumber
                                                                and isnull(Operations.Error,0)=0
                                                                and isnull(ComInit.Error,0)=0
                                                                and [DateTime]<=replace(convert(varchar, DATEADD(ss, ComInit.[DeltaTime], @TimeNow),111),'/','')+replace(convert(varchar, DATEADD(ss, ComInit.[DeltaTime], @TimeNow),108),':','')
                                                                and isnull([Disable],0)<>1
                                                        order by DateTime", con))
                {
                    command.Parameters.Add("@FPNumber", SqlDbType.Int);command.Parameters["@FPNumber"].Value = FPNumber;
                    //command.Parameters.Add("@WorkDate", SqlDbType.BigInt);
                    //command.Parameters["@WorkDate"].Value = Time;
                    command.Parameters.Add("@TimeNow", SqlDbType.DateTime);command.Parameters["@TimeNow"].Value = now;
                    command.CommandTimeout = sqltimeout;
                    //command.Transaction = trans;
                    using (SqlDataReader reader = command.ExecuteReader())
                    {

                        int ByteStatus = 0;
                        int ByteResult = 0;
                        //int ErrorByteStatus = 0;
                        //int ErrorByteResult = 0;
                        bool CloseOperation = true;

                        while (reader.Read())
                        {
                            SetSQLInWork(FPNumber, (Int64)reader["DateTime"], (int)reader["Operation"]);

                            if (Convert.ToInt16(reader["Operation"]) == 39) //Печатаем Z-отчет
                            {
                                if (ics.GetFPCplCutter)
                                    ics.FPCplCutter();
                                if (!ics.GetSmenaOpened)
                                {

                                    ics.SetDateTime(now.AddSeconds((Int64)reader["DeltaTime"]));
                                    ics.FPNullCheck();
                                    InCashCurrent(FPNumber);

                                }
                                //Обновляем статусы перед Z отчетом
                                try
                                {
                                    SetInfo((int)reader["FPNumber"], (Int64)reader["DateTime"], (int)reader["Operation"]);
                                }
                                catch (Exception ex)
                                {
                                    EventLog m_EventLog = new EventLog("");
                                    m_EventLog.Source = "FPIKSErrors";
                                    m_EventLog.WriteEntry("Ошибка в работе сервиса::SetInfo:" + ex.Message,
                                    EventLogEntryType.Warning);
                                    m_EventLog = null;
                                }

                                info = PrintZ(out ByteStatus, out ByteResult, out ByteReserv);
                                _SetErrorVersion();
                            }
                            else if (Convert.ToInt16(reader["Operation"]) == 35) //Печатаем X-отчет
                            {
                                if (ics.GetFPCplCutter)
                                    ics.FPCplCutter();
                                if (!ics.GetSmenaOpened)
                                {
                                    ics.SetDateTime(now.AddSeconds((Int64)reader["DeltaTime"]));
                                    ics.FPNullCheck();
                                }
                                info = PrintX(out ByteStatus, out ByteResult, out ByteReserv);
                            }
                            else if (Convert.ToInt16(reader["Operation"]) == 40) //Печатаем периодического отчета
                            {
                                if (ics.GetFPCplCutter)
                                    ics.FPCplCutter();
                                DateTime LastMonthLastDate = DateTime.Today.AddDays(0 - DateTime.Today.Day);
                                DateTime LastMonthFirstDate = LastMonthLastDate.AddDays(1 - LastMonthLastDate.Day);

                                if (DateTime.Today.Day >= 21)
                                {
                                    LastMonthFirstDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                                    LastMonthLastDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 20);
                                }
                                else if (DateTime.Today.Day > 10 && DateTime.Today.Day < 20)
                                {
                                    LastMonthFirstDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                                    LastMonthLastDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 10);
                                }

                                info = PeriodicReport(out ByteStatus, out ByteResult, out ByteReserv, LastMonthFirstDate, LastMonthLastDate);
                            }
                            else if (Convert.ToInt16(reader["Operation"]) == 12) //Печатаем чек
                            {
                                if (!ics.GetSmenaOpened)
                                {
                                    if (ics.GetFPCplCutter)
                                        ics.FPCplCutter();
                                    ics.SetDateTime(now.AddSeconds((Int64)reader["DeltaTime"]));
                                    ics.FPNullCheck();
                                    InCashCurrent(FPNumber);
                                }
                                if (!ics.GetFPCplCutter)
                                    ics.FPCplCutter();
                                    SqlCommand cmd = new SqlCommand(@"SELECT TOP 1
                                                                [Payment].id
                                                                ,[Payment].NumOperation
                                                                ,[Payment].[DATETIME]
                                                                ,[Payment].[FPNumber]
                                                                ,[Payment].[Type]
                                                                ,[Payment].[FRECNUM]
                                                                ,[Payment].[Payment_Status]
                                                                ,[Payment].[Payment]
                                                                ,[Payment].[Payment0]
                                                                ,[Payment].[Payment1]
                                                                ,[Payment].[Payment2]
                                                                ,[Payment].[Payment3]
                                                                ,[Payment].[CheckClose]
                                                                ,[Payment].[FiscStatus]
                                                                ,[Payment].[Comment]
                                                                ,isnull([Payment].[CheckSum],0) [CheckSum]
                                                                ,isnull([Payment].[PayBonus],0) [PayBonus]
                                                                ,isnull([Payment].[BousInAcc],0) [BousInAcc]
                                                                ,isnull([Payment].[BonusCalc],0) [BonusCalc]
                                                                ,isnull([Payment].[Card],0) [Card]
                                                                ,isnull([Payment].[RowCount],0) [RowCount]
                                                            FROM [FPWork].[dbo].[tbl_Payment] [Payment] with(rowlock)
                                                            inner join [FPWork].dbo.tbl_ComInit ComInit ON ComInit.[FPNumber]=[Payment].FPNumber
                                                            where       DATETIME=@DATETIME
                                                                    AND Payment.id=@NumPayment
                                                                    AND Payment.NumOperation=@NumOperation
                                                                    AND ComInit.FPNumber=@FPNumber
                                                                    and Type=0 and isnull([Payment].[RowCount],0) > 0
                                                            ", con);
                                    cmd.Parameters.Add("@FPNumber", SqlDbType.Int); cmd.Parameters["@FPNumber"].Value = FPNumber;
                                    cmd.Parameters.Add("@NumOperation", SqlDbType.BigInt); cmd.Parameters["@NumOperation"].Value = reader["id"];
                                    cmd.Parameters.Add("@NumPayment", SqlDbType.BigInt); cmd.Parameters["@NumPayment"].Value = reader["NumSlave"];
                                    cmd.Parameters.Add("@DATETIME", SqlDbType.BigInt); cmd.Parameters["@DATETIME"].Value = reader["DateTime"];
                                    //cmd.Transaction = tr;
                                    cmd.CommandTimeout = sqltimeout;
                                    SqlDataReader rdr = cmd.ExecuteReader();

                                    if (rdr.Read())
                                    {
                                        List<object> Dop = new List<object>();
                                        Dop.Add(rdr["CheckSum"]);
                                        Dop.Add(rdr["PayBonus"]);
                                        Dop.Add(rdr["BousInAcc"]);
                                        Dop.Add(rdr["BonusCalc"]);
                                        Dop.Add(rdr["Card"]);
                                        Int64 SumCheck = 0;
                                        info = PrintCheck(Convert.ToUInt64(rdr["id"])
                                                                    , Convert.ToUInt32(rdr["Payment"])
                                                                    , Convert.ToUInt32(rdr["Payment0"])
                                                                    , Convert.ToUInt32(rdr["Payment1"])
                                                                    , Convert.ToUInt32(rdr["Payment2"])
                                                                    , Convert.ToUInt32(rdr["Payment3"])
                                                                    , Convert.ToBoolean(rdr["CheckClose"])
                                                                    , Convert.ToBoolean(rdr["FiscStatus"])
                                                                    , rdr["Comment"].ToString()
                                                                    , Convert.ToInt32(rdr["FPNumber"])
                                                                    , Convert.ToUInt64(rdr["DateTime"])
                                                                    , Convert.ToInt32(rdr["FRECNUM"])
                                                                    , out ByteStatus
                                                                    , out ByteResult
                                                                    , out ByteReserv
                                                                    , out CloseOperation
                                                                    , Dop
                                                                    , out SumCheck
                                                                    , Convert.ToUInt32(rdr["RowCount"]));

                                        using (SqlCommand commandUpdate = new SqlCommand(@"UPDATE [FPWork].[dbo].[tbl_Payment]
                                                                        SET
                                                                            [ByteStatus] = @ByteStatus
                                                                            ,[ByteResult] = @ByteResult
                                                                            ,[ByteReserv] = @ByteReserv
                                                                            ,[Error]=@Error
                                                                            ,[FPSumm]=@FPSumm
                                                                        WHERE
                                                                            [id]=@id
                                                                            and [DateTime]=@DateTime
                                                                            and [FPNumber]=@FPNumber
                                                                            ", con))
                                        {
                                            commandUpdate.Parameters.Add("@id", SqlDbType.BigInt); commandUpdate.Parameters["@id"].Value = rdr["id"];
                                            commandUpdate.Parameters.Add("@DateTime", SqlDbType.BigInt); commandUpdate.Parameters["@DateTime"].Value = rdr["DateTime"];
                                            commandUpdate.Parameters.Add("@FPNumber", SqlDbType.Int); commandUpdate.Parameters["@FPNumber"].Value = rdr["FPNumber"];
                                            commandUpdate.Parameters.Add("@ByteStatus", SqlDbType.Int); commandUpdate.Parameters["@ByteStatus"].Value = ByteStatus;
                                            commandUpdate.Parameters.Add("@ByteResult", SqlDbType.Int); commandUpdate.Parameters["@ByteResult"].Value = ByteResult;
                                            commandUpdate.Parameters.Add("@ByteReserv", SqlDbType.Int); commandUpdate.Parameters["@ByteReserv"].Value = ByteReserv;
                                            commandUpdate.Parameters.Add("@Error", SqlDbType.Bit); commandUpdate.Parameters["@Error"].Value = !info;
                                            commandUpdate.Parameters.Add("@FPSumm", SqlDbType.BigInt); commandUpdate.Parameters["@FPSumm"].Value = SumCheck;
                                            commandUpdate.CommandTimeout = sqltimeout;
                                            //commandUpdate.Transaction = tr;
                                            commandUpdate.ExecuteNonQuery();
                                            commandUpdate.Dispose();
                                        }

                                    }

                                    rdr.Close();

                            }
                            else if (Convert.ToInt16(reader["Operation"]) == 5) //Печатаем чек возврата
                            {
                                if (!ics.GetFPCplCutter)
                                    ics.FPCplCutter();
                                SqlCommand cmd = new SqlCommand(@"SELECT TOP 1
                                                                [Payment].id
                                                                ,[Payment].NumOperation
                                                                ,[Payment].[DATETIME]
                                                                ,[Payment].[FPNumber]
                                                                ,[Payment].[Type]
                                                                ,[Payment].[FRECNUM]
                                                                ,[Payment].[Payment_Status]
                                                                ,[Payment].[Payment]
                                                                ,[Payment].[Payment0]
                                                                ,[Payment].[Payment1]
                                                                ,[Payment].[Payment2]
                                                                ,[Payment].[Payment3]
                                                                ,[Payment].[CheckClose]
                                                                ,[Payment].[FiscStatus]
                                                                ,[Payment].[Comment]
                                                                ,isnull([Payment].[CheckSum],0) [CheckSum]
                                                                ,isnull([Payment].[PayBonus],0) [PayBonus]
                                                                ,isnull([Payment].[BousInAcc],0) [BousInAcc]
                                                                ,isnull([Payment].[BonusCalc],0) [BonusCalc]
                                                                ,isnull([Payment].[Card],0) [Card]
                                                            FROM [FPWork].[dbo].[tbl_Payment] [Payment] with(rowlock)
                                                            inner join [FPWork].dbo.tbl_ComInit ComInit ON ComInit.[FPNumber]=[Payment].FPNumber
                                                            where       Payment.DATETIME=@DATETIME
                                                                    AND Payment.id=@NumPayment
                                                                    AND Payment.NumOperation=@NumOperation
                                                                    AND ComInit.FPNumber=@FPNumber
                                                                    and [Payment].Type=1
                                                            ", con);
                                cmd.Parameters.Add("@FPNumber", SqlDbType.Int); cmd.Parameters["@FPNumber"].Value = FPNumber;
                                cmd.Parameters.Add("@NumOperation", SqlDbType.BigInt); cmd.Parameters["@NumOperation"].Value = reader["id"];
                                cmd.Parameters.Add("@NumPayment", SqlDbType.BigInt); cmd.Parameters["@NumPayment"].Value = reader["NumSlave"];
                                cmd.Parameters.Add("@DATETIME", SqlDbType.BigInt); cmd.Parameters["@DATETIME"].Value = reader["DateTime"];
                                //cmd.Transaction = trans;
                                cmd.CommandTimeout = sqltimeout;
                                SqlDataReader rdr = cmd.ExecuteReader();

                                if (rdr.Read())
                                {
                                    List<object> Dop = new List<object>();
                                    Dop.Add(rdr["CheckSum"]);
                                    Dop.Add(rdr["PayBonus"]);
                                    Dop.Add(rdr["BousInAcc"]);
                                    Dop.Add(rdr["BonusCalc"]);
                                    Dop.Add(rdr["Card"]);
                                    Int64 SumCheck = 0;
                                    info = PrintCheckPay(Convert.ToUInt64(rdr["id"])
                                                                , Convert.ToUInt32(rdr["Payment"])
                                                                , Convert.ToUInt32(rdr["Payment0"])
                                                                , Convert.ToUInt32(rdr["Payment1"])
                                                                , Convert.ToUInt32(rdr["Payment2"])
                                                                , Convert.ToUInt32(rdr["Payment3"])
                                                                , Convert.ToBoolean(rdr["CheckClose"])
                                                                , Convert.ToBoolean(rdr["FiscStatus"])
                                                                , rdr["Comment"].ToString()
                                                                , Convert.ToInt32(rdr["FPNumber"])
                                                                , Convert.ToUInt64(rdr["DateTime"])
                                                                , Convert.ToInt32(rdr["FRECNUM"])
                                                                , out ByteStatus
                                                                , out ByteResult
                                                                , out ByteReserv
                                                                , out CloseOperation
                                                                , Dop
                                                                , out SumCheck);

                                    using (SqlCommand commandUpdate = new SqlCommand(@"UPDATE [FPWork].[dbo].[tbl_Payment]
                                                                        SET
                                                                            [ByteStatus] = @ByteStatus
                                                                            ,[ByteResult] = @ByteResult
                                                                            ,[ByteReserv] = @ByteReserv
                                                                            ,[Error]=@Error
                                                                            ,[FPSumm]=@FPSumm
                                                                        WHERE
                                                                            [id]=@id
                                                                            and [DateTime]=@DateTime
                                                                            and [FPNumber]=@FPNumber
                                                                            ", con))
                                    {
                                        commandUpdate.Parameters.Add("@id", SqlDbType.BigInt); commandUpdate.Parameters["@id"].Value = rdr["id"];
                                        commandUpdate.Parameters.Add("@DateTime", SqlDbType.BigInt); commandUpdate.Parameters["@DateTime"].Value = rdr["DateTime"];
                                        commandUpdate.Parameters.Add("@FPNumber", SqlDbType.Int); commandUpdate.Parameters["@FPNumber"].Value = rdr["FPNumber"];
                                        commandUpdate.Parameters.Add("@ByteStatus", SqlDbType.Int); commandUpdate.Parameters["@ByteStatus"].Value = ByteStatus;
                                        commandUpdate.Parameters.Add("@ByteResult", SqlDbType.Int); commandUpdate.Parameters["@ByteResult"].Value = ByteResult;
                                        commandUpdate.Parameters.Add("@ByteReserv", SqlDbType.Int); commandUpdate.Parameters["@ByteReserv"].Value = ByteReserv;
                                        commandUpdate.Parameters.Add("@Error", SqlDbType.Bit); commandUpdate.Parameters["@Error"].Value = !info;
                                        commandUpdate.Parameters.Add("@FPSumm", SqlDbType.BigInt); commandUpdate.Parameters["@FPSumm"].Value = SumCheck;
                                        commandUpdate.CommandTimeout = sqltimeout;
                                        //commandUpdate.Transaction = tr;
                                        commandUpdate.ExecuteNonQuery();
                                        commandUpdate.Dispose();
                                    }

                                }

                                rdr.Close();
                            }
                            else if (Convert.ToInt16(reader["Operation"]) == 3) //Смена кассира
                            {
                                SqlCommand cmd = new SqlCommand(@"SELECT TOP 1
                                                                [Cashiers].[id]
                                                                ,[Cashiers].[DATETIME]
                                                                ,[Cashiers].[FPNumber]
                                                                ,[Cashiers].[Num_Cashier]
                                                                ,[Cashiers].[Name_Cashier]
                                                                ,[Cashiers].[Pass_Cashier]
                                                                ,[Cashiers].[TakeProgName]
                                                            FROM [FPWork].[dbo].[tbl_Cashiers] [Cashiers] with(rowlock)
                                                            inner join [FPWork].dbo.tbl_ComInit ComInit ON ComInit.[FPNumber]=[Cashiers].FPNumber
                                                            where [Cashiers].DATETIME=@DATETIME AND ComInit.FPNumber=@FPNumber
                                                            ", con);
                                cmd.Parameters.Add("@FPNumber", SqlDbType.Int); cmd.Parameters["@FPNumber"].Value = FPNumber;
                                cmd.Parameters.Add("@DATETIME", SqlDbType.BigInt); cmd.Parameters["@DATETIME"].Value = reader["DateTime"];
                                //cmd.Transaction = trans;
                                cmd.CommandTimeout = sqltimeout;
                                SqlDataReader rdr = cmd.ExecuteReader();

                                if (rdr.Read())
                                {
                                    info = ChangeCashiers(rdr["Name_Cashier"].ToString(), out ByteStatus, out ByteResult, out ByteReserv);
                                }

                                rdr.Close();

                            }
                            else if (Convert.ToInt16(reader["Operation"]) == 10) //внесение денег
                            {
                                if (ics.GetFPCplCutter)
                                    ics.FPCplCutter();
                                if (!ics.GetSmenaOpened)
                                {

                                    ics.SetDateTime(now.AddSeconds((Int64)reader["DeltaTime"]));
                                    ics.FPNullCheck();
                                    InCashCurrent(FPNumber);
                                }
                                SqlCommand cmd = new SqlCommand(@"SELECT TOP 1
                                                                [CashIO].[id]
                                                                ,[CashIO].[DATETIME]
                                                                ,[CashIO].[FPNumber]
                                                                ,[CashIO].[Type]
                                                                ,[CashIO].[Money]
                                                            FROM [FPWork].[dbo].[tbl_CashIO] [CashIO] with(rowlock)
                                                            inner join [FPWork].dbo.tbl_ComInit ComInit ON ComInit.[FPNumber]=[CashIO].FPNumber
                                                            where [CashIO].DATETIME=@DATETIME AND ComInit.FPNumber=@FPNumber and [CashIO].Type=0
                                                            ", con);
                                cmd.Parameters.Add("@FPNumber", SqlDbType.Int); cmd.Parameters["@FPNumber"].Value = FPNumber;
                                cmd.Parameters.Add("@DATETIME", SqlDbType.BigInt); cmd.Parameters["@DATETIME"].Value = reader["DateTime"];
                                //cmd.Transaction = trans;
                                cmd.CommandTimeout = sqltimeout;
                                SqlDataReader rdr = cmd.ExecuteReader();

                                if (rdr.Read())
                                {
                                    info = InToCash(Convert.ToUInt32(rdr["Money"]), out ByteStatus, out ByteResult, out ByteReserv);
                                }

                                rdr.Close();
                            }
                            else if (Convert.ToInt16(reader["Operation"]) == 15) //вынос денег
                            {
                                if (ics.GetFPCplCutter)
                                    ics.FPCplCutter();
                                SqlCommand cmd = new SqlCommand(@"SELECT TOP 1
                                                                 [CashIO].[id]
                                                                ,[CashIO].[DATETIME]
                                                                ,[CashIO].[FPNumber]
                                                                ,[CashIO].[Type]
                                                                ,[CashIO].[Money]
                                                            FROM [FPWork].[dbo].[tbl_CashIO] [CashIO] with(rowlock)
                                                            inner join [FPWork].dbo.tbl_ComInit ComInit ON ComInit.[FPNumber]=[CashIO].FPNumber
                                                            where [CashIO].DATETIME=@DATETIME AND ComInit.FPNumber=@FPNumber and [CashIO].Type=1
                                                            ", con);
                                cmd.Parameters.Add("@FPNumber", SqlDbType.Int); cmd.Parameters["@FPNumber"].Value = FPNumber;
                                cmd.Parameters.Add("@DATETIME", SqlDbType.BigInt); cmd.Parameters["@DATETIME"].Value = reader["DateTime"];
                                //cmd.Transaction = trans;
                                cmd.CommandTimeout = sqltimeout;
                                SqlDataReader rdr = cmd.ExecuteReader();

                                if (rdr.Read())
                                {
                                    UInt32 MaxMoney = (UInt32)Math.Min(Convert.ToDecimal(rdr["Money"]), (ics.GetMoneyInBox));
                                    if (MaxMoney > 40000)
                                    {
                                        string s_MaxMOney = MaxMoney.ToString();
                                        UInt32 Ost = Convert.ToUInt32("3" + s_MaxMOney.Substring(s_MaxMOney.Length - 4, 4));
                                        MaxMoney = MaxMoney - Ost;
                                    }
                                    info = OutOfCash(MaxMoney, out ByteStatus, out ByteResult, out ByteReserv);
                                }

                                rdr.Close();
                            }

                            using (SqlCommand commandUpdate = new SqlCommand(@"UPDATE [FPWork].[dbo].[tbl_Operations]
                                                                            SET [Closed] = @info
                                                                                ,Error= case when @info=0 and InWork=1 and @Error=0 then 1 else @Error end
                                                                                ,InWork=case when @info=1 and InWork=1 and Error=0 then 0 else InWork end
                                                                                ,ByteStatus=@ByteStatus
                                                                                ,ByteResult=@ByteResult
                                                                                ,ByteReserv=@ByteReserv
                                                                                ,CurentDateTime=@CurentDateTime
                                                                        WHERE [DateTime]=@DateTime
                                                                                and [id]=@NumOperation
                                                                                and FPNumber=@FPNumber
                                                                                and Operation=@Operation
                                                                        ", con))
                            {

                                commandUpdate.Parameters.Add("@FPNumber", SqlDbType.Int); commandUpdate.Parameters["@FPNumber"].Value = reader["FPNumber"];
                                commandUpdate.Parameters.Add("@NumOperation", SqlDbType.BigInt); commandUpdate.Parameters["@NumOperation"].Value = reader["id"];
                                commandUpdate.Parameters.Add("@DateTime", SqlDbType.BigInt); commandUpdate.Parameters["@DateTime"].Value = reader["DateTime"];
                                commandUpdate.Parameters.Add("@Operation", SqlDbType.Int); commandUpdate.Parameters["@Operation"].Value = reader["Operation"];
                                commandUpdate.Parameters.Add("@info", SqlDbType.Bit); commandUpdate.Parameters["@info"].Value = CloseOperation;
                                commandUpdate.Parameters.Add("@Error", SqlDbType.Bit); commandUpdate.Parameters["@Error"].Value = !info;
                                commandUpdate.Parameters.Add("@ByteStatus", SqlDbType.Int); commandUpdate.Parameters["@ByteStatus"].Value = ByteStatus;
                                commandUpdate.Parameters.Add("@ByteResult", SqlDbType.Int); commandUpdate.Parameters["@ByteResult"].Value = ByteResult;
                                commandUpdate.Parameters.Add("@ByteReserv", SqlDbType.Int); commandUpdate.Parameters["@ByteReserv"].Value = ByteReserv;
                                commandUpdate.Parameters.Add("@CurentDateTime", SqlDbType.DateTime); commandUpdate.Parameters["@CurentDateTime"].Value = DateTime.Now;
                                //ics.FPClose();
                                commandUpdate.CommandTimeout = sqltimeout;
                                commandUpdate.ExecuteNonQuery();
                                commandUpdate.Dispose();
                            }
                            try
                            {
                                SetInfo((int)reader["FPNumber"], (Int64)reader["DateTime"], (int)reader["Operation"]);
                            }
                            catch (Exception ex)
                            {
                                EventLog m_EventLog = new EventLog("");
                                m_EventLog.Source = "FPIKSErrors";
                                m_EventLog.WriteEntry("Ошибка в работе сервиса::SetInfo:" + ex.Message,
                                EventLogEntryType.Warning);
                                m_EventLog = null;
                            }
                        }

                        reader.Close();
                    }
                    command.Dispose();
                }
                    con.Close();
                con.Dispose();
            }
            //}
            //catch (Exception ex)
            //{
            //    EventLog m_EventLog = new EventLog("");
            //    m_EventLog.Source = "FPIKSErrors";
            //    m_EventLog.WriteEntry("Ошибка в работе сервиса::Startjob:" + ex.Message,
            //        EventLogEntryType.Warning);
            //}
            //finally
            //{
                lastTime = DateTime.Now;
                ics.FPClose();
                ics = null;
                //if((con!=null)&&(con.State==ConnectionState.Open))
                //    con.Close();
                //con.Dispose();
                //con = null;
                ((Mutex)mu).ReleaseMutex();
               //         }
            //return info;
        }