Beispiel #1
0
 /*
  * static private void PrinterStatusVerification()
  * {
  *  try
  *  {
  *      if (!ToShtrih.PrinterColorIsGray())
  *      {
  *          //Андрюша раздолбай
  *          //Надо ему об этом сообщить
  *          EventSenderClass.SendAsincEvent(PDiscountCard.StopListService.RemoteEventType.AndrFoool, "");
  *      }
  *      else
  *      {
  *          //  EventSenderClass.SendAsincEvent(PDiscountCard.s2010StopList.RemoteEventType.CheckClosed, "Good");
  *      }
  *  }
  *  catch
  *  { }
  * }
  */
 /*
  * static internal void CheckIsClosed(int TableId)
  * {
  *  try
  *  {
  *      if (iniFile.Read("Options", "CloseCheck") == "TRUE")
  *      {
  *          Utils.ToLog("CheckIsClosed TableId=" + TableId.ToString(), 6);
  *          Check Ch = ReadCheckFromTmp();
  *          if (Ch == null)
  *          {
  *              Utils.ToLog("Ch == null", 6);
  *              return;
  *          }
  *          if (Ch.TableId == TableId)
  *          {
  *              Utils.ToLog("Ch.TableId == TableId", 6);
  *              File.Delete(ChecksPath + @"\ch.xml");
  *              Utils.ToLog("Файл удален", 6);
  *          }
  *      }
  *  }
  *  catch (Exception e)
  *  {
  *      Utils.ToLog("Error CheckIsClosed " + e.Message, 6);
  *
  *  }
  * }
  */
 static internal void WriteAllChecks(AllChecks AllCh)
 {
     try
     {
         if (!Directory.Exists(ChecksPath))
         {
             Directory.CreateDirectory(ChecksPath);
         }
         XmlWriter XWriter = new XmlTextWriter(ChecksPath + @"\hamster.xml", System.Text.Encoding.UTF8);
         //CardMooverInfoSerializer.CardMooverInfoSerializer.CardMooverInfoSerializer.CardMooverInfoSerializer.XmlSerializer XS = new XmlSerializer(typeof(CardMooverInfo));
         XmlSerializer XS = new XmlSerializer(typeof(AllChecks));
         //FiskInfo CDI = new FiskInfo();
         //CDI.FiskNum = CurentNum;И
         XS.Serialize(XWriter, AllCh);
         XWriter.Close();
     }
     catch
     {
     }
 }
Beispiel #2
0
        static void CloseCheckQuere()
        {
            try
            {
                DirectoryInfo Di = new DirectoryInfo(ChecksPath);
                if (!Di.Exists)
                {
                    Di.Create();
                }

                while (!mExitCloseCheckThread)
                {
                    try
                    {
                        //  CreateCloseCheckFileEventWaitHandle.WaitOne();
                        try
                        {
                            foreach (FileInfo fi in Di.GetFiles("*.0"))
                            {
                                try
                                {
                                    Utils.ToCardLog("Очередь на фискальник. Файл " + fi.Name);
                                    String State1FileName = fi.FullName.Substring(0, fi.FullName.Length - 1) + "1";
                                    String State2FileName = fi.FullName.Substring(0, fi.FullName.Length - 1) + "2";
                                    Check  Ch             = ReadCheckFromTmp(fi.FullName);

                                    if (iniFile.FRSEnabled)
                                    {
                                        continue;

                                        /*
                                         * try
                                         * {
                                         *  Utils.ToCardLog("FRSEnabled");
                                         *  if (Ch.GuidId == null) { Ch.GuidId = Guid.NewGuid(); }
                                         *
                                         *  String State5FileName = fi.FullName.Substring(0, fi.FullName.Length - 2) + Ch.GuidId.ToString() + ".5"; //FRS
                                         *  Utils.ToCardLog("State5FileName: " + State5FileName);
                                         *  if (File.Exists(State5FileName))
                                         *  {
                                         *      Utils.ToCardLog("Exist. Delete: ");
                                         *      File.Delete(State5FileName);
                                         *  }
                                         *  fi.CopyTo(State5FileName);
                                         *
                                         *  try
                                         *  {
                                         *      Utils.ToCardLog("fi.MoveTo(State2FileName): " + State2FileName);
                                         *      fi.MoveTo(State2FileName);
                                         *  }
                                         *  catch (Exception e)
                                         *  {
                                         *      Utils.ToCardLog("Error fi.MoveTo(State2FileName):  " + e.Message);
                                         *  }
                                         *  continue;
                                         * }
                                         * catch (Exception e)
                                         * {
                                         *  Utils.ToCardLog("Error FRSEnabled " + e.Message);
                                         * }
                                         * try
                                         * {
                                         *  Utils.ToCardLog("Переименовываю в  " + State2FileName);
                                         *  fi.MoveTo(State2FileName); //Нужен грамотный lock
                                         * }
                                         * catch (Exception ee)
                                         * {
                                         *  Utils.ToCardLog("Error Переименовываю в  " + State2FileName + " " + ee.Message);
                                         * }
                                         */
                                    }
                                    else
                                    {
                                        if (File.Exists(State1FileName))
                                        {
                                            Utils.ToCardLog("Существует " + State1FileName + " переношу в папку багов");
                                            if (!Directory.Exists(BugChecksPath))
                                            {
                                                Directory.CreateDirectory(BugChecksPath);
                                            }
                                            fi.MoveTo(BugChecksPath + fi.Name);
                                            continue;
                                        }

                                        Utils.ToCardLog("Переименовываю в  " + State1FileName);
                                        fi.MoveTo(State1FileName); //Нужен грамотный lock
                                    }

                                    if (Ch != null)
                                    {
                                        if (myAllChecks.Checks.Where(a => a.CheckNum == Ch.CheckNum && a.Summ == Ch.Summ && a.SystemDateOfOpen == Ch.SystemDateOfOpen).Count() > 0)
                                        {
                                            Utils.ToCardLog("Чек присутствует в myAllChecks " + Ch.CheckNum);
                                            fi.Delete();
                                            continue;
                                        }


                                        if (Shtrih2.QuereContainsChk(Ch))
                                        {
                                            Utils.ToCardLog("Чек уже присутствует в очереди закрытия " + Ch.CheckNum);
                                            continue;
                                        }


                                        if ((Ch.HasFiskalPayment() && Ch.Summ != 0) && (!iniFile.NOLocalFR) && (!iniFile.FRSEnabled))
                                        {
                                            Utils.ToCardLog("Отправляю в фискальную очередь  ");
                                            if (!iniFile.FiskalDriverNonShtrih)
                                            {
                                                Ch.FiskalFileName = State1FileName;
                                                ToShtrih.CloseCheck2(Ch);
                                            }
                                            else
                                            {
                                                Utils.ToCardLog("iniFile.FiskalDriverNonShtrih");
                                                if (FiskalDrivers.FiskalDriver.CloseCheck(Utils.GetFiskalCheck(Ch)))
                                                {
                                                    fi.MoveTo(State2FileName);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Utils.ToCardLog("Нет фискальных платежей либо локального ФР");
                                            fi.MoveTo(State2FileName);
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Utils.ToCardLog("[Error] Очередь на фискальник. Файл " + fi.Name + " Err " + e.Message);
                                }
                            }
                        }
                        catch
                        { }
                        //  CreateCloseCheckFileEventWaitHandle.Set();

                        WriteCheck2FileEventWaitHandle.WaitOne();
                        try
                        {
                            foreach (FileInfo fi in Di.GetFiles("*.2"))
                            {
                                try
                                {
                                    Utils.ToCardLog("*.2 Find " + fi.FullName);
                                    String State3FileName = fi.FullName.Substring(0, fi.FullName.Length - 1) + "3";
                                    Check  Ch             = ReadCheckFromTmp(fi.FullName);
                                    if (File.Exists(Ch.FiskalFileName))
                                    {
                                        File.Delete(Ch.FiskalFileName);
                                    }

                                    if (Ch != null)
                                    {
                                        if (iniFile.SpoolEnabled)
                                        {
                                            //if (Ch.ConSolidateSpoolDishez.Count > 0)
                                            {
                                                Spool.SpoolCreator.AddToSpoolFile(Ch);
                                            }
                                        }
                                        if (iniFile.JMSEnable)
                                        {
                                            //if (Ch.ConSolidateSpoolDishez.Count > 0)
                                            {
                                                JMSSendQuereChecks.Add(Ch);
                                                //Thread th = new Thread(SendJms);
                                                //th.Start(Ch);
                                            }
                                        }

                                        if (iniFile.AlohaFlyExportEnabled)
                                        {
                                            AlohaFlyExport.AlohaFlyExportHelper exp = new AlohaFlyExport.AlohaFlyExportHelper();
                                            exp.SendOrderFlightAsync(Ch);
                                        }
                                    }
                                    if (iniFile.FRSEnabled)
                                    {
                                        String State6FileName = fi.FullName.Substring(0, fi.FullName.Length - 2) + Ch.GuidId.ToString() + ".6"; //FRS
                                        fi.MoveTo(State6FileName);
                                    }
                                    else
                                    {
                                        fi.MoveTo(State3FileName);
                                    }
                                }
                                catch (Exception e)
                                {
                                    Utils.ToCardLog("Error2  *.2 Find " + fi.FullName);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Utils.ToCardLog("Error *.2 Find " + e.Message);
                        }
                        WriteCheck2FileEventWaitHandle.Set();

                        foreach (FileInfo fi in Di.GetFiles("*.3"))
                        {
                            //if ()

                            if (!iniFile.HamsterDisabled)
                            {
                                Check Ch = ReadCheckFromTmp(fi.FullName);
                                try
                                {
                                    AllChecks myAllChecks2 = ReadAllChecks(ChecksPath + @"\hamster.xml");
                                    if ((myAllChecks2.Checks.Count == 0) && File.Exists(ChecksPath + @"\hamster.xml"))
                                    {
                                        File.Copy(ChecksPath + @"\hamster.xml", ChecksPath + @"\hamster" + Guid.NewGuid() + ".xml");
                                    }
                                    myAllChecks2.Checks.Add(Ch);
                                    WriteAllChecks(myAllChecks2);
                                    fi.Delete();
                                }
                                catch (Exception ee)
                                {
                                    Utils.ToCardLog("[Error] CloseCheckQuere state 3 " + ee.Message);
                                }
                                myAllChecks.AddChk(Ch);
                            }
                            else
                            {
                                fi.Delete();
                            }
                        }

                        foreach (FileInfo fi in Di.GetFiles("*.6"))
                        {
                            try
                            {
                                //Check Ch = ReadCheckFromTmp(fi.FullName);
                                Hamster.HamsterWorker.SendHamsterChk(fi.FullName);
                            }
                            catch (Exception ee)
                            {
                                Utils.ToCardLog("[Error] CloseCheckQuere state 6 " + ee.Message);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Utils.ToCardLog("[Error] CloseCheckQuere " + e.Message);
                    }
                    Thread.Sleep(200);
                }
            }
            catch (Exception ee)
            {
                Utils.ToCardLog("[Error] CloseCheckQuere2 " + ee.Message);
            }
        }