Пример #1
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }

        else if (instance != this)
        {
            Destroy(gameObject);
        }

        Setting();

        DontDestroyOnLoad(gameObject);
    }
Пример #2
0
 void OnDestroy()
 {
     instance = null;
 }
Пример #3
0
        /// <summary>
        /// 结账
        /// </summary>
        private void PayEnd()
        {
            //禁用控件,除了返回键
            foreach (Control control in Controls)
            {
                control.Enabled = false;
            }
            btnReturn.Enabled = true;

            List <OrderItem> order     = new List <OrderItem>();
            BinaryFormatter  formatter = new BinaryFormatter();

            using (Stream input = File.OpenRead(GlobalParams.orderPath))
            {
                if (input.Length > 0)
                {
                    order = (List <OrderItem>)formatter.Deserialize(input);
                }
            }

            //得到销售数据模型 salesList
            List <Sales> salesList = GetSalesListModel(order);

            //测试
            //List<Sales> salesList = GetSalesList(order);
            new DataOperator().UpdateSalesData(salesList);

            #region 打印小票

            //小票模板传参
            Receipt rpt = new Receipt()
            {
                xph         = GetXPH(),
                jh          = ConfigHelper.GetAppConfig("JH").Substring(1, 4),
                syybh       = staff.Staff_no,
                order       = order.Where(o => o.isValid == true).ToList(),
                goodsCount  = sell.GoodsCount,
                moneyTotal  = sell.MoneyTotal,
                yh          = (sell.YH + sell.DZ),//sell.YH,
                zjj         = Zjj,
                actualTotal = ZJ,
                cash        = Convert.ToDecimal(txtPayCash.Text == "" ? "0" : txtPayCash.Text),
                cardPay     = CardPayed,
                change      = Change,
                mcard       = sell.Membercard,
                mName       = mName,
                iniBalance  = mIniBalance,
                endBalance  = mEndBalance,
                printTime   = DateTime.Now
            };

            //增加小票到小票列表,序列化保存
            rList.Add(rpt);
            SerializeReceiptList(rList);

            //更新客显
            UpdateDisplay();

            bool flag = true;
#if DEBUG
            flag = false;
#endif
            //开钱箱,收现金
            if (rpt.cash > 0 && flag)
            {
                ICustomerDisplayer custDisplayer = ObjFactory.CreateCustomerDisplayer();
                if ("TECT10".Equals(custDisplayer.GetTypeID()))
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo("tec_drw.exe");
                    //startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                    Process.Start(startInfo);
                }
            }

            //打印小票
            Print prt = new Print();

            //如果是内部员工卡打印两张一样的小票
            if (sell.Mname != "" || sell.isCash)
            {
                prt.rec = rpt;
                prt.PrintReceipt(false);
                //打印到 txt
                prt.print(false);
            }


            prt.rec = rpt;
            prt.PrintReceipt(false);
            //打印到 txt
            prt.print(false);
            #endregion

            //收银完毕,删除购物单临时文件
            File.Delete(GlobalParams.orderPath);

            //小票号递增,记录格式
            GlobalParams.xph++;
            ConfigHelper.UpdateAppConfig("XPH", DateTime.Now.ToString("yyyyMMdd") + "#" + GlobalParams.xph);

            //前后台交互
            DataUpload.Upload(string.Format("小票号:{0}", GlobalParams.xph - 1));

            #region 导出单次销售明细表数据到 DBF 文件 (废)

            ////服务端是否存在 control.tab
            ////没有,就上传 pos.tab(可能碰到断网),表示前台开始控制
            ////有,意味着 DBF 文件正在被服务端占用,需要延迟上传
            //if (!File.Exists(GlobalParams.ControlTabPath))
            //{
            //    try
            //    {
            //        File.Copy(GlobalParams.PosTabLocalPath, GlobalParams.PosTabServerPath, true);
            //    }
            //    catch (Exception ex)
            //    {
            //        //断网情况会失败
            //        Log.WriteErrorLog(ex.Message, ex.Source, "向服务端放 pos.tab ");
            //    }

            //    //服务端是否存在 DBF 文件:存在意味着服务端还没有读取,需要向其中追加
            //    if (File.Exists(GlobalParams.xsxbServerPath))
            //    {
            //        try
            //        {
            //            //先拷贝到本地
            //            File.Copy(GlobalParams.xsxbServerPath, GlobalParams.xsxbPath, true);

            //            //读取 DBF 文件数据到单次销售明细表(追加)
            //            new DataOperator().DBFtoDB(GlobalParams.xsxbPath, "sales_time");
            //            new SalesBLL().DeleteSalesTime999();
            //        }
            //        catch (Exception ex)
            //        {
            //            Log.WriteErrorLog(ex.Message, ex.Source, "从服务端拷贝 xsxb.dbf 文件 ");
            //        }
            //    }
            //}

            ////备份路径是否存在 DBF 文件:存在意味着上次上传失败或延迟上传
            //if (File.Exists(GlobalParams.xsxbBackupsPath))
            //{
            //    //如果服务端存在DBF文件,复制到本地后,判断和备份文件是否一致
            //    //不一致才追加备份文件
            //    //先拷贝到本地
            //    File.Copy(GlobalParams.xsxbServerPath, GlobalParams.xsxbPath, true);

            //    if (!DataOperator.CompareFile(GlobalParams.xsxbBackupsPath, GlobalParams.xsxbPath))
            //    {
            //        //读取备份 DBF 文件数据到单次销售明细表(追加)
            //        new DataOperator().DBFtoDB(GlobalParams.xsxbBackupsPath, "sales_time");
            //        new SalesBLL().DeleteSalesTime999();

            //        //删除备份 DBF 文件
            //        File.Delete(GlobalParams.xsxbBackupsPath);
            //    }
            //}

            ////复制原始文件到单次销售明细 dbf 文件本地保存路径(覆盖)
            ////dbf文件无法真正删除老数据,每次上传前先使用比较小的原始文件
            //File.Copy(GlobalParams.xsxbIniPath, GlobalParams.xsxbPath, true);

            ////导出单次销售明细数据到本地 DBF 文件
            ////new DataOperator().SalesTimetoDBF();

            ////服务端是否有pos.tab:有意味着是正常上传,没有意味着要延迟到下次上传(可能断网了)
            //if (File.Exists(GlobalParams.PosTabServerPath))
            //{
            //    //上传本地 DBF 文件到服务端
            //    if (File.Exists(GlobalParams.xsxbPath))
            //    {
            //        try
            //        {
            //            File.Copy(GlobalParams.xsxbPath, GlobalParams.xsxbServerPath, true);
            //        }
            //        catch (Exception ex)
            //        {
            //            Log.WriteErrorLog(ex.Message, ex.Source, "上传本地 DBF 文件到服务端");
            //        }
            //    }

            //    //判断本地和服务端的文件是否一致,不一致说明上传失败,保存本地 DBF 文件到备份路径
            //    //有一种可能要排除:刚才上传成功了,但是突然断网了,现在再去对比,由于服务器的文件访问不了,也是不一致
            //    //此时会备份文件,断网了也删不掉服务器上的文件
            //    //到下次读取备份文件时,要先对比下是否和服务器上的文件是否一致,一致的话就不用追加到单次明细里了
            //    if (!(File.Exists(GlobalParams.xsxbServerPath)
            //        && DataOperator.CompareFile(GlobalParams.xsxbPath, GlobalParams.xsxbServerPath)))
            //    {
            //        File.Copy(GlobalParams.xsxbPath, GlobalParams.xsxbBackupsPath);
            //        Log.WriteNormalLog("","服务端与本地文件对比失败,复制到备份路径","");

            //        //服务端如果存在dbf文件,因为此时是上传失败的,所以它是老文件
            //        //老文件的数据已经添加到本地的备份文件中,所以要删除掉老文件防止重复数据
            //        if (File.Exists(GlobalParams.xsxbServerPath))
            //        {
            //            try
            //            {
            //                File.Delete(GlobalParams.xsxbServerPath);
            //                Log.WriteNormalLog("", "删除服务端老的单次销售明细数据", "");
            //            }
            //            catch (Exception ex)
            //            {
            //                Log.WriteErrorLog(ex.Message, ex.Source, "删除服务端老的单次销售明细数据");
            //            }
            //        }
            //    }

            //    //删除服务端 pos.tab
            //    try
            //    {
            //        File.Delete(GlobalParams.PosTabServerPath);
            //    }
            //    catch (Exception ex)
            //    {
            //        Log.WriteErrorLog(ex.Message, ex.Source, "上传后删除服务端的 pos.tab");
            //    }
            //}
            //else
            //{
            //    File.Copy(GlobalParams.xsxbPath, GlobalParams.xsxbBackupsPath);
            //    Log.WriteNormalLog("","延迟上传单次销售明细数据,复制到备份路径","");
            //}

            ////删掉本地的DBF文件
            //File.Delete(GlobalParams.xsxbPath);

            #endregion

            //更新商品变化主档
            DataOperator.UpdateSpit();

            //找零时,暂停3秒
            if (Change > 0)
            {
                Thread.Sleep(3000);
            }
            sell.isCash = false;
            sell.Show();
            this.Dispose();
        }
Пример #4
0
    /// <summary>Updates the currently loaded scene objects</summary>
    public void ParseScene()
    {
        // Clear out all previously loaded objects.
        loadedCheckpoints.Clear();
#if DEBUG
        debugObjects.Clear();
#endif

        // Handle the display of this world logic gameobject.
        HandleChildDebugObjects(gameObject);

        /*
         * Parse all of the checkpoints currently loaded in the scene.
         */

        // Declare a dictionary to store the parsed checkpoints.
        Dictionary <int, GameObject> checkpoints = new Dictionary <int, GameObject>();

        // Cycle through all objects tagged as checkpoints.
        foreach (GameObject checkpoint in GameObject.FindGameObjectsWithTag("Checkpoint"))
        {
            // Get the checkpoint script off of this object.
            Checkpoint script = checkpoint.GetComponent <Checkpoint>();

            // Does this script not exist?
            if (script == null)
            {
#if DEBUG
                // Print a warning out to the console.
                Debug.LogWarning("\"" + checkpoint.name + "\" is tagged as checkpoint but contains no checkpoint script.");
#endif
            }
            else
            {
                // Does this checkpoint have the same ID as another?
                if (checkpoints.ContainsKey(script.pointNumber))
                {
#if DEBUG
                    // Print a warning out to the console.
                    Debug.LogWarning("Gameobject \"" + checkpoint + "\" was denied a checkpoint because ID#" +
                                     script.pointNumber + " already belongs to \"" + checkpoints[script.pointNumber].name + "\"." +
                                     " Considering deleting one of the checkpoints or changing an identity.");
#endif
                }
                else
                {
                    // Add this checkpoint to the dictionary.
                    checkpoints.Add(script.pointNumber, checkpoint);
                }
            }
        }
        // All checkpoints parsed.

        // Is there no checkpoint for the level origin?
        if (!checkpoints.ContainsKey(0))
        {
#if DEBUG
            Debug.LogWarning("There is no checkpoint in the scene with the ID#0. Please create this checkpoint." +
                             " ID#0 has been created by default at the scene origin.");
#endif
            // Create the level origin checkpoint at the scene origin.
            GameObject originCP = Instantiate(checkpointPrefab, Vector3.zero, Quaternion.identity);
            checkpoints.Add(0, originCP);
        }

        // Transfer the loaded checkpoints into the accessible dictionary.
        foreach (KeyValuePair <int, GameObject> checkpoint in checkpoints)
        {
            loadedCheckpoints.Add(checkpoint.Key, checkpoint.Value.GetComponent <Checkpoint>());

            // Based on the build, handle the visual debug children.
            HandleChildDebugObjects(checkpoint.Value);
        }

        /*
         * Parse all of the factories currently loaded in the scene.
         */

        // Declare a dictionary to store the parsed factories.
        Dictionary <int, GameObject> factories = new Dictionary <int, GameObject>();

        // Cycle through all objects tagged as checkpoints.
        foreach (GameObject factory in GameObject.FindGameObjectsWithTag("Factory"))
        {
            // Get the factory script off of this object.
            ObjFactory script = factory.GetComponent <ObjFactory>();

            // Does this script not exist?
            if (script == null)
            {
#if DEBUG
                // Print a warning out to the console.
                Debug.LogWarning("\"" + factory.name + "\" is tagged as factory but contains no factory script.");
#endif
            }
            else
            {
                // Does this checkpoint have the same ID as another?
                if (factories.ContainsKey(script.pointNumber))
                {
#if DEBUG
                    // Print a warning out to the console.
                    Debug.LogWarning("Gameobject \"" + factory + "\" was denied a factory ID because ID#" +
                                     script.pointNumber + " already belongs to \"" + checkpoints[script.pointNumber].name + "\"." +
                                     " Considering deleting one of the factories or changing an identity.");
#endif
                }
                else
                {
                    // Add this checkpoint to the dictionary.
                    factories.Add(script.pointNumber, factory);
                }
            }
        }
        // All factories parsed.

        // Transfer the loaded factories into the accessible dictionary.
        foreach (KeyValuePair <int, GameObject> factory in factories)
        {
            loadedFactories.Add(factory.Key, factory.Value.GetComponent <ObjFactory>());

            // Based on the build, handle the visual debug children.
            HandleChildDebugObjects(factory.Value);
        }
    }