Пример #1
0
        private void LoadData()
        {
            var Id = dgvList.Id;

            if (Id != 0)
            {
                try
                {
                    var m = UnitMeasureFacade.Select(Id);
                    txtCode.Text   = m.Code;
                    txtFactor.Text = m.Default_Factor.ToString();
                    txtDesc.Text   = m.Description;
                    txtNote.Text   = m.Note;
                    SetStatus(m.Status);
                    LockControls();
                    IsDirty = false;
                    SessionLogFacade.Log(Type.Priority_Information, Type.Module_IC_Unit_Measure, Type.Log_View, "View. Id=" + m.Id + ", Code=" + m.Code);
                }
                catch (Exception ex)
                {
                    MessageFacade.Show(MessageFacade.error_load_record + "\r\n" + ex.Message, LabelFacade.sy_unit_measure, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SYS.ErrorLogFacade.Log(ex);
                }
            }
            else    // when delete all => disable buttons and clear all controls
            {
                if (dgvList.RowCount == 0)
                {
                    btnUnlock.Enabled = false;
                    ClearAllBoxes();
                }
            }
        }
Пример #2
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            if (!Privilege.CanAccess(Type.Function_IC_Unit_Measure, Type.Privilege_New))
            {
                MessageFacade.Show(MessageFacade.privilege_no_access, LabelFacade.sy_new, MessageBoxButtons.OK, MessageBoxIcon.Information);
                SessionLogFacade.Log(Type.Priority_Caution, Type.Module_IC_Unit_Measure, Type.Log_NoAccess, "New: No access");
                return;
            }
            if (IsExpand)
            {
                picExpand_Click(sender, e);
            }
            ClearAllBoxes();
            if (dgvList.CurrentRow != null)
            {
                dgvList.CurrentRow.Selected = false;
            }
            Id = 0;
            LockControls(false);

            if (dgvList.CurrentRow != null)
            {
                RowIndex = dgvList.CurrentRow.Index;
            }
            SessionLogFacade.Log(Type.Priority_Information, Type.Module_IC_Unit_Measure, Type.Log_New, "New clicked");
        }
Пример #3
0
 private void btnSaveNew_Click(object sender, EventArgs e)
 {
     SessionLogFacade.Log(Type.Priority_Information, Type.Module_IC_Unit_Measure, Type.Log_SaveAndNew, "Saved and new. Id=" + dgvList.Id + ", Code=" + txtCode.Text);
     btnSave_Click(sender, e);
     if (btnSaveNew.Enabled)
     {
         return;
     }
     btnNew_Click(sender, e);
 }
Пример #4
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         var Id = dgvList.Id;
         if (Id == 0)
         {
             return;
         }
         // If referenced
         //todo: check if exist in ic_item
         // If locked
         var    lInfo = UnitMeasureFacade.GetLock(Id);
         string msg   = "";
         if (lInfo.Locked)
         {
             msg = string.Format(MessageFacade.delete_locked, lInfo.Lock_By, lInfo.Lock_At);
             if (!Privilege.CanAccess(Type.Function_IC_Unit_Measure, "O"))
             {
                 MessageFacade.Show(msg, LabelFacade.sy_delete, MessageBoxButtons.OK, MessageBoxIcon.Information);
                 SessionLogFacade.Log(Type.Priority_Caution, Type.Module_IC_Unit_Measure, Type.Log_Delete, "Cannot delete. Currently locked by '" + lInfo.Lock_By + "' since '" + lInfo.Lock_At + "' . Id=" + dgvList.Id + ", Code=" + txtCode.Text);
                 return;
             }
         }
         // Delete
         msg = MessageFacade.delete_confirmation;
         if (lInfo.Locked)
         {
             msg = string.Format(MessageFacade.lock_currently, lInfo.Lock_By, lInfo.Lock_At) + "'\n" + msg;
         }
         if (MessageFacade.Show(msg, LabelFacade.sy_delete, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
         {
             return;
         }
         try
         {
             UnitMeasureFacade.SetStatus(Id, Type.RecordStatus_Deleted);
         }
         catch (Exception ex)
         {
             MessageFacade.Show(MessageFacade.error_delete + "\r\n" + ex.Message, LabelFacade.sy_delete, MessageBoxButtons.OK, MessageBoxIcon.Error);
             ErrorLogFacade.Log(ex);
         }
         RefreshGrid();
         // log
         SessionLogFacade.Log(Type.Priority_Warning, Type.Module_IC_Unit_Measure, Type.Log_Delete, "Deleted. Id=" + dgvList.Id + ", Code=" + txtCode.Text);
     }
     catch (Exception ex)
     {
         MessageFacade.Show(MessageFacade.error_delete + "\r\n" + ex.Message, LabelFacade.sy_delete, MessageBoxButtons.OK, MessageBoxIcon.Error);
         ErrorLogFacade.Log(ex);
     }
 }
Пример #5
0
        private bool Save()
        {
            if (!IsValidated())
            {
                return(false);
            }
            Cursor = Cursors.WaitCursor;
            var m   = new Account();
            var log = new SessionLog {
                Module = Type.Module_IC_Location
            };

            m.Id          = Id;
            m.Code        = txtCode.Text.Trim();
            m.Description = txtDesc.Text;
            m.Type        = cboNormalBalance.Text.Substring(0, 1);
            m.Address     = txtStructureCode.Text;
            m.Name        = txtStructureCodeDesc.Text;
            m.Phone       = txtGroup.Text;
            m.Fax         = txtFax.Text;
            m.Email       = txtEmail.Text;
            m.Note        = txtNote.Text;
            if (m.Id == 0)
            {
                log.Priority = Type.Priority_Information;
                log.Type     = Type.Log_Insert;
            }
            else
            {
                log.Priority = Type.Priority_Caution;
                log.Type     = Type.Log_Update;
            }
            try
            {
                m.Id = AccountFacade.Save(m);
            }
            catch (Exception ex)
            {
                MessageFacade.Show(MessageFacade.error_save + "\r\n" + ex.Message, LabelFacade.sy_save, MessageBoxButtons.OK, MessageBoxIcon.Error);
                ErrorLogFacade.Log(ex);
            }
            if (dgvList.RowCount > 0)
            {
                RowIndex = dgvList.CurrentRow.Index;
            }
            RefreshGrid(m.Id);
            LockControls();
            Cursor      = Cursors.Default;
            log.Message = "Saved. Id=" + m.Id + ", Code=" + txtCode.Text;
            SessionLogFacade.Log(log);
            IsDirty = false;
            return(true);
        }
Пример #6
0
        public static bool Init()
        {
            SetVersion();

            // Splash screen
            fSplash = new frmSplash();
            fSplash.SetAppName(" v " + SYS.App.version);
            fSplash.Show();
            fSplash.ShowMsg("Initializing the application...");
            fSplash.TopMost = true;
            // Database connection string from setting.ini
            try
            {
                fSplash.ShowMsg("Loading settings...");
                LoadSettings();

                fSplash.ShowMsg("Connecting to the database ...");
                SqlFacade.OpenConnection(); // Database connection: open/test

                fSplash.ShowMsg("Ensuring database setup ...");
                SqlFacade.EnsureDBSetup();  // Create tables if not exist
            }
            catch (Exception ex)
            {
                fSplash.ShowError(ex.Message);
                fSplash.Visible = false;
                fSplash.ShowDialog();
                ErrorLogFacade.LogToFile(ex);
                return(false);
            }

            //Session
            session.Username          = "******"; //todo: logged in user (to be removed)
            session.Branch_Code       = "000";
            session.Machine_Name      = Environment.MachineName;
            session.Machine_User_Name = Environment.UserName;
            session.Version           = version;

            LabelFacade.LoadSystemLabel();
            MessageFacade.LoadSystemMessage();

            // Log
            ErrorLogFacade.logFile.FileName = Path.Combine(Application.StartupPath, "Error.log");
            AccessLog.FileName = Path.Combine(Application.StartupPath, "Access.log");
            AccessLog.Write(DateTime.Now.ToString("yyy-MM-dd ddd hh:mm:ss tt") + " Application started. Process Id: " + ProcessID + ", Machine: " + session.Machine_Name + ", machine's username: "******", version: " + session.Version);
            session.Id = SessionFacade.Save(session);
            SessionLogFacade.Log(Type.Priority_Information, "Application", Type.Log_Launch, "Application started");

            return(true);
        }
Пример #7
0
        private bool Save()
        {
            if (!IsValidated())
            {
                return(false);
            }
            Cursor = Cursors.WaitCursor;
            var m   = new UnitMeasure();
            var log = new SessionLog {
                Module = Type.Module_IC_Unit_Measure
            };

            m.Id             = Id;
            m.Code           = txtCode.Text.Trim();
            m.Default_Factor = double.Parse(txtFactor.Text);
            m.Description    = txtDesc.Text;
            m.Note           = txtNote.Text;
            if (m.Id == 0)
            {
                log.Priority = Type.Priority_Information;
                log.Type     = Type.Log_Insert;
            }
            else
            {
                log.Priority = Type.Priority_Caution;
                log.Type     = Type.Log_Update;
            }
            try
            {
                m.Id = UnitMeasureFacade.Save(m);
            }
            catch (Exception ex)
            {
                MessageFacade.Show(MessageFacade.error_save + "\r\n" + ex.Message, LabelFacade.sy_save, MessageBoxButtons.OK, MessageBoxIcon.Error);
                ErrorLogFacade.Log(ex);
            }
            if (dgvList.RowCount > 0)
            {
                RowIndex = dgvList.CurrentRow.Index;
            }
            RefreshGrid(m.Id);
            LockControls();
            Cursor      = Cursors.Default;
            log.Message = "Saved. Id=" + m.Id + ", Code=" + txtCode.Text;
            SessionLogFacade.Log(log);
            IsDirty = false;
            return(true);
        }
Пример #8
0
 private void btnCopy_Click(object sender, EventArgs e)
 {
     if (!Privilege.CanAccess(Type.Function_IC_Unit_Measure, Type.Privilege_New))
     {
         MessageFacade.Show(MessageFacade.privilege_no_access, LabelFacade.sy_copy, MessageBoxButtons.OK, MessageBoxIcon.Information);
         SessionLogFacade.Log(Type.Priority_Information, Type.Module_IC_Unit_Measure, Type.Log_NoAccess, "Copy: No access");
         return;
     }
     Id = 0;
     if (IsExpand)
     {
         picExpand_Click(sender, e);
     }
     txtCode.Focus();
     LockControls(false);
     SessionLogFacade.Log(Type.Priority_Information, Type.Module_IC_Unit_Measure, Type.Log_Copy, "Copy from Id=" + dgvList.Id + "Code=" + txtCode.Text);
     IsDirty = false;
 }
Пример #9
0
 private void frmUnitMeasureList_Load(object sender, EventArgs e)
 {
     Icon = Properties.Resources.Icon;
     try
     {
         dgvList.ShowLessColumns(true);
         SetSettings();
         SetLabels();
         SessionLogFacade.Log(Type.Priority_Information, Type.Module_IC_Unit_Measure, Type.Log_Open, "Opened");
         RefreshGrid();
         LoadData();
     }
     catch (Exception ex)
     {
         ErrorLogFacade.Log(ex, "Form_Load");
         MessageFacade.Show(MessageFacade.error_load_form + "\r\n" + ex.Message, LabelFacade.sy_unit_measure, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #10
0
        private void btnActive_Click(object sender, EventArgs e)
        {
            var Id = dgvList.Id;

            if (Id == 0)
            {
                return;
            }

            string status = btnActive.Text == LabelFacade.sy_button_inactive ? Type.RecordStatus_InActive : Type.RecordStatus_Active;
            // If referenced
            //todo: check if already used in ic_item

            //If locked
            var lInfo = UnitMeasureFacade.GetLock(Id);

            if (lInfo.Locked)
            {
                string msg = string.Format(MessageFacade.lock_currently, lInfo.Lock_By, lInfo.Lock_At);
                if (!Privilege.CanAccess(Type.Function_IC_Unit_Measure, "O"))
                {
                    MessageFacade.Show(msg, MessageFacade.active_inactive, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                if (MessageFacade.Show(msg + "\r\n" + MessageFacade.proceed_confirmation, MessageFacade.active_inactive, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }
            try
            {
                UnitMeasureFacade.SetStatus(Id, status);
            }
            catch (Exception ex)
            {
                MessageFacade.Show(MessageFacade.error_active_inactive + ex.Message, MessageFacade.active_inactive, MessageBoxButtons.OK, MessageBoxIcon.Error);
                ErrorLogFacade.Log(ex);
            }
            RefreshGrid();
            SessionLogFacade.Log(Type.Priority_Caution, Type.Module_IC_Unit_Measure, status == Type.RecordStatus_InActive ? Type.Log_Inactive : Type.Log_Active, "Id=" + dgvList.Id + ", Code=" + txtCode.Text);
        }
Пример #11
0
        private void LoadData()
        {
            var Id = dgvList.Id;

            if (Id != 0)
            {
                try
                {
                    var m = AccountFacade.Select(Id);
                    txtCode.Text = m.Code;
                    txtDesc.Text = m.Description;
                    cboNormalBalance.SelectedIndex = (m.Type != "L" ? 0 : 1);
                    txtStructureCode.Text          = m.Address;
                    txtStructureCodeDesc.Text      = m.Name;
                    txtGroup.Text = m.Phone;
                    txtFax.Text   = m.Fax;
                    txtEmail.Text = m.Email;
                    txtNote.Text  = m.Note;
                    SetStatus(m.Status);
                    LockControls();
                    IsDirty = false;
                    SessionLogFacade.Log(Type.Priority_Information, Type.Module_IC_Location, Type.Log_View, "View. Id=" + m.Id + ", Code=" + m.Code);
                }
                catch (Exception ex)
                {
                    MessageFacade.Show(MessageFacade.error_load_record + "\r\n" + ex.Message, LabelFacade.sy_location, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SYS.ErrorLogFacade.Log(ex);
                }
            }
            else    // when delete all => disable buttons and clear all controls
            {
                if (dgvList.RowCount == 0)
                {
                    btnUnlock.Enabled = false;
                    ClearAllBoxes();
                }
            }
        }
Пример #12
0
        private void btnUnlock_Click(object sender, EventArgs e)
        {
            if (!Privilege.CanAccess(Type.Function_IC_Unit_Measure, Type.Privilege_Update))
            {
                MessageFacade.Show(MessageFacade.privilege_no_access, LabelFacade.sy_button_unlock, MessageBoxButtons.OK, MessageBoxIcon.Information);
                SessionLogFacade.Log(Type.Priority_Information, Type.Module_IC_Unit_Measure, Type.Log_NoAccess, "Copy: No access");
                return;
            }
            if (IsExpand)
            {
                picExpand_Click(sender, e);
            }
            Id = dgvList.Id;
            // Cancel
            if (btnUnlock.Text == LabelFacade.sy_button_cancel)
            {
                if (IsDirty)
                {
                    var result = MessageFacade.Show(MessageFacade.save_confirmation, LabelFacade.sy_button_cancel, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (result == System.Windows.Forms.DialogResult.Yes) // Save then close
                    {
                        btnSave_Click(null, null);
                    }
                    else if (result == System.Windows.Forms.DialogResult.No)
                    {
                        LoadData(); // Load original back if changes (dirty)
                    }
                    else if (result == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return;
                    }
                }
                LockControls(true);
                dgvList.Focus();
                try
                {
                    UnitMeasureFacade.ReleaseLock(dgvList.Id);
                }
                catch (Exception ex)
                {
                    MessageFacade.Show(MessageFacade.error_unlock + "\r\n" + ex.Message, LabelFacade.sy_unlock, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ErrorLogFacade.Log(ex);
                    return;
                }
                if (dgvList.CurrentRow != null && !dgvList.CurrentRow.Selected)
                {
                    dgvList.CurrentRow.Selected = true;
                }
                SessionLogFacade.Log(Type.Priority_Information, Type.Module_IC_Unit_Measure, Type.Log_Unlock, "Unlock cancel. Id=" + dgvList.Id + ", Code=" + txtCode.Text);
                btnUnlock.ToolTipText = "Unlock (Ctrl+L)";
                IsDirty = false;
                return;
            }
            // Unlock
            if (Id == 0)
            {
                return;
            }
            try
            {
                var lInfo = UnitMeasureFacade.GetLock(Id);

                if (lInfo.Locked) // Check if record is locked
                {
                    string msg = string.Format(MessageFacade.lock_currently, lInfo.Lock_By, lInfo.Lock_At);
                    if (!Privilege.CanAccess(Type.Function_IC_Unit_Measure, "O"))
                    {
                        MessageFacade.Show(msg, LabelFacade.sy_unlock, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    else
                    if (MessageFacade.Show(msg + "\r\n" + MessageFacade.lock_override, LabelFacade.sy_unlock, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
                    {
                        SessionLogFacade.Log(Type.Priority_Caution, Type.Module_IC_Unit_Measure, Type.Log_Lock, "Override lock. Id=" + dgvList.Id + ", Code=" + txtCode.Text);
                    }
                    else
                    {
                        return;
                    }
                }
                txtDesc.SelectionStart = txtDesc.Text.Length;
                txtDesc.Focus();
                LockControls(false);
            }
            catch (Exception ex)
            {
                MessageFacade.Show(MessageFacade.error_unlock + "\r\n" + ex.Message, LabelFacade.sy_unlock, MessageBoxButtons.OK, MessageBoxIcon.Error);
                ErrorLogFacade.Log(ex);
                return;
            }
            try
            {
                UnitMeasureFacade.Lock(dgvList.Id, txtCode.Text);
            }
            catch (Exception ex)
            {
                MessageFacade.Show(MessageFacade.error_lock + "\r\n" + ex.Message, LabelFacade.sy_lock, MessageBoxButtons.OK, MessageBoxIcon.Error);
                ErrorLogFacade.Log(ex);
                return;
            }
            SessionLogFacade.Log(Type.Priority_Information, Type.Module_IC_Unit_Measure, Type.Log_Lock, "Locked. Id=" + dgvList.Id + ", Code=" + txtCode.Text);
            btnUnlock.ToolTipText = "Cancel (Esc or Ctrl+L)";
        }