Ejemplo n.º 1
0
        private bool IsValidated()
        {
            var     sMsg   = new StringBuilder();
            Control cFocus = null;
            string  Code   = txtCode.Text.Trim();

            if (Code.Length == 0)
            {
                sMsg.AppendLine(LabelFacade.sy_msg_prefix + MessageFacade.code_not_empty);
                cFocus = txtCode;
            }
            else if (CategoryFacade.Exists(Code, Id))
            {
                sMsg.AppendLine(LabelFacade.sy_msg_prefix + MessageFacade.code_already_exists);
                cFocus = txtCode;
            }
            if (sMsg.Length > 0)
            {
                MessageFacade.Show(this, ref fMsg, sMsg.ToString(), LabelFacade.sy_save);
                //fMsg.Show(sMsg.ToString(), LabelFacade.sy_save, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                cFocus.Focus();
                return(false);
            }
            return(true);
        }
        public async Task ReceivedMessages_Success()
        {
            var mockManager    = new FacadeMockManager();
            var unitOfWorkMock = FacadeMockManager.ConfigureUowMock().Object;
            var userService    = CreateUserService(mockManager);
            var messageService = CreateMessagesService(mockManager);
            var facade         = new MessageFacade(unitOfWorkMock, messageService, userService);
            var ids            = CreateSampleUsers(userService);
            var numMessages    = 10;
            var msgText        = "Hello World";

            for (int i = 0; i < numMessages; i++)
            {
                facade.SendMessage(new UserDto {
                    Id = ids.Item1
                }, new UserDto {
                    Id = ids.Item2
                }, msgText);
            }
            var msgs = await facade.ReceivedMessages(new UserDto { Id = ids.Item1 });

            Assert.AreEqual(msgs.Count, 10);
            msgs.ForEach(m =>
            {
                Assert.AreEqual(m.UserSenderId, ids.Item1);
                Assert.AreEqual(m.UserReceiverId, ids.Item2);
                Assert.AreEqual(m.Text, msgText);
            });
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
0
        private bool IsValidated()
        {
            var     sMsg   = new StringBuilder();
            Control cFocus = null;
            string  Code   = txtCode.Text.Trim();

            if (Code.Length == 0)
            {
                sMsg.AppendLine(LabelFacade.sy_msg_prefix + MessageFacade.code_not_empty);
                cFocus = txtCode;
            }
            else if (UnitMeasureFacade.Exists(Code, Id))
            {
                sMsg.AppendLine(LabelFacade.sy_msg_prefix + MessageFacade.code_already_exists);
                cFocus = txtCode;
            }
            if (!Util.IsDecimal(txtFactor.Text)) // Factor
            {
                sMsg.AppendLine(LabelFacade.sy_msg_prefix + MessageFacade.location_factor_not_number);
                cFocus = txtFactor;
            }
            if (sMsg.Length > 0)
            {
                MessageFacade.Show(this, ref fMsg, sMsg.ToString(), LabelFacade.sy_save);
                cFocus.Focus();
                return(false);
            }
            return(true);
        }
Ejemplo n.º 5
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();
                }
            }
        }
Ejemplo n.º 6
0
        public void Execute(object parameter)
        {
            string error;
            var    messageThread = ParentModel.MessageThread;

            MessageFacade.SendMessage(ParentModel.Text, ref messageThread, out error);
            ContactFacade.ContactPage.RecentConversationsListView.SelectedIndex = 0;
            ParentModel.Text = string.Empty;
            MessageFacade.ChatPage.ClearTextBox();
        }
Ejemplo n.º 7
0
 private void RefreshGrid(long seq = 0)
 {
     Cursor = Cursors.WaitCursor;
     //IsIgnore = true;
     if (dgvList.SelectedRows.Count > 0)
     {
         RowIndex = dgvList.SelectedRows[0].Index;
     }
     try
     {
         dgvList.DataSource = UnitMeasureFacade.GetDataTable(txtFind.Text, GetStatus());
     }
     catch (Exception ex)
     {
         Cursor = Cursors.Default;
         MessageFacade.Show(MessageFacade.error_retrieve_data + "\r\n" + ex.Message, LabelFacade.sy_unit_measure, MessageBoxButtons.OK, MessageBoxIcon.Error);
         ErrorLogFacade.Log(ex);
         return;
     }
     if (dgvList.RowCount > 0)
     {
         if (seq == 0)
         {
             if (RowIndex >= dgvList.RowCount)
             {
                 RowIndex = dgvList.RowCount - 1;
             }
             dgvList.CurrentCell = dgvList[1, RowIndex];
         }
         else
         {
             foreach (DataGridViewRow row in dgvList.Rows)
             {
                 if ((long)row.Cells[0].Value == seq)
                 {
                     Id = (int)seq;
                     dgvList.CurrentCell = dgvList[1, row.Index];
                     break;
                 }
             }
         }
     }
     else
     {
         btnCopy.Enabled   = false;
         btnUnlock.Enabled = false;
         btnActive.Enabled = false;
         btnDelete.Enabled = false;
         ClearAllBoxes();
     }
     IsIgnore = false;
     //LoadData();
     Cursor = Cursors.Default;
 }
Ejemplo n.º 8
0
 private void txtCode_Leave(object sender, EventArgs e)
 {
     // Check if entered code already exists
     if (txtCode.ReadOnly)
     {
         return;
     }
     if (UnitMeasureFacade.Exists(txtCode.Text.Trim()))
     {
         MessageFacade.Show(this, ref fMsg, LabelFacade.sy_msg_prefix + MessageFacade.code_already_exists, LabelFacade.sy_unit_measure);
     }
 }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
     }
 }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        public static bool Exists(string Code, long Id = 0)
        {
            var sql     = SqlFacade.SqlExists(TableName, "id <> :id and status <> :status and code = :code");
            var bExists = false;

            try
            {
                bExists = SqlFacade.Connection.ExecuteScalar <bool>(sql, new { Id, Status = Type.RecordStatus_Deleted, Code });
            }
            catch (Exception ex)
            {
                MessageFacade.Show(MessageFacade.error_query + "\r\n" + ex.Message, LabelFacade.sy_location, MessageBoxButtons.OK, MessageBoxIcon.Error);
                ErrorLogFacade.Log(ex, "Exists");
            }
            return(bExists);
        }
Ejemplo n.º 13
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;
 }
Ejemplo n.º 14
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);
     }
 }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        private bool IsValidated()
        {
            var     sMsg   = new StringBuilder();
            Control cFocus = null;
            string  Code   = txtCode.Text.Trim();

            if (Code.Length == 0)
            {
                sMsg.AppendLine(LabelFacade.sy_msg_prefix + MessageFacade.code_not_empty);
                cFocus = txtCode;
            }
            else if (AccountFacade.Exists(Code, Id))
            {
                sMsg.AppendLine(LabelFacade.sy_msg_prefix + MessageFacade.code_already_exists);
                cFocus = txtCode;
            }
            if (cboNormalBalance.SelectedIndex == -1)
            {
                sMsg.AppendLine(LabelFacade.sy_msg_prefix + MessageFacade.location_type_not_empty);
                if (cFocus == null)
                {
                    cFocus = cboNormalBalance;
                }
            }
            if (txtEmail.Text.Length > 0 && !Util.IsEmailValid(txtEmail.Text))
            {
                sMsg.AppendLine(LabelFacade.sy_msg_prefix + MessageFacade.email_not_valid);
                if (cFocus == null)
                {
                    cFocus = txtEmail;
                }
            }
            if (sMsg.Length > 0)
            {
                MessageFacade.Show(this, ref fMsg, sMsg.ToString(), LabelFacade.sy_save);
                //fMsg.Show(sMsg.ToString(), LabelFacade.sy_save, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                cFocus.Focus();
                return(false);
            }
            return(true);
        }
        public async Task SendMessage_Success()
        {
            var mockManager    = new FacadeMockManager();
            var unitOfWorkMock = FacadeMockManager.ConfigureUowMock().Object;
            var userService    = CreateUserService(mockManager);
            var messageService = CreateMessagesService(mockManager);
            var facade         = new MessageFacade(unitOfWorkMock, messageService, userService);
            var ids            = CreateSampleUsers(userService);
            var msgText        = "Hello World";
            var guid           = facade.SendMessage(new UserDto {
                Id = ids.Item1
            }, new UserDto {
                Id = ids.Item2
            }, msgText);
            var dto = await messageService.GetAsync(guid);

            Assert.IsFalse(dto.Seen);
            Assert.AreEqual(dto.UserSenderId, ids.Item1);
            Assert.AreEqual(dto.UserReceiverId, ids.Item2);
            Assert.AreEqual(dto.Text, msgText);
        }
Ejemplo n.º 18
0
        private void frmUnitMeasureList_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (IsDirty)
            {
                switch (MessageFacade.Show(MessageFacade.save_confirmation, LabelFacade.sy_close, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                {
                case System.Windows.Forms.DialogResult.Yes:     // Save then close
                    if (!Save())
                    {
                        e.Cancel = true;
                    }
                    break;

                case System.Windows.Forms.DialogResult.Cancel:
                    e.Cancel = true;
                    break;
                }
            }
            if (e.Cancel)
            {
                return;
            }
            IsDirty = false;
            if (btnUnlock.Text == "Cance&l")
            {
                btnUnlock_Click(null, null);
            }

            // Set config values
            if (!IsExpand)
            {
                ConfigFacade.ic_unit_measure_splitter_distance = splitContainer1.SplitterDistance;
            }
            ConfigFacade.ic_unit_measure_location     = Location;
            ConfigFacade.ic_unit_measure_window_state = (int)WindowState;
            if (WindowState == FormWindowState.Normal)
            {
                ConfigFacade.ic_unit_measure_size = Size;
            }
        }
Ejemplo n.º 19
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();
                }
            }
        }
Ejemplo n.º 20
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)";
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Handle the facade message
        /// </summary>
        /// <param name="message">Message sent from client</param>
        /// <param name="server">Instance of the socket server</param>
        /// <param name="client">Socket that sent the message (for return messages)</param>
        internal static void HandleFacadeMessage(Newtonsoft.Json.Linq.JObject message, SocketServer server, AsyncSocket client)
        {
            String    action        = (string)message["FacadeAction"];
            GUIWindow currentPlugin = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow);

            if (action.Equals("get"))
            {
                MessageFacade returnMessage = new MessageFacade();
                if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome))
                {
                    GUIMenuControl    menu  = (GUIMenuControl)currentPlugin.GetControl(50);
                    List <FacadeItem> items = MpFacadeHelper.GetHomeItems(menu);
                    returnMessage.FacadeItems = items;
                    returnMessage.ViewType    = "Home";
                }
                else
                {
                    GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50);
                    if (facade != null)
                    {
                        List <FacadeItem> items = MpFacadeHelper.GetFacadeItems(currentPlugin.GetID, 50);
                        returnMessage.ViewType    = facade.CurrentLayout.ToString();
                        returnMessage.FacadeItems = items;
                    }
                }

                returnMessage.WindowId = currentPlugin.GetID;
                server.SendMessageToClient(returnMessage, client);
            }
            else if (action.Equals("setselected"))
            {
                if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome))
                {
                }
                else
                {
                    GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50);
                    int selected            = (int)message["SelectedIndex"];
                    facade.SelectedListItemIndex = selected;
                }
            }
            else if (action.Equals("getselected"))
            {
                if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome))
                {
                    //TODO: find a way to retrieve the currently selected home button
                }
                else
                {
                    GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50);
                    int selected            = facade.SelectedListItemIndex;
                }
            }
            else if (action.Equals("getcount"))
            {
                if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome))
                {
                    GUIMenuControl menu  = (GUIMenuControl)currentPlugin.GetControl(50);
                    int            count = menu.ButtonInfos.Count;
                }
                else
                {
                    GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50);
                    int count = facade.Count;
                }
            }
            else if (action.Equals("select"))
            {
                int selected = (int)message["SelectedIndex"];
                if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome))
                {
                    GUIMenuControl menu = (GUIMenuControl)currentPlugin.GetControl(50);
                    MenuButtonInfo info = menu.ButtonInfos[selected];
                    GUIMessage     msg  = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, info.PluginID, 0, null);
                    GUIWindowManager.SendThreadMessage(msg);
                }
                else
                {
                    GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50);
                    //TODO: is there a better way to select a list item

                    facade.SelectedListItemIndex = selected;
                    new Communication().SendCommand("ok");
                }
            }
            else if (action.Equals("context"))
            {
                int selected = (int)message["SelectedIndex"];
                if (currentPlugin.GetType() == typeof(MediaPortal.GUI.Home.GUIHome))
                {
                    GUIMenuControl menu = (GUIMenuControl)currentPlugin.GetControl(50);
                    MenuButtonInfo info = menu.ButtonInfos[selected];
                    GUIMessage     msg  = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, info.PluginID, 0, null);
                    GUIWindowManager.SendThreadMessage(msg);
                }
                else
                {
                    GUIFacadeControl facade = (GUIFacadeControl)currentPlugin.GetControl(50);
                    //TODO: is there a better way to select a list item

                    facade.SelectedListItemIndex = selected;
                    new Communication().SendCommand("info");
                }
            }
        }
Ejemplo n.º 22
0
        public static int ExportToCSV(string sql)
        {
            //sql = "COPY (" + sql + ") TO '" + path + "' DELIMITER '" + delimiter + "' CSV HEADER ENCODING 'UTF8';";
            //Connection.ExecuteNonQuery(sql);
            var result = 0;

            var sfd = new SaveFileDialog
            {
                CheckPathExists = true,
                OverwritePrompt = true,
                Filter          = "CSV File (*.csv)|*.csv|All Files (*.*)|*.*",
                Title           = "Export to CSV"
            };

            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return(result);
            }
            var path     = sfd.FileName;
            var fileName = Path.GetFileName(path);

            var fNotification = new frmNotification(string.Format(MessageFacade.export_exporting, fileName));

            fNotification.Show();
            Application.DoEvents();

            StringBuilder sb = new StringBuilder();

            try
            {
                var dr = GetDataReader(sql);

                var sLine = "";
                if (!dr.HasRows)
                {
                    return(1);                          // No record
                }
                for (int i = 0; i < dr.FieldCount; i++) // Column headers
                {
                    sLine += dr.GetName(i);
                    if (i < dr.FieldCount - 1)
                    {
                        sLine += ConfigFacade.sy_export_delimiter;
                    }
                }
                sb.AppendLine(sLine);

                while (dr.Read())   // Rows
                {
                    sLine = "";
                    for (int i = 0; i < dr.FieldCount; i++)
                    {
                        sLine += "\"" + dr[i].ToString() + "\"";
                        if (i < dr.FieldCount - 1)
                        {
                            sLine += ConfigFacade.sy_export_delimiter;
                        }
                    }
                    sb.AppendLine(sLine);
                }
                dr.Close();
            }
            catch (Exception ex)
            {
                MessageFacade.Show(MessageFacade.error_export + "\r\n" + ex.Message, LabelFacade.sy_export, MessageBoxButtons.OK, MessageBoxIcon.Error);
                ErrorLogFacade.Log(ex);
                return(-1);
            }
            while (Util.IsFileLocked(path))   // Check if file is being used
            {
                if (MessageFacade.Show(string.Format(MessageFacade.file_being_used_try_again, fileName), LabelFacade.sy_export, MessageBoxButtons.RetryCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                {
                    fNotification.Close();
                    return(0);
                }
                continue;
            }
            using (var sw = new StreamWriter(path, false, Encoding.UTF8))   // Write to file
            {
                sw.Write(sb);
            }
            fNotification.ShowMsg(string.Format(MessageFacade.export_opening, fileName));
            if (ConfigFacade.sy_export_open_file_after)
            {
                System.Diagnostics.Process.Start(path);                                           // Open file
            }
            fNotification.Close();
            return(result);
        }