private void ReinitPosIfNotCurrentDobOrDifferentFranchise(bool isUpdated, string fileCode, string dataFolder,
                                                                  dynamic dataFolderFranchise, string tmpFolder)
        {
            if (isUpdated == false || !File.Exists(fileCode))
            {
                //Kill Iber process if exists
                ProcessExt.ForceKillProcess(SettingsData.AlohaIber.Replace(SettingsData.Constants.EXTENSION_EXE, String.Empty));

                //Delete DATA folders
                DirExt.ForceDeleteFolder(dataFolder);
                //Copy directories of franchise
                DirExt.ForceCopyFolder(Path.Combine(SettingsData.AlohaPath, dataFolderFranchise.ToString()),
                                       dataFolder);
                try
                {
                    DirExt.ForceToCreateFile(fileCode);
                }
                catch (Exception ex)
                {
                    SharedLogger.LogErrorToFile(ex, fileCode);
                }
                //WaitForTopMostToDisable(process);

                ChangeAlohaIniDate(dataFolder);
                DeleteTransLog(dataFolder);
                DeleteTmpFiles(tmpFolder);
            }
        }
        private bool InjectPosData(PropagateOrderModel propagateOrder, int termId, int checkId)
        {
            try
            {
                LasaFOHLib67.IberFuncs funcs = new LasaFOHLib67.IberFuncsClass();
                var dicParents         = new Dictionary <long, int>();
                var bLastItemIsEndItem = true;
                var hasPromo           = propagateOrder.PosCheck.Promos != null && propagateOrder.PosCheck.Promos.Count > 0;

                foreach (var itemModel in propagateOrder.PosCheck.LstItems)
                {
                    if (hasPromo && propagateOrder.PosCheck.Promos.ContainsKey(itemModel.ItemId))
                    {
                        continue;
                    }

                    bLastItemIsEndItem = false;
                    int entryId;
                    if (itemModel.ParentId == null)
                    {
                        if (dicParents.Count != 0)
                        {
                            funcs.EndItem(termId);
                            bLastItemIsEndItem = true;
                        }

                        entryId = funcs.BeginItem(termId, checkId, (int)itemModel.ItemId, "", -999999999);
                        dicParents.Add(itemModel.CheckItemId, entryId);
                        continue;
                    }

                    if (!dicParents.TryGetValue(itemModel.ParentId.Value, out entryId))
                    {
                        continue;
                    }

                    entryId = funcs.ModItem(termId, entryId, (int)itemModel.ItemId, "", -999999999, itemModel.ModCode);
                    dicParents.Add(itemModel.CheckItemId, entryId);
                }

                if (!bLastItemIsEndItem)
                {
                    funcs.EndItem(termId);
                }

                funcs.RefreshCheckDisplay();
                return(true);
            }
            catch (Exception ex)
            {
                var sMsg = ex.AlohaError();
                SharedLogger.LogErrorToFile(ex, sMsg);
                MessageBox.Show("Item Error: " + sMsg + " | " + ex.Message);
                return(false);
            }
        }
        private bool StartInjectPosData(PropagateOrderModel propagateOrder)
        {
            LasaFOHLib67.IberFuncs funcs;
            int termId, checkId;

            try
            {
                LasaFOHLib67.IberDepot   depot      = new LasaFOHLib67.IberDepotClass();
                LasaFOHLib67.IIberObject localState = depot.GetEnum(720).First();
                termId = localState.GetLongVal("TERMINAL_NUM");
                funcs  = new LasaFOHLib67.IberFuncsClass();
            }
            catch (Exception ex)
            {
                var sMsg = ex.AlohaError();
                SharedLogger.LogErrorToFile(ex, sMsg);
                MessageBox.Show("Func error: " + sMsg + " | " + ex.Message);
                return(false);
            }


            try
            {
                funcs.LogOut(termId);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            try
            {
                funcs.LogIn(termId, SettingsData.Client.UserAlohaPosId, String.Empty, String.Empty);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            try
            {
                funcs.ClockIn(termId, SettingsData.Client.JobAlohaPosId);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            bool isTableService;

            try
            {
                funcs.RefreshCheckDisplay();
                isTableService = funcs.IsTableService();
            }
            catch (Exception ex)
            {
                var sMsg = ex.AlohaError();
                SharedLogger.LogErrorToFile(ex, sMsg);
                //MessageBox.Show("Refresh Error: " + sMsg + " | " + ex.Message);
                return(false);
            }

            try
            {
                var tableId = funcs.AddTable(termId, (isTableService ? 0 : 1), (isTableService ? SettingsData.Client.TablePosId : 0), SettingsData.Client.TablePosName, 1);
                checkId = funcs.AddCheck(termId, tableId);
                funcs.RefreshCheckDisplay();
            }
            catch (Exception ex)
            {
                var sMsg = ex.AlohaError();
                SharedLogger.LogErrorToFile(ex, sMsg);
                MessageBox.Show("Add Table Error: " + sMsg + " | " + ex.Message);
                return(false);
            }
            return(InjectPosData(propagateOrder, termId, checkId));
        }