Esempio n. 1
0
 public BL(bool pIsUseOldDB = false)
 {
     db = new WDB_SQLite(default(DateTime), null, pIsUseOldDB);
     db.BildWorkplace();
     ds  = new DataSync(this);
     sBL = this;
 }
Esempio n. 2
0
        public Receipt GetReceiptByFiscalNumber(int IdWorkplace, string pFiscalNumber, DateTime pStartDate = default(DateTime), DateTime pFinishDate = default(DateTime))
        {
            if (pStartDate == default(DateTime))
            {
                pStartDate = DateTime.Now.Date.AddDays(-14);
            }
            if (pFinishDate == default(DateTime))
            {
                pFinishDate = DateTime.Now;
            }

            var Ldc = pStartDate.Date;

            while (Ldc <= pFinishDate.Date)
            {
                var ldb = new WDB_SQLite(Ldc);
                var l   = ldb.GetReceiptByFiscalNumber(IdWorkplace, pFiscalNumber, pStartDate, pFinishDate);
                if (l != null && l.Count() >= 1)
                {
                    return(l.First());
                }
                Ldc = Ldc.AddDays(1);
            }
            return(null);
        }
Esempio n. 3
0
        public void LoadWeightKasa2(DateTime parDT, int TypeSource = 0)
        {
            try
            {
                var    ldb       = new WDB_SQLite(parDT);
                string SQLUpdate = @"insert into  DW.dbo.Weight_Receipt  (Type_Source,code_wares, weight,Date,ID_WORKPLACE, CODE_RECEIPT,QUANTITY) values (@TypeSource, @CodeWares,@Weight,@Date,@IdWorkplace,@CodeReceipt,@Quantity)";
                var    dbMs      = new MSSQL();

                var SqlSelect = TypeSource == 0 ? "select 0 as TypeSource,CODE_WARES as CodeWares,FIX_WEIGHT as WEIGHT,DATE_CREATE as date, ID_WORKPLACE as IdWorkplace, CODE_RECEIPT as CodeReceipt, QUANTITY as Quantity  from WARES_RECEIPT where FIX_WEIGHT>0" :
                                @"select 1  as TypeSource,re.CODE_WARES as CodeWares,re.PRODUCT_CONFIRMED_WEIGHT/1000.0 as WEIGHT,wr.DATE_CREATE as date, re.ID_WORKPLACE as IdWorkplace, re.CODE_RECEIPT as CodeReceipt, wr.QUANTITY as Quantity,wr.FIX_WEIGHT
from RECEIPT_EVENT RE 
join WARES_RECEIPT wr on re.ID_WORKPLACE=wr.ID_WORKPLACE and wr.CODE_RECEIPT=re.CODE_RECEIPT and re.code_wares=wr.code_wares
where RE.EVENT_TYPE=1"
                ;
                Console.WriteLine("Start LoadWeightKasa2");
                var r = ldb.db.Execute <WeightReceipt>(SqlSelect);
                Console.WriteLine(parDT.ToString() + " " + r.Count().ToString());
                dbMs.BulkExecuteNonQuery <WeightReceipt>(SQLUpdate, r);
                Console.WriteLine("Finish LoadWeightKasa2");
            }
            catch (Exception ex)
            {
                Global.OnSyncInfoCollected?.Invoke(new SyncInformation {
                    Exception = ex, Status = eSyncStatus.NoFatalError, StatusDescription = "LoadWeightKasa2=> " + ex.Message
                });
            }
        }
Esempio n. 4
0
        public void SendOldReceipt()
        {
            var Ldc   = db.GetConfig <DateTime>("LastDaySend");
            var today = DateTime.Now.Date;

            if (Ldc == default(DateTime))
            {
                Ldc = today.AddDays(-10);
            }

            while (Ldc < today)
            {
                var ldb = new WDB_SQLite(Ldc);
                var t   = SendAllReceipt(ldb);
                t.Wait();
                var res = ldb.GetIdReceiptbyState(eStateReceipt.Print);
                if (res.Count() == 0)
                {
                    db.SetConfig <DateTime>("LastDaySend", Ldc);
                }
                else
                {
                    Global.OnSyncInfoCollected?.Invoke(new SyncInformation {
                        Status = eSyncStatus.NoFatalError, StatusDescription = $"SendOldReceipt => ErrorSend Date:{Ldc} Not Send => {res.Count()}"
                    });
                    return;
                }
                Ldc = Ldc.AddDays(1);
            }
            //Перекидаємо лічильник на сьогодня.
            db.SetConfig <DateTime>("LastDaySend", Ldc);
        }
Esempio n. 5
0
        public bool SendReceiptTo1C(IdReceipt parIdReceipt)
        {
            var ldb = new WDB_SQLite(parIdReceipt.DTPeriod);
            var r   = ldb.ViewReceipt(parIdReceipt, true);


#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            SendReceiptTo1CAsync(r, ldb);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            return(true);
        }
Esempio n. 6
0
        public Receipt GetReceiptHead(IdReceipt idReceipt, bool parWithDetail = false)
        {
            DateTime Ldc = idReceipt.DTPeriod;

            if (Ldc == DateTime.Now.Date)
            {
                return(db.ViewReceipt(idReceipt, parWithDetail));
            }

            var ldb = new WDB_SQLite(Ldc);

            return(ldb.ViewReceipt(idReceipt, parWithDetail));
        }
Esempio n. 7
0
        public async Task <bool> SendReceiptTo1CAsync(Receipt parReceipt, WDB_SQLite parDB)
        {
            try
            {
                var r = new Receipt1C(parReceipt);

                var body = soapTo1C.GenBody("JSONCheck", new Parameters[] { new Parameters("JSONSting", r.GetBase64()) });

                var res = await soapTo1C.RequestAsync(Global.Server1C, body, 240000, "application/json");

                /*
                 *               HttpClient client = new HttpClient();
                 *
                 *               // Add a new Request Message
                 *               HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, Global.Server1C);
                 *               //requestMessage.Headers.Add("Accept", "application/vnd.github.v3+json");
                 *               // Add our custom headers
                 *               requestMessage.Content = new StringContent(//r.GetSOAP()
                 *                   body, Encoding.UTF8, "application/json");
                 *               var response = await client.SendAsync(requestMessage);
                 *
                 *               if (response.IsSuccessStatusCode)
                 *               {
                 *                   var res = await response.Content.ReadAsStringAsync();
                 *                   parReceipt.StateReceipt = eStateReceipt.Send;
                 *                   db.SetStateReceipt(parReceipt);//Змінюєм стан чека на відправлено.
                 *                   return true;
                 *               }
                 *               else
                 *               {
                 *                   return false;
                 *               }
                 */

                if (!string.IsNullOrEmpty(res) && res.Equals("0"))
                {
                    parReceipt.StateReceipt = eStateReceipt.Send;
                    parDB.SetStateReceipt(parReceipt);//Змінюєм стан чека на відправлено.
                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Global.OnSyncInfoCollected?.Invoke(new SyncInformation {
                    TerminalId = Global.GetTerminalIdByIdWorkplace(parReceipt.IdWorkplace), Exception = ex, Status = eSyncStatus.NoFatalError, StatusDescription = "SendReceiptTo1CAsync=>" + parReceipt.ReceiptId.ToString() + " " + ex.Message + '\n' + new System.Diagnostics.StackTrace().ToString()
                });
                return(false);
            }
        }
Esempio n. 8
0
        public async Task <bool> SendAllReceipt(WDB_SQLite parDB = null)
        {
            var varDB       = (parDB == null ? db : parDB);
            var varReceipts = varDB.GetIdReceiptbyState(eStateReceipt.Print);

            foreach (var el in varReceipts)
            {
                await SendReceiptTo1CAsync(varDB.ViewReceipt(el, true), varDB);
            }
            if (parDB == null)
            {
                SendOldReceipt();
            }
            Global.OnStatusChanged?.Invoke(db.GetStatus());
            return(true);
        }
Esempio n. 9
0
        public IEnumerable <Receipt> GetReceipts(DateTime parStartDate, DateTime parFinishDate, int IdWorkPlace)
        {
            var res = db.GetReceipts(parStartDate.Date, parFinishDate.Date.AddDays(1), IdWorkPlace).ToList();

            if (parStartDate.Date != DateTime.Now.Date || parFinishDate.Date != DateTime.Now.Date)
            {
                var Ldc = parStartDate.Date;
                while (Ldc <= parFinishDate.Date)
                {
                    using (var ldb = new WDB_SQLite(Ldc))
                    {
                        var l = ldb.GetReceipts(Ldc.Date, Ldc.Date.AddDays(1), IdWorkPlace);
                        res.AddRange(l);
                        Ldc = Ldc.AddDays(1);
                    }
                }
            }
            return(res);
        }
Esempio n. 10
0
        public bool UpdateReceiptFiscalNumber(IdReceipt receiptId, string pFiscalNumber, decimal pSumFiscal = 0, DateTime pDateFiscal = default(DateTime))
        {
            if (pDateFiscal == default(DateTime))
            {
                pDateFiscal = DateTime.Now;
            }
            var receipt = new Receipt(receiptId);

            receipt.NumberReceipt = pFiscalNumber;
            receipt.StateReceipt  = eStateReceipt.Print;
            receipt.UserCreate    = GetUserIdbyWorkPlace(receiptId.IdWorkplace);
            receipt.SumFiscal     = pSumFiscal;
            receipt.DateReceipt   = pDateFiscal;

            DateTime Ldc = receiptId.DTPeriod;

            WDB_SQLite ldb = (Ldc == DateTime.Now.Date ? db : new WDB_SQLite(Ldc));

            var Res = ldb.CloseReceipt(receipt);

            curRecipt = receipt;
            return(Res);
        }
Esempio n. 11
0
        public async Task SendRWDeleteAsync()
        {
            var Ldc   = db.GetConfig <DateTime>("LastDaySendDeleted");
            var today = DateTime.Now.Date;

            try
            {
                if (Ldc == default(DateTime))
                {
                    Ldc = today.AddDays(-10);
                }
                Ldc = Ldc.AddDays(1);
                while (Ldc < today)
                {
                    var ldb = new WDB_SQLite(Ldc);
                    var t   = ldb.GetReceiptWaresDeleted();
                    var res = await Send1CReceiptWaresDeletedAsync(t);

                    if (res)
                    {
                        db.SetConfig <DateTime>("LastDaySendDeleted", Ldc);
                    }
                    else
                    {
                        break;
                    }

                    Ldc = Ldc.AddDays(1);
                }
            }
            catch (Exception ex)
            {
                Global.OnSyncInfoCollected?.Invoke(new SyncInformation {
                    Exception = ex, Status = eSyncStatus.NoFatalError, StatusDescription = "SendRWDeleteAsync=>" + Ldc.ToString() + " " + ex.Message + '\n' + new System.Diagnostics.StackTrace().ToString()
                });
            }
        }