Example #1
0
        //LogOff User Before Delete
        void TreeView_RecordBeforeDelete(object sender, EventArgs e)
        {
            SYS_UserDetail userDetail = (_dataSourceRow as SYS_UserDetail);

            //If User deleted Force Logout in Sytem
            GlobalApp.WindowStartup.LogOutUser(false, userDetail);
        }
Example #2
0
        public DialogUserDetail(Window pSourceWindow, GenericTreeViewXPO pTreeView, DialogFlags pFlags, DialogMode pDialogMode, XPGuidObject pXPGuidObject)
            : base(pSourceWindow, pTreeView, pFlags, pDialogMode, pXPGuidObject)
        {
            this.Title = Utils.GetWindowTitle(Resx.window_title_edit_user);
            SetSizeRequest(500, 469);

            //Store References
            _userDetail   = (DataSourceRow as SYS_UserDetail);
            _isLoggedUser = (_userDetail == GlobalFramework.LoggedUser);

            //Store Current User Unchanged Profile
            _currentUserPermissionProfileGuid = (_userDetail.Profile != null && _dialogMode == DialogMode.Update)
                ? _userDetail.Profile.Oid
                : Guid.Empty;

            //Store Current User Unchanged PasswordReset
            _currentUserPasswordReset = _userDetail.PasswordReset;
            //Store Current User Unchanged Disabled
            _currentUserDisabled = _userDetail.Disabled;

            //Init UI
            InitUI();
            InitNotes();
            ShowAll();
        }
Example #3
0
        //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        //FinanceDocument

        //Used to trigger all Errors
        public static FIN_DocumentFinanceMaster PersistFinanceDocumentMinimal(Guid pDocumentFinanceType)
        {
            //Store current Logged Details
            SYS_UserDetail loggedUser = GlobalFramework.LoggedUser;
            POS_ConfigurationPlaceTerminal loggedTerminal = GlobalFramework.LoggedTerminal;

            //Reset Current Logged Details
            GlobalFramework.LoggedUser     = null;
            GlobalFramework.LoggedTerminal = null;
            FIN_DocumentFinanceMaster documentFinanceMaster = null;

            try
            {
                //Create Empty ArticleBag
                ArticleBag articleBag = new ArticleBag();
                //Create ProcessFinanceDocumentParameter
                ProcessFinanceDocumentParameter processFinanceDocumentParameter = new ProcessFinanceDocumentParameter(pDocumentFinanceType, articleBag);
                //Reset Defaults
                processFinanceDocumentParameter.Currency = Guid.Empty;
                documentFinanceMaster = ProcessFinanceDocument.PersistFinanceDocument(processFinanceDocumentParameter);
                Console.WriteLine(string.Format("documentFinanceMaster.DocumentNumber: [{0}]", documentFinanceMaster.DocumentNumber));
            }
            finally
            {
                //Restore Old Logged Details
                GlobalFramework.LoggedUser     = loggedUser;
                GlobalFramework.LoggedTerminal = loggedTerminal;
            }

            return(documentFinanceMaster);
        }
Example #4
0
 public void LogOutUser(bool pGotoStartupWindow, SYS_UserDetail pUserDetail)
 {
     if (
         GlobalFramework.SessionApp.LoggedUsers.ContainsKey(pUserDetail.Oid))
     {
         GlobalFramework.SessionApp.LoggedUsers.Remove(pUserDetail.Oid);
         GlobalFramework.SessionApp.Write();
         FrameworkUtils.Audit("USER_LOGOUT", string.Format(Resx.audit_message_user_logout, pUserDetail.Name));
         //Only Reset LoggedUser if equal to pUser
         if (GlobalFramework.LoggedUser.Equals(pUserDetail))
         {
             GlobalFramework.LoggedUser            = null;
             GlobalFramework.LoggedUserPermissions = null;
         }
     }
     //Update Table, In case user change Users in BackOffice
     GlobalApp.WindowStartup.TablePadUser.UpdateSql();
     //Required to Assign Details to Update Select User
     AssignUserDetail();
     //Show Startup Windows, or Not (Silent Mode)
     if (pGotoStartupWindow)
     {
         GlobalApp.WindowStartup.ShowAll();
     }
 }
Example #5
0
        //Start Application or Change User
        private void ProcessLogin(SYS_UserDetail pUserDetail)
        {
            GlobalFramework.LoggedUser            = pUserDetail;
            GlobalFramework.LoggedUserPermissions = FrameworkUtils.GetUserPermissions();
            FrameworkUtils.Audit("USER_LOGIN", string.Format(Resx.audit_message_user_login, pUserDetail.Name));

            //SessionApp Add LoggedUser
            if (!GlobalFramework.SessionApp.LoggedUsers.ContainsKey(GlobalFramework.LoggedUser.Oid))
            {
                GlobalFramework.SessionApp.LoggedUsers.Add(pUserDetail.Oid, FrameworkUtils.CurrentDateTimeAtomic());
            }
            else
            {
                GlobalFramework.SessionApp.LoggedUsers[GlobalFramework.LoggedUser.Oid] = FrameworkUtils.CurrentDateTimeAtomic();
            }
            GlobalFramework.SessionApp.Write();

            //Returns to default mode
            _mode = NumberPadPinMode.Password;
            UpdateStatusLabels();

            //Process Notifications After Login/Create First Time PosWindow
            //Disabled SystemNotification and ShowNotifications. Moved to Startup Window
            //FrameworkUtils.SystemNotification();
            //Utils.ShowNotifications(_sourceWindow, pUserDetail.Oid);
            Utils.ShowFrontOffice(_sourceWindow);
        }
Example #6
0
        public PosSendMessageDialog(Window pSourceWindow, DialogFlags pDialogFlags, string pWindowIcon)
        //public PosInputTextDialog(Window pSourceWindow, DialogFlags pDialogFlags, string pWindowTitle, string pEntryLabel, string pDefaultValue, string pRule, bool pRequired)
            : base(pSourceWindow, pDialogFlags, Resx.window_title_dialog_send_message, pWindowIcon, "Label", "Default", SettingsApp.RegexAlfaNumericExtended, true)
        {
            this.HeightRequest = 320;

            //UserDetail
            CriteriaOperator criteriaOperatorUser = CriteriaOperator.Parse("(Disabled IS NULL OR Disabled  <> 1)");

            _entryBoxSelectUser = new XPOEntryBoxSelectRecordValidation <SYS_UserDetail, TreeViewUser>(_sourceWindow, Resx.global_user, "Designation", "Oid", _valueUser, criteriaOperatorUser, SettingsApp.RegexGuid, false);
            _entryBoxSelectUser.EntryValidation.IsEditable = false;
            //Public Reference
            _valueUser = _entryBoxSelectUser.Value;

            //Terminal
            CriteriaOperator criteriaOperatorTerminal = CriteriaOperator.Parse("(Disabled IS NULL OR Disabled  <> 1)");

            _entryBoxSelectTerminal = new XPOEntryBoxSelectRecordValidation <POS_ConfigurationPlaceTerminal, TreeViewConfigurationPlaceTerminal>(_sourceWindow, Resx.global_user, "Designation", "Oid", _valueTerminal, criteriaOperatorTerminal, SettingsApp.RegexGuid, false);
            _entryBoxSelectTerminal.EntryValidation.IsEditable = false;
            //Public Reference
            _valueTerminal = _entryBoxSelectTerminal.Value;

            _vbox.PackStart(_entryBoxSelectTerminal, true, true, 0);
            _vbox.PackStart(_entryBoxSelectUser, true, true, 0);
            _vbox.ShowAll();

            //dialog.VBoxContent.PackStart(textViewTouch, true, true, 0);
            //dialog.VBoxContent.ShowAll();

            /*
             * //Init Local Vars
             * String windowTitle = Resx.window_title_dialog_send_message;
             * Size windowSize = new Size(600, 500);
             * String fileDefaultWindowIcon = FrameworkUtils.OSSlash(GlobalFramework.Path["images"] + @"Icons\Windows\icon_window_send_message.png");
             *
             * //Init Content
             * Fixed fixedContent = new Fixed();
             * fixedContent.Put(new Label("Place content here"), 0, 0);
             *
             * //ActionArea Buttons
             * TouchButtonIconWithText buttonOk = ActionAreaButton.FactoryGetDialogButtonType(PosBaseDialogButtonType.Ok);
             * TouchButtonIconWithText buttonCancel = ActionAreaButton.FactoryGetDialogButtonType(PosBaseDialogButtonType.Cancel);
             *
             * //ActionArea
             * ActionAreaButtons actionAreaButtons = new ActionAreaButtons();
             * actionAreaButtons.Add(new ActionAreaButton(buttonOk, ResponseType.Ok));
             * actionAreaButtons.Add(new ActionAreaButton(buttonCancel, ResponseType.Cancel));
             * //Init Object
             * this.InitObject(this, pDialogFlags, fileDefaultWindowIcon, windowTitle, windowSize, fixedContent, actionAreaButtons);
             */
        }
Example #7
0
        //XpoMode
        public TreeViewUser(Window pSourceWindow, XPGuidObject pDefaultValue, CriteriaOperator pXpoCriteria, Type pDialogType, GenericTreeViewMode pGenericTreeViewMode = GenericTreeViewMode.Default, GenericTreeViewNavigatorMode pGenericTreeViewNavigatorMode = GenericTreeViewNavigatorMode.Default)
        {
            Type xpoGuidObjectType = typeof(SYS_UserDetail);
            //Override Default Value with Parameter Default Value, this way we can have diferent Default Values for GenericTreeView
            SYS_UserDetail defaultValue = (pDefaultValue != null) ? pDefaultValue as SYS_UserDetail : null;
            //Override Default DialogType with Parameter Dialog Type, this way we can have diferent DialogTypes for GenericTreeView
            Type typeDialogClass = (pDialogType != null) ? pDialogType : typeof(DialogUserDetail);

            // XPO column properties
            List <GenericTreeViewColumnProperty> columnProperties = new List <GenericTreeViewColumnProperty>();

            columnProperties.Add(new GenericTreeViewColumnProperty("Code")
            {
                Title = Resx.global_record_code, MinWidth = 100
            });
            columnProperties.Add(new GenericTreeViewColumnProperty("Name")
            {
                Title = Resx.global_users, Expand = true
            });
            columnProperties.Add(new GenericTreeViewColumnProperty("Profile")
            {
                Title = Resx.global_profile, ChildName = "Designation", MinWidth = 160
            });
            //columnProperties.Add(new GenericTreeViewColumnProperty("MobilePhone") { Title = Resx.global_mobile_phone });
            columnProperties.Add(new GenericTreeViewColumnProperty("FiscalNumber")
            {
                Title = Resx.global_fiscal_number, MinWidth = 100
            });
            columnProperties.Add(new GenericTreeViewColumnProperty("UpdatedAt")
            {
                Title = Resx.global_record_date_updated, MinWidth = 150, MaxWidth = 150
            });

            //configure criteria/xpcollection/model
            CriteriaOperator criteria      = pXpoCriteria;
            XPCollection     xpoCollection = new XPCollection(GlobalFramework.SessionXpo, xpoGuidObjectType, criteria);

            //Call Base Initializer
            base.InitObject(
                pSourceWindow,                 //Pass parameter
                defaultValue,                  //Pass parameter
                pGenericTreeViewMode,          //Pass parameter
                pGenericTreeViewNavigatorMode, //Pass parameter
                columnProperties,              //Created Here
                xpoCollection,                 //Created Here
                typeDialogClass                //Created Here
                );

            //Protection to LogOff User
            this.RecordBeforeDelete += TreeView_RecordBeforeDelete;
        }
Example #8
0
        public static bool PersistWorkSessionMovement(Session pSession, POS_WorkSessionPeriod pWorkSessionPeriod, POS_WorkSessionMovementType pWorkSessionMovementType, FIN_DocumentFinanceMaster pDocumentFinanceMaster, FIN_DocumentFinancePayment pDocumentFinancePayment, SYS_UserDetail pUserDetail, POS_ConfigurationPlaceTerminal pTerminal, DateTime pDate, decimal pMovementAmount, string pDescription, uint pOrd = 1)
        {
            //Prevent Deleted Objects, Get Fresh Objects
            SYS_UserDetail userDetail = pSession.GetObjectByKey <SYS_UserDetail>(GlobalFramework.LoggedUser.Oid);
            POS_ConfigurationPlaceTerminal terminal = pSession.GetObjectByKey <POS_ConfigurationPlaceTerminal>(GlobalFramework.LoggedTerminal.Oid);
            POS_WorkSessionMovementType    workSessionMovementType = pSession.GetObjectByKey <POS_WorkSessionMovementType>(pWorkSessionMovementType.Oid);

            try
            {
                POS_WorkSessionMovement workSessionMovement = new POS_WorkSessionMovement(pSession)
                {
                    Ord = pOrd,
                    WorkSessionPeriod       = pWorkSessionPeriod,
                    WorkSessionMovementType = workSessionMovementType,
                    UserDetail     = userDetail,
                    Terminal       = terminal,
                    Date           = pDate,
                    MovementAmount = pMovementAmount,
                    Description    = pDescription
                };
                //Assign parent DocumentFinanceMaster and PaymentMethod
                if (pDocumentFinanceMaster != null)
                {
                    workSessionMovement.DocumentFinanceMaster = pDocumentFinanceMaster;
                    workSessionMovement.DocumentFinanceType   = pDocumentFinanceMaster.DocumentType;
                    workSessionMovement.PaymentMethod         = pDocumentFinanceMaster.PaymentMethod;
                }
                //Assign parent DocumentFinancePayment and PaymentMethod
                if (pDocumentFinancePayment != null)
                {
                    workSessionMovement.DocumentFinancePayment = pDocumentFinancePayment;
                    workSessionMovement.DocumentFinanceType    = pDocumentFinancePayment.DocumentType;
                    workSessionMovement.PaymentMethod          = pDocumentFinancePayment.PaymentMethod;
                }

                //Save WorkSessionMovement if not in UOW
                if (pSession.GetType() == typeof(Session))
                {
                    workSessionMovement.Save();
                }

                return(true);
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                return(false);
            }
        }
Example #9
0
        public PosPinPadDialog(Window pSourceWindow, DialogFlags pDialogFlags, SYS_UserDetail pUserDetail)
            : base(pSourceWindow, pDialogFlags)
        {
            //Dialog compile time preferences
            Boolean showCancel   = false;
            int     DialogHeight = (showCancel) ? 465 : 440;//465 : 400;

            //Init Local Vars Parameters
            _selectedUserDetail = pUserDetail;
            //Init Local Vars
            String            windowTitle           = Resx.window_title_dialog_request_user_pin;
            Size              windowSize            = new Size(332, DialogHeight);
            String            fileDefaultWindowIcon = FrameworkUtils.OSSlash(GlobalFramework.Path["images"] + @"Icons\Windows\icon_window_users.png");
            String            fontNumberPadPinButtonKeysTextAndLabel = GlobalFramework.Settings["fontNumberPadPinButtonKeysTextAndLabel"];
            ActionAreaButtons actionAreaButtons;

            //Init Content
            Fixed fixedContent = new Fixed();

            //NumberPadPin
            _numberPadPin = new NumberPadPin(pSourceWindow, "numberPadPin", System.Drawing.Color.Transparent, fontNumberPadPinButtonKeysTextAndLabel, "12", Color.White, Color.Black, 100, 67);
            _numberPadPin.ButtonKeyOK.Clicked += ButtonKeyOK_Clicked;

            fixedContent.Put(_numberPadPin, 0, 0);

            if (showCancel)
            {
                //ActionArea Buttons
                TouchButtonIconWithText buttonCancel = ActionAreaButton.FactoryGetDialogButtonType(PosBaseDialogButtonType.Cancel);

                //ActionArea
                actionAreaButtons = new ActionAreaButtons();
                actionAreaButtons.Add(new ActionAreaButton(buttonCancel, ResponseType.Cancel));
            }
            else
            {
                actionAreaButtons = new ActionAreaButtons();
            }

            //Init Mode
            _numberPadPin.Mode = (_selectedUserDetail.PasswordReset) ? NumberPadPinMode.PasswordOld :
                                 NumberPadPinMode.Password;

            //Events
            this.KeyReleaseEvent += PosPinPadDialog_KeyReleaseEvent;

            //Init Object
            this.InitObject(this, pDialogFlags, fileDefaultWindowIcon, windowTitle, windowSize, fixedContent, actionAreaButtons);
        }
Example #10
0
 public void DeleteLoggedUsers()
 {
     try
     {
         foreach (Guid item in GlobalFramework.SessionApp.LoggedUsers.Keys)
         {
             SYS_UserDetail user = (SYS_UserDetail)FrameworkUtils.GetXPGuidObject(typeof(SYS_UserDetail), item);
             FrameworkUtils.Audit("USER_LOGOUT", string.Format(Resx.audit_message_used_forced_logout, user.Name));
         }
         GlobalFramework.SessionApp.LoggedUsers.Clear();
     }
     catch (Exception ex)
     {
         _log.Error(ex.Message, ex);
     }
 }
Example #11
0
        public bool ValidatePassword(SYS_UserDetail pUserDetail)
        {
            bool   result   = false;
            string password = _entryPin.Text;

            string sql = string.Format(@"
                SELECT 
                    AccessPin 
                FROM 
                    sys_userdetail 
                WHERE 
                    (Disabled <> 1 OR Disabled IS NULL)
                    AND Oid = '{0}'
                ;", pUserDetail.Oid
                                       );

            try
            {
                var resultObject = GlobalFramework.SessionXpo.ExecuteScalar(sql);

                if (resultObject != null && resultObject.GetType() == typeof(String) && CryptographyUtils.SaltedString.ValidateSaltedString(resultObject.ToString(), password))
                {
                    _entryPin.ModifyText(StateType.Normal, Utils.ColorToGdkColor(Color.Black));
                    _entryPin.Visibility = false;
                    _entryPinShowStatus  = false;
                    result = true;
                }
                else
                {
                    FrameworkUtils.Audit("USER_LOGIN_ERROR", string.Format(Resx.audit_message_user_login_error, pUserDetail.Name));
                    _entryPin.ModifyText(StateType.Normal, Utils.ColorToGdkColor(Color.Red));
                    _entryPin.Text       = Resx.status_message_pin_error;
                    _entryPin.Visibility = true;
                    _entryPinShowStatus  = true;
                    result = false;
                }

                return(result);
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                return(result);
            }
        }
Example #12
0
        void _tablePadUsers_Clicked(object sender, EventArgs e)
        {
            TouchButtonBase button = (TouchButtonBase)sender;

            //Assign CurrentId to TablePad.CurrentId, to Know last Clicked Button Id
            _tablePadUsers.SelectedButtonOid = button.CurrentButtonOid;
            //To be Used in Dialog Result
            _selectedUserDetail = (SYS_UserDetail)FrameworkUtils.GetXPGuidObject(typeof(SYS_UserDetail), button.CurrentButtonOid);

            if (_selectedUserDetail.PasswordReset)
            {
                //_log.Debug(string.Format("Name: [{0}], PasswordReset: [{1}]", _selectedUserDetail.Name, _selectedUserDetail.PasswordReset));
                Utils.ShowMessageTouch(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, Resx.global_information,
                                       string.Format(Resx.dialog_message_user_request_change_password, _selectedUserDetail.Name, SettingsApp.DefaultValueUserDetailAccessPin)
                                       );
            }

            //Send Response to Replace the Old Ok Button
            Respond(ResponseType.Ok);
        }
Example #13
0
        //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        //Logic

        public bool ProcessPassword(Window pSourceWindow, SYS_UserDetail pUserDetail)
        {
            bool result = false;

            try
            {
                switch (_mode)
                {
                case NumberPadPinMode.Password:
                    //Valid User
                    if (ValidatePassword(pUserDetail))
                    {
                        //Start Application
                        ProcessLogin(pUserDetail);
                        //Finish Job usefull to PosPinDialog send Respond(ResponseType.Ok) when Done
                        result = true;
                    }
                    break;

                case NumberPadPinMode.PasswordOld:
                    //Valid User
                    if (ValidatePassword(pUserDetail))
                    {
                        _mode = NumberPadPinMode.PasswordNew;
                        UpdateStatusLabels();
                    }
                    break;

                case NumberPadPinMode.PasswordNew:
                    //Check If New Password is Equal to Old Password using ValidatePassword
                    if (CryptographyUtils.SaltedString.ValidateSaltedString(pUserDetail.AccessPin, _entryPin.Text))
                    {
                        //Show Error Message
                        ResponseType responseType = Utils.ShowMessageTouch(pSourceWindow, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Resx.window_title_dialog_change_password, Resx.pos_pinpad_message_password_equal_error);
                        ClearEntryPinStatusMessage(true);
                    }
                    else
                    {
                        _passwordNew = _entryPin.Text;
                        _mode        = NumberPadPinMode.PasswordNewConfirm;
                        UpdateStatusLabels();
                    }
                    break;

                case NumberPadPinMode.PasswordNewConfirm:
                    if (_passwordNew == _entryPin.Text)
                    {
                        //Commit Changes
                        pUserDetail.AccessPin         = CryptographyUtils.SaltedString.GenerateSaltedString(_passwordNew);
                        pUserDetail.PasswordReset     = false;
                        pUserDetail.PasswordResetDate = FrameworkUtils.CurrentDateTimeAtomic();
                        pUserDetail.Save();
                        FrameworkUtils.Audit("USER_CHANGE_PASSWORD", string.Format(Resx.audit_message_user_change_password, pUserDetail.Name));
                        ResponseType responseType = Utils.ShowMessageTouch(pSourceWindow, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, Resx.window_title_dialog_change_password, Resx.pos_pinpad_message_password_changed);
                        //Start Application
                        ProcessLogin(pUserDetail);
                        //Finish Job usefull to PosPinDialog send Respond(ResponseType.Ok) when Done
                        result = true;
                    }
                    else
                    {
                        //Show Error Message
                        ResponseType responseType = Utils.ShowMessageTouch(pSourceWindow, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Resx.window_title_dialog_change_password, Resx.pos_pinpad_message_password_confirmation_error);
                        ClearEntryPinStatusMessage(true);
                        //Return to
                        _mode = NumberPadPinMode.PasswordNew;
                        UpdateStatusLabels();
                        //Reset passwordNew
                        _passwordNew = string.Empty;
                    }
                    break;

                case NumberPadPinMode.PasswordReset:
                    //Valid User
                    if (ValidatePassword(pUserDetail))
                    {
                        _mode = NumberPadPinMode.PasswordNew;
                        UpdateStatusLabels();
                    }
                    //Return to default request password mode
                    else
                    {
                        _mode = NumberPadPinMode.Password;
                    }
                    break;

                default:
                    break;
                }

                //Always focus Entry
                _entryPin.GrabFocus();
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
            }

            return(result);
        }
Example #14
0
        private static bool SystemPrintInsert(FIN_DocumentFinanceMaster pDocumentFinanceMaster, FIN_DocumentFinancePayment pDocumentFinancePayment, string pPrinterDesignation, int pPrintCopies, List <int> pCopyNames, bool pSecondPrint, string pPrintMotive, SYS_UserDetail pUserDetail, POS_ConfigurationPlaceTerminal pConfigurationPlaceTerminal)
        {
            bool result = false;

            try
            {
                //Start UnitOfWork
                using (UnitOfWork uowSession = new UnitOfWork())
                {
                    string designation = String.Empty;
                    //Get Objects into Current UOW Session
                    SYS_UserDetail userDetail = (SYS_UserDetail)FrameworkUtils.GetXPGuidObject(uowSession, typeof(SYS_UserDetail), pUserDetail.Oid);
                    POS_ConfigurationPlaceTerminal configurationPlaceTerminal = (POS_ConfigurationPlaceTerminal)FrameworkUtils.GetXPGuidObject(uowSession, typeof(POS_ConfigurationPlaceTerminal), pConfigurationPlaceTerminal.Oid);

                    //Convert CopyNames List to Comma Delimited String
                    string copyNamesCommaDelimited = CustomReport.CopyNamesCommaDelimited(pCopyNames);

                    //SystemPrint
                    SYS_SystemPrint systemPrint = new SYS_SystemPrint(uowSession)
                    {
                        Date        = FrameworkUtils.CurrentDateTimeAtomic(),
                        Designation = designation,
                        PrintCopies = pPrintCopies,
                        CopyNames   = copyNamesCommaDelimited,
                        SecondPrint = pSecondPrint,
                        UserDetail  = userDetail,
                        Terminal    = configurationPlaceTerminal
                    };
                    if (pPrintMotive != String.Empty)
                    {
                        systemPrint.PrintMotive = pPrintMotive;
                    }

                    //Mode: DocumentFinanceMaster
                    if (pDocumentFinanceMaster != null)
                    {
                        FIN_DocumentFinanceMaster documentFinanceMaster = (FIN_DocumentFinanceMaster)FrameworkUtils.GetXPGuidObject(uowSession, typeof(FIN_DocumentFinanceMaster), pDocumentFinanceMaster.Oid);
                        systemPrint.DocumentMaster = documentFinanceMaster;
                        designation = string.Format("{0} {1} : {2}", Resx.global_printed, documentFinanceMaster.DocumentType.Designation, documentFinanceMaster.DocumentNumber);
                        //Update DocumentFinanceMaster
                        if (!documentFinanceMaster.Printed)
                        {
                            documentFinanceMaster.Printed = true;
                        }
                    }
                    //Mode: DocumentFinancePayment
                    if (pDocumentFinancePayment != null)
                    {
                        FIN_DocumentFinancePayment documentFinancePayment = (FIN_DocumentFinancePayment)FrameworkUtils.GetXPGuidObject(uowSession, typeof(FIN_DocumentFinancePayment), pDocumentFinancePayment.Oid);
                        systemPrint.DocumentPayment = documentFinancePayment;
                        designation = string.Format("{0} {1} : {2}", Resx.global_printed, documentFinancePayment.DocumentType.Designation, documentFinancePayment.PaymentRefNo);
                    }
                    systemPrint.Designation = designation;

                    try
                    {
                        //Commit UOW Changes : Before get current OrderMain
                        uowSession.CommitChanges();
                        //Audit
                        FrameworkUtils.Audit("SYSTEM_PRINT_FINANCE_DOCUMENT", designation);
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex.Message, ex);
                        uowSession.RollbackTransaction();
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
            }
            return(result);
        }
Example #15
0
        public static bool Add(Session pSession, ProcessArticleStockMode pMode, FIN_DocumentFinanceDetail pDocumentDetail, ERP_Customer pCustomer, int pOrd, DateTime pDocumentDate, string pDocumentNumber, FIN_Article pArticle, decimal pQuantity, string pNotes)
        {
            //Log4Net
            log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            bool    result   = false;
            decimal quantity = 0.0m;

            try
            {
                switch (pMode)
                {
                case ProcessArticleStockMode.Out:
                    quantity = -(pQuantity);
                    break;

                case ProcessArticleStockMode.In:
                    quantity = pQuantity;
                    break;
                }

                //Get Objects in same Session
                ERP_Customer customer = (ERP_Customer)pSession.GetObjectByKey(typeof(ERP_Customer), pCustomer.Oid);
                FIN_Article  article  = (FIN_Article)pSession.GetObjectByKey(typeof(FIN_Article), pArticle.Oid);
                POS_ConfigurationPlaceTerminal terminal = (POS_ConfigurationPlaceTerminal)pSession.GetObjectByKey(typeof(POS_ConfigurationPlaceTerminal), GlobalFramework.LoggedTerminal.Oid);
                SYS_UserDetail userDetail = (SYS_UserDetail)pSession.GetObjectByKey(typeof(SYS_UserDetail), GlobalFramework.LoggedUser.Oid);

                FIN_ArticleStock articleStock = new FIN_ArticleStock(pSession)
                {
                    Customer     = customer,
                    Date         = pDocumentDate,
                    Article      = article,
                    Quantity     = quantity,
                    Notes        = pNotes,
                    CreatedWhere = terminal,
                    CreatedBy    = userDetail
                };
                if (pDocumentNumber != string.Empty)
                {
                    articleStock.DocumentNumber = pDocumentNumber;
                }
                if (pDocumentDetail != null)
                {
                    articleStock.DocumentNumber = pDocumentDetail.DocumentMaster.DocumentNumber;
                    articleStock.DocumentMaster = pDocumentDetail.DocumentMaster;
                    articleStock.DocumentDetail = pDocumentDetail;
                }

                //Only saves if not Working on a Unit Of Work Transaction
                if (pSession.GetType() != typeof(UnitOfWork))
                {
                    articleStock.Save();
                }

                //Audit
                switch (pMode)
                {
                case ProcessArticleStockMode.Out:
                    FrameworkUtils.Audit("STOCK_MOVEMENT_OUT", string.Format(Resx.audit_message_stock_movement_out, article.Designation, FrameworkUtils.DecimalToString(quantity, SettingsApp.DecimalFormatStockQuantity)));
                    break;

                case ProcessArticleStockMode.In:
                    FrameworkUtils.Audit("STOCK_MOVEMENT_IN", string.Format(Resx.audit_message_stock_movement_in, article.Designation, FrameworkUtils.DecimalToString(quantity, SettingsApp.DecimalFormatStockQuantity)));
                    break;
                }

                result = true;
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
            }

            return(result);
        }
Example #16
0
        public static bool Backup(Window pSourceWindow)
        {
            bool   backupResult       = true;
            string fileName           = string.Empty;
            string fullFileNamePacked = string.Empty;
            string fileHash           = string.Empty;
            Thread thread;

            try
            {
                //FrameworkUtils.ShowWaitingCursor();

                Init();

                //Initialize object before start Actions, to allocate database (automatic backups) and assign CreatedAt, this way next Terminal Skip Backup when trigger backup event
                SYS_SystemBackup systemBackup = new SYS_SystemBackup(GlobalFramework.SessionXpo)
                {
                    FileName       = Path.GetRandomFileName(),
                    FileNamePacked = Path.GetRandomFileName(),
                    DataBaseType   = GlobalFramework.DatabaseType,
                    Version        = FrameworkUtils.GetNextTableFieldID("SYS_SystemBackup", "Version", false),
                    Terminal       = (POS_ConfigurationPlaceTerminal)GlobalFramework.SessionXpo.GetObjectByKey(typeof(POS_ConfigurationPlaceTerminal), GlobalFramework.LoggedTerminal.Oid)
                };
                systemBackup.Save();

                switch (GlobalFramework.DatabaseType)
                {
                case DatabaseType.MonoLite:
                case DatabaseType.SQLite:
                    fileName = GetBackupFileName(_fileExtension, systemBackup.Version);
                    //Non Thread
                    //resultBackup = BackupSQLite(fileName);
                    //Thread
                    thread = new Thread(() => backupResult = BackupSQLite(fileName));
                    Utils.ThreadStart(pSourceWindow, thread);
                    break;

                case DatabaseType.MSSqlServer:
                    fileName = GetBackupFileName(_fileExtension, systemBackup.Version);
                    //Non Thread
                    //resultBackup = BackupMSSqlServer(fileName);
                    //Thread
                    thread = new Thread(() => backupResult = BackupMSSqlServer(fileName));
                    Utils.ThreadStart(pSourceWindow, thread);
                    break;

                case DatabaseType.MySql:
                    fileName = GetBackupFileName(_fileExtension, systemBackup.Version);
                    //Non Thread
                    //resultBackup = BackupMySql(_backupConnectionString, fileName);
                    //Thread
                    thread = new Thread(() => backupResult = BackupMySql(_backupConnectionString, fileName));
                    Utils.ThreadStart(pSourceWindow, thread);
                    break;

                default:
                    break;
                }

                if (_debug)
                {
                    _log.Debug(string.Format("Backup DatabaseType: [{0}] to FileName: [{1}], resultBackup:[{2}]", GlobalFramework.DatabaseType, fileName, backupResult));
                }

                if (backupResult)
                {
                    //Update SystemBackup after Backup
                    systemBackup.FileName = Path.GetFileName(fileName);
                    systemBackup.FilePath = Path.GetDirectoryName(fileName);

                    //Extra Protection for System Automatic Backups, with unlogged users
                    SYS_UserDetail userDetail = (GlobalFramework.LoggedUser != null) ? (SYS_UserDetail)GlobalFramework.SessionXpo.GetObjectByKey(typeof(SYS_UserDetail), GlobalFramework.LoggedUser.Oid) : null;
                    if (userDetail != null)
                    {
                        systemBackup.User = userDetail;
                    }

                    //Non MSSqlServer Work: Cant Get Remote File Sizes, Hash etc from LPDev Backups
                    if (GlobalFramework.DatabaseType != DatabaseType.MSSqlServer)
                    {
                        //systemBackup.FileSize = new FileInfo(fileName).Length;
                        systemBackup.FileNamePacked = Path.ChangeExtension(systemBackup.FileName, SettingsApp.BackupExtension);
                        //Compress File : Required OSSlash
                        fullFileNamePacked = FrameworkUtils.OSSlash(string.Format(@"{0}\{1}", systemBackup.FilePath, systemBackup.FileNamePacked));
                        // Old Method before PluginSoftwareVendor Implementation
                        //backupResult = Utils.ZipPack(new string[] { fileName }, fullFileNamePacked);
                        backupResult = GlobalFramework.PluginSoftwareVendor.BackupDatabase(SettingsApp.SecretKey, new string[] { fileName }, fullFileNamePacked);
                        // Add FileHash
                        if (backupResult)
                        {
                            systemBackup.FileHash = FrameworkUtils.MD5HashFile(fullFileNamePacked);
                        }
                    }
                    //MSSqlServer
                    else
                    {
                        //Must Assign FileName to FileNamePacked else next backup violate iFileNamePacked_SystemBackup Index
                        systemBackup.FileNamePacked = systemBackup.FileName;
                    }

                    if (backupResult)
                    {
                        //Commit Object
                        systemBackup.Save();
                        //Remove Temporary Backup
                        try
                        {
                            if (File.Exists(fileName))
                            {
                                File.Delete(fileName);
                            }
                        }
                        catch (Exception ex)
                        {
                            _log.Error(ex.Message, ex);
                        }

                        //Post Backup
                        FrameworkUtils.Audit("DATABASE_BACKUP", string.Format(Resx.audit_message_database_backup,
                                                                              (fullFileNamePacked != string.Empty) ? fullFileNamePacked : systemBackup.FileNamePacked
                                                                              ));

                        //Moved to Thread Outside > Only Show if not in Silence Mode
                        if (pSourceWindow != null)
                        {
                            Utils.ShowMessageTouch(pSourceWindow, DialogFlags.Modal, _sizeDialog, MessageType.Info, ButtonsType.Close, Resx.global_information, string.Format(Resx.dialog_message_database_backup_successfully, fullFileNamePacked));
                        }
                    }
                    else
                    {
                        //On Error Delete Object form Database, this way we dont have a invalid Backup
                        systemBackup.Delete();
                    }
                }
                else
                {
                    //Moved to Thread Outside > Only Show if not in Silence Mode
                    if (pSourceWindow != null)
                    {
                        Utils.ShowMessageTouch(pSourceWindow, DialogFlags.Modal, _sizeDialog, MessageType.Error, ButtonsType.Close, Resx.global_error, string.Format(Resx.dialog_message_database_backup_error, fullFileNamePacked));
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
            }
            finally
            {
                //FrameworkUtils.HideWaitingCursor();
            }

            return(backupResult);
        }
Example #17
0
        public static bool Restore(Window pSourceWindow, DataBaseRestoreFrom pRestoreFrom)
        {
            try
            {
                //FrameworkUtils.ShowWaitingCursor();

                Init();

                bool   restoreResult  = false;
                string sql            = string.Empty;
                string fileName       = string.Empty;
                string fileNamePacked = string.Empty;
                //default pathBackups from Settings, can be Overrided in ChooseFromFilePickerDialog Mode
                string pathBackups = _pathBackups;
                DataBaseBackupFileInfo fileInfo = null;
                Guid systemBackupGuid           = Guid.Empty;
                //Required to assign current FileName and FileNamePacked after restore, else name will be the TempName ex acegvpls.soj & n2sjiamk.32o
                SYS_SystemBackup systemBackup = null;
                string           currentFileName = string.Empty, currentFileNamePacked = string.Empty, currentFilePath = string.Empty, currentFileHash = string.Empty;
                SYS_UserDetail   currentUserDetail = null;

                switch (pRestoreFrom)
                {
                case DataBaseRestoreFrom.SystemBackup:
                    fileInfo = GetSelectRecordFileName(pSourceWindow);
                    //Equal to Filename not FileNamePacked
                    fileNamePacked = fileInfo.FileNamePacked;
                    if (_debug)
                    {
                        _log.Debug(string.Format("RestoreBackup: FileNamePacked:[{0}], FileHashDB:[{1}], FileHashFile:[{2}] FileHashValid:[{3}]", fileInfo.FileNamePacked, fileInfo.FileHashDB, fileInfo.FileHashFile, fileInfo.FileHashValid));
                    }
                    if (fileInfo.Response != ResponseType.Cancel && !fileInfo.FileHashValid)
                    {
                        //#EQUAL#1
                        string message = string.Format(Resx.dialog_message_database_restore_error_invalid_backup_file, fileNamePacked);
                        Utils.ShowMessageTouch(pSourceWindow, DialogFlags.Modal, new Size(600, 300), MessageType.Error, ButtonsType.Ok, Resx.global_error, message);
                        return(false);
                    }
                    break;

                case DataBaseRestoreFrom.ChooseFromFilePickerDialog:
                    FileFilter          fileFilterBackups = Utils.GetFileFilterBackups();
                    PosFilePickerDialog dialog            = new PosFilePickerDialog(pSourceWindow, DialogFlags.DestroyWithParent, fileFilterBackups, FileChooserAction.Open);
                    ResponseType        response          = (ResponseType)dialog.Run();
                    if (response == ResponseType.Ok)
                    {
                        fileNamePacked = dialog.FilePicker.Filename;
                        //Override Default pathBackups
                        pathBackups = string.Format("{0}/", Path.GetDirectoryName(fileNamePacked));
                    }
                    dialog.Destroy();
                    break;

                default:
                    break;
                }

                if (GlobalFramework.DatabaseType != DatabaseType.MSSqlServer)
                {
                    fileName = Path.ChangeExtension(fileNamePacked, _fileExtension);
                }
                else
                {
                    //Require to assign filename and packed filename from fileInfo
                    fileName       = fileInfo.FileName;
                    fileNamePacked = fileInfo.FileName;
                }

                if (fileName != string.Empty)
                {
                    if (_debug)
                    {
                        _log.Debug(string.Format("Restore Filename:[{0}] to pathBackups[{1}]", fileNamePacked, pathBackups));
                    }
                    if (GlobalFramework.DatabaseType != DatabaseType.MSSqlServer)
                    {
                        // Old Method before PluginSoftwareVendor Implementation
                        //restoreResult = Utils.ZipUnPack(fileNamePacked, pathBackups, true);
                        restoreResult = GlobalFramework.PluginSoftwareVendor.RestoreBackup(SettingsApp.SecretKey, fileNamePacked, pathBackups, true);
                        if (_debug)
                        {
                            _log.Debug(string.Format("RestoreBackup: unpackResult:[{0}]", restoreResult));
                        }
                    }

                    if (restoreResult || GlobalFramework.DatabaseType == DatabaseType.MSSqlServer)
                    {
                        //Get properties from SystemBackup Object before Restore, to Assign Properties after Restore (FilePath,FileHash,User,Terminal)
                        sql = string.Format("SELECT Oid FROM sys_systembackup WHERE fileNamePacked = '{0}';", Path.GetFileName(fileNamePacked));
                        systemBackupGuid = FrameworkUtils.GetGuidFromQuery(sql);
                        if (systemBackupGuid != Guid.Empty)
                        {
                            systemBackup          = (SYS_SystemBackup)FrameworkUtils.GetXPGuidObject(GlobalFramework.SessionXpo, typeof(SYS_SystemBackup), systemBackupGuid);
                            currentFileName       = systemBackup.FileName;
                            currentFileNamePacked = systemBackup.FileNamePacked;
                            currentFilePath       = systemBackup.FilePath;
                            currentFileHash       = systemBackup.FileHash;
                            currentUserDetail     = systemBackup.User;
                        }

                        //Send fileNamePacked only to show its name in success dialog
                        if (Restore(pSourceWindow, fileName, fileNamePacked, systemBackup))
                        {
                            //Audit DATABASE_RESTORE
                            FrameworkUtils.Audit("DATABASE_RESTORE", string.Format(Resx.audit_message_database_restore, fileNamePacked));
                            //Required to DropIdentity before get currentDocumentFinanceYear Object, else it exists in old non restored Session
                            GlobalFramework.SessionXpo.DropIdentityMap();
                            //Get Current Active FinanceYear
                            FIN_DocumentFinanceYears currentDocumentFinanceYear = ProcessFinanceDocumentSeries.GetCurrentDocumentFinanceYear();

                            //Disable all Active FinanceYear Series and SeriesTerminal if Exists
                            if (currentDocumentFinanceYear != null)
                            {
                                ProcessFinanceDocumentSeries.DisableActiveYearSeriesAndTerminalSeries(currentDocumentFinanceYear);
                            }

                            //Restore SystemBackup properties else it keeps temp names after Restore acegvpls.soj & n2sjiamk.32o, empty hash etc
                            if (systemBackupGuid != Guid.Empty)
                            {
                                //ReFresh UserDetail from Repository
                                currentUserDetail = (currentUserDetail != null) ? (SYS_UserDetail)FrameworkUtils.GetXPGuidObject(GlobalFramework.SessionXpo, typeof(SYS_UserDetail), currentUserDetail.Oid) : null;
                                //Get Current Restored systemBackup Object
                                systemBackup                = (SYS_SystemBackup)FrameworkUtils.GetXPGuidObject(GlobalFramework.SessionXpo, typeof(SYS_SystemBackup), systemBackupGuid);
                                systemBackup.FileName       = currentFileName;
                                systemBackup.FileNamePacked = currentFileNamePacked;
                                systemBackup.FilePath       = currentFilePath;
                                systemBackup.FileHash       = currentFileHash;
                                systemBackup.User           = currentUserDetail;
                                systemBackup.Save();
                            }
                            //If Cant get Record, because works on ChooseFromFilePickerDialog, we must recreate Record from file, only in the case of record with miss fileNamePacked
                            else
                            {
                                sql = "DELETE FROM sys_systembackup WHERE FilePath IS NULL AND FileHash IS NULL AND User IS NULL;";
                                GlobalFramework.SessionXpo.ExecuteNonQuery(sql);
                            }

                            //Audit
                            FrameworkUtils.Audit("APP_CLOSE");
                            //Call QuitWithoutConfirmation without Audit
                            LogicPos.QuitWithoutConfirmation(false);

                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        //#EQUAL#1
                        string message = string.Format(Resx.dialog_message_database_restore_error_invalid_backup_file, fileNamePacked);
                        Utils.ShowMessageTouch(pSourceWindow, DialogFlags.Modal, new Size(600, 300), MessageType.Error, ButtonsType.Ok, Resx.global_error, message);
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                return(false);
            }
            finally
            {
                //FrameworkUtils.HideWaitingCursor();
            }
        }
Example #18
0
 //Main Method  - With and Without Session
 public static bool PersistWorkSessionMovement(POS_WorkSessionPeriod pWorkSessionPeriod, POS_WorkSessionMovementType pWorkSessionMovementType, FIN_DocumentFinanceMaster pDocumentFinanceMaster, FIN_DocumentFinancePayment pDocumentFinancePayment, SYS_UserDetail pUserDetail, POS_ConfigurationPlaceTerminal pTerminal, DateTime pDate, decimal pMovementAmount, string pDescription, uint pOrd = 1)
 {
     return(PersistWorkSessionMovement(GlobalFramework.SessionXpo, pWorkSessionPeriod, pWorkSessionMovementType, pDocumentFinanceMaster, pDocumentFinancePayment, pUserDetail, pTerminal, pDate, pMovementAmount, pDescription));
 }