예제 #1
0
        /// <summary>
        /// Инкассация - изымаем купюры и монеты из кэшбокса, обнуляем счетчики
        /// </summary>
        public async void MakeIncassation()
        {
            try
            {
                CashCounterAccessFlag.Wait();
                WaterDeviceIncasso tmpincasso = new WaterDeviceIncasso
                {
                    CommandID           = 0,
                    ID                  = 0,
                    IncassoBABills      = SystemState.BABillsCount,
                    IncassoBASum        = SystemState.BASum,
                    IncassoCashboxCoins = SystemState.CBCount,
                    IncassoCashboxSum   = SystemState.CBSum,
                    IncassoDatetime     = 0,
                    IncassoDatetimeStr  = "",
                    WaterDeviceID       = GlobalVars.RegID
                };
                ClientRequest tmpreq             = RequestEncoder.EncodeRequestData(tmpincasso);
                Dictionary <string, string> data = new Dictionary <string, string>
                {
                    { "Request", tmpreq.Request },
                    { "Signature", tmpreq.Signature },
                    { "AData", tmpreq.AData },
                    { "BData", tmpreq.BData }
                };
                HttpFormUrlEncodedContent content = new HttpFormUrlEncodedContent(data);
                HttpClient          httpClient    = NewWebClient();
                Uri                 requestUri    = new Uri(GlobalVars.SERVER_ENDPOINT + GlobalVars.INCASSO_REPORT_PATH);
                HttpResponseMessage httpResponse  = new HttpResponseMessage();
                httpResponse = await httpClient.PostAsync(requestUri, content);

                httpResponse.EnsureSuccessStatusCode();
                string tmpres = await httpResponse.Content.ReadAsStringAsync();

                if (Convert.ToDouble(tmpres) == SystemState.BASum + SystemState.CBSum)
                {
                    byte[] ccdata          = new byte[24];
                    string wcfilename      = GlobalVars.HardWareID + ".005";
                    byte[] tmpcbccount     = BitConverter.GetBytes(0);
                    byte[] tmpcbcsum       = BitConverter.GetBytes(0.00);
                    byte[] tmpbabillscount = BitConverter.GetBytes(0);
                    byte[] tmpbasum        = BitConverter.GetBytes(0.00);
                    SystemState.IncassoSum   = 0;
                    SystemState.CBCount      = 0;
                    SystemState.CBSum        = 0;
                    SystemState.BABillsCount = 0;
                    SystemState.BASum        = 0;
                    byte[] updatedccdata = new byte[24];
                    Array.Copy(tmpcbccount, 0, updatedccdata, 0, 4);
                    Array.Copy(tmpcbcsum, 0, updatedccdata, 4, 8);
                    Array.Copy(tmpbabillscount, 0, updatedccdata, 12, 4);
                    Array.Copy(tmpbasum, 0, updatedccdata, 16, 8);
                    StorageFile wcfile = null;
                    wcfile = await ApplicationData.Current.LocalFolder.GetFileAsync(wcfilename);

                    using (StorageStreamTransaction transaction = await wcfile.OpenTransactedWriteAsync())
                    {
                        using (DataWriter dataWriter = new DataWriter(transaction.Stream))
                        {
                            dataWriter.WriteBytes(updatedccdata);
                            transaction.Stream.Size = await dataWriter.StoreAsync(); // reset stream size to override the file

                            await transaction.CommitAsync();
                        }
                    }
                }
            }
            catch
            {
            }
            CashCounterAccessFlag.Release();
        }