Esempio n. 1
0
        private void InvalidCPO_Load(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".InvalidCPO_Load()";

            const string STARTDATE_COL   = "StartDate";
            const string DUEDATE_COL     = "DueDate";
            const string QUANTITY_COL    = "Quantity";
            const string ERRORCODE_COL   = "ErrorCode";
            const string ERRORREASON_COL = "ErrorReason";

            try
            {
                Security objSecurity = new Security();
                this.Name = THIS;
                if (objSecurity.SetRightForUserOnForm(this, SystemProperty.UserName) == 0)
                {
                    this.Close();
                    return;
                }

                if (m_dtbInvalidWOLineAndCPO != null)
                {
                    m_dtbInvalidWOLineAndCPO.Columns.Add(ERRORREASON_COL, typeof(string));
                    foreach (DataRow drow in m_dtbInvalidWOLineAndCPO.Rows)
                    {
                        drow[ERRORREASON_COL] = ErrorMessageBO.GetErrorMessage(Convert.ToInt32(drow[ERRORCODE_COL]));
                    }
                    DataTable dtbLayout = FormControlComponents.StoreGridLayout(tgridOverCapacityWC);
                    tgridOverCapacityWC.DataSource = m_dtbInvalidWOLineAndCPO;
                    FormControlComponents.RestoreGridLayout(tgridOverCapacityWC, dtbLayout);
                    tgridOverCapacityWC.Columns[STARTDATE_COL].NumberFormat = Constants.DATETIME_FORMAT_HOUR;
                    tgridOverCapacityWC.Columns[DUEDATE_COL].NumberFormat   = Constants.DATETIME_FORMAT_HOUR;
                    tgridOverCapacityWC.Columns[QUANTITY_COL].NumberFormat  = Constants.DECIMAL_NUMBERFORMAT;
                }
            }
            catch (PCSException ex)
            {
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Show PCSMessage with parameters
        /// </summary>
        /// <param name="pintMessageCode"></param>
        /// <param name="pobjIcon"></param>
        /// <param name="pstrParams"></param>
        /// <returns></returns>
        /// <author>TuanDM 2005 - 14 - 10</author>
        public static DialogResult Show(int pintMessageCode, MessageBoxIcon pobjIcon, string[] pstrParams)
        {
            const string OLD_CHAR = "@";

            try
            {
                string strMessage = ErrorMessageBO.GetErrorMessage(pintMessageCode);
                for (int i = 0; i < pstrParams.Length; i++)
                {
                    int intIndex = strMessage.IndexOf(OLD_CHAR);
                    strMessage = strMessage.Remove(intIndex, OLD_CHAR.Length);
                    strMessage = strMessage.Insert(intIndex, pstrParams[i]);
                }
                return(MessageBox.Show(strMessage, Constants.APPLICATION_NAME, MessageBoxButtons.OK, pobjIcon));
            }
            catch
            {
                // log message.
                try
                {
                    Logger.LogMessage(MESSAGE_SYSTEM_ERROR + SPACE + pintMessageCode, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                }

                return(MessageBox.Show(MESSAGE_SYSTEM_ERROR, Constants.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error));
            }
        }
Esempio n. 3
0
        public static DialogResult Show(int pintMessageCode, MessageBoxIcon pobjMessageBoxIcon)
        {
            try
            {
                string strMessage = ErrorMessageBO.GetErrorMessage(pintMessageCode);
                return(MessageBox.Show(strMessage, Constants.APPLICATION_NAME, MessageBoxButtons.OK, pobjMessageBoxIcon));
            }
            catch
            {
                // log message.
                try
                {
                    Logger.LogMessage(MESSAGE_SYSTEM_ERROR + SPACE + pintMessageCode, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                }

                return(MessageBox.Show(MESSAGE_SYSTEM_ERROR, Constants.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error));
            }
        }
Esempio n. 4
0
        public static DialogResult Show(int pintBaseCodeMessage, int pintExtendCodeMessage)
        {
            const string OR = " OR ";

            try
            {
                string strBaseCodeMessage   = ErrorMessageBO.GetErrorMessage(pintBaseCodeMessage);
                string strExtendCodeMessage = ErrorMessageBO.GetErrorMessage(pintExtendCodeMessage);
                string strMessage           = strBaseCodeMessage.Replace(ICON_REPLACE, strExtendCodeMessage);
                return(MessageBox.Show(strMessage, Constants.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error));
            }
            catch
            {
                // log message.
                try
                {
                    Logger.LogMessage(MESSAGE_SYSTEM_ERROR + SPACE + pintBaseCodeMessage, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                }
                return(MessageBox.Show(MESSAGE_SYSTEM_ERROR, Constants.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Set all right for a user on form
        /// </summary>
        /// <Inputs>
        /// pForm : the form needs to set
        /// pstrUserName : contains UserName
        /// </Inputs>
        /// <Return>
        /// void
        /// </Return>
        /// <Authors>
        /// TuanDm
        /// </Authors>
        /// <History>
        ///	Friday - January 13 - 2005
        /// </History>
        public int SetRightForUserOnForm(Form pForm, string pstrUserName)
        {
            // SetButtonForRight_View(pForm);
            if (!pForm.Modal)
            {
                bool blnIsFound = false;

                #region Search form which assign security

                foreach (object t in SystemProperty.ArrayForms)
                {
                    try
                    {
                        var objInforForm = (FormInfo)t;
                        if (objInforForm.mForm == pForm)
                        {
                            blnIsFound = true;
                            break;
                        }
                    }
                    catch { }
                }

                #endregion

                if (!blnIsFound)
                {
                    #region // if not found add to Array form to manage
                    var list = (from obj in SystemProperty.TableMenuEntry
                                where (obj.FormLoad == pForm.GetType().FullName&& obj.IsUserCreated == 0)
                                orderby obj.Menu_EntryID ascending
                                select obj).ToList();
                    FormInfo infoForm = list.Count > 0 ? new FormInfo(pForm, list[0].Prefix, list[0].TransFormat, list[0].TableName, list[0].TransNoFieldName, SystemProperty.UserName) : new FormInfo(pForm, string.Empty, string.Empty, string.Empty, string.Empty, SystemProperty.UserName);
                    SystemProperty.ArrayForms.Add(infoForm);

                    #endregion
                }
            }

            var     boCommon          = new CommonBO();
            DataSet dstSecurity       = boCommon.GetSecurityInfo(pstrUserName, pForm.GetType().FullName);
            int     intFullPermission = int.Parse(dstSecurity.Tables[Sys_RightTable.TABLE_NAME].Rows[0][0].ToString());

            #region // HACK: Added by Tuan TQ update code to manage super admin user

            if (pstrUserName.Equals(Constants.SUPER_ADMIN_USER))
            {
                // HACK: SONHT HardCode
                DialogResult result = PCSMessageBox.Show(MessageCreateDataVisibility, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (result == DialogResult.Yes)
                {
                    var frmGroupControl = new GroupControls(pForm);
                    frmGroupControl.Show();
                    if (pForm.Modal)
                    {
                        pForm.Show();
                    }
                }
                intFullPermission = FullPermission;// (2 exp 5) -1
            }

            #endregion

            #region // if has no permission
            if (intFullPermission == 0)
            {
                int intCountExisted = int.Parse(dstSecurity.Tables[Sys_Menu_EntryTable.TABLE_NAME].Rows[0][0].ToString());
                if (intCountExisted > 0)
                {
                    return(intFullPermission);
                }
                intFullPermission = FullPermission;// (2 exp 5) -1
            }

            #endregion

            // Set visible control
            DataTable dtbTable = dstSecurity.Tables[Sys_VisibilityGroup_RoleTable.TABLE_NAME];
            // Set other property for form
            pForm.StartPosition = FormStartPosition.CenterScreen;
            pForm.KeyPreview    = true;

            Control objControl = pForm;
            #region // Scan control on form to set default property
            while (true)
            {
                #region // Get next control
                objControl = pForm.GetNextControl(objControl, true);
                if (objControl == null)
                {
                    break;
                }

                #endregion

                #region // Set OnEnter and OnLeave
                if (objControl.GetType().Equals(typeof(TextBox)) ||
                    objControl.GetType().Equals(typeof(ComboBox)) ||
                    objControl.GetType().Equals(typeof(C1Combo)) ||
                    objControl.GetType().Equals(typeof(C1DateEdit)) ||
                    objControl.GetType().Equals(typeof(C1TextBox)) ||
                    objControl.GetType().Equals(typeof(C1NumericEdit)) ||
                    objControl.GetType().Equals(typeof(NumericUpDown)))
                {
                    objControl.Enter += FormControlComponents.OnEnterControl;
                    objControl.Leave += FormControlComponents.OnLeaveControl;
                }

                if (objControl.GetType().Equals(typeof(Button)))
                {
                    if (objControl.Name == "btnHelp" || objControl.Name == "HelpButton")
                    {
                        objControl.Click += FormControlComponents.OnHelpClick;
                    }
                }

                #endregion

                if (objControl.GetType().Equals(typeof(TextBox)))
                {
                    #region // If it's TextBox
                    var txtBox = (TextBox)objControl;
                    txtBox.TextAlign = HorizontalAlignment.Left;
                    //HACK : TUANDM 18 - 10 - 2005
                    txtBox.Text = txtBox.Text.Trim();
                    if (txtBox.Text != string.Empty)
                    {
                        var btnSearch = (Button)FindButtonControlByName(pForm, txtBox.Text);
                        if (btnSearch != null)
                        {
                            txtBox.Validating += FormControlComponents.ControlValidating;
                            txtBox.Text        = string.Empty;
                        }
                    }

                    #endregion

                    //END: TUANDM 18 - 10 - 2005
                }
                else if (objControl.GetType().Equals(typeof(C1TextBox)))
                {
                    #region C1TextBox
                    var txtC1Text = (C1TextBox)objControl;
                    txtC1Text.TextAlign = HorizontalAlignment.Left;
                    //HACK : TUANDM 18 - 10 - 2005
                    txtC1Text.Value = txtC1Text.Value.ToString().Trim();
                    if (txtC1Text.Value.ToString() != string.Empty)
                    {
                        var btnSearch = (Button)FindButtonControlByName(pForm, txtC1Text.Value.ToString());
                        if (btnSearch != null)
                        {
                            txtC1Text.Validating += FormControlComponents.ControlValidating;
                            txtC1Text.Value       = string.Empty;
                        }
                    }

                    #endregion
                }
                else if (objControl.GetType().Equals(typeof(C1DateEdit)))
                {
                    var dtmC1Date = (C1DateEdit)objControl;
                    dtmC1Date.Validated    += FormControlComponents.C1DateEdit_Validated;
                    dtmC1Date.TextAlign     = HorizontalAlignment.Center;
                    dtmC1Date.AcceptsEscape = false;

                    #region // Set default dd-MM-yyyy format
                    if (dtmC1Date.CustomFormat.Trim().Length == 0)
                    {
                        dtmC1Date.CustomFormat = Constants.DATETIME_FORMAT;
                        dtmC1Date.FormatType   = FormatTypeEnum.CustomFormat;
                    }
                    string strMsg = ErrorMessageBO.GetErrorMessage(ErrorCode.MESSAGE_C1NUMBER_INPUT_VALUE);
                    strMsg = strMsg.Replace(Chara, string.Empty);
                    string strSecondMsg = ErrorMessageBO.GetErrorMessage(ErrorCode.MESSAGE_C1NUMBER_OR_MSG);
                    // if it has no Intervals
                    if (dtmC1Date.PostValidation.Intervals.Count == 0)
                    {
                        continue;
                    }
                    strMsg = dtmC1Date.PostValidation.Intervals.Cast <ValueInterval>().Aggregate(strMsg, (current, vlInterval) => current + (Constants.OPEN_SBRACKET + vlInterval.MinValue + Constants.COMMA + Constants.WHITE_SPACE + vlInterval.MaxValue + Constants.CLOSE_SBRACKET + Constants.WHITE_SPACE + strSecondMsg + Constants.WHITE_SPACE));
                    strMsg = strMsg.Substring(0, strMsg.Length - strSecondMsg.Length - 1);
                    dtmC1Date.ErrorInfo.ShowErrorMessage    = true;
                    dtmC1Date.ErrorInfo.ErrorMessageCaption = Constants.APPLICATION_NAME;
                    dtmC1Date.ErrorInfo.ErrorMessage        = strMsg;
                    dtmC1Date.ErrorInfo.CanLoseFocus        = false;

                    #endregion
                }
                else if (objControl.GetType().Equals(typeof(C1NumericEdit)))
                {
                    #region // if it is C1NumericEdit
                    var dtmC1Num = (C1NumericEdit)objControl;
                    dtmC1Num.TextAlign     = HorizontalAlignment.Right;
                    dtmC1Num.AcceptsEscape = false;
                    // Set default number format
                    if (dtmC1Num.CustomFormat.Trim().Length == 0)
                    {
                        dtmC1Num.CustomFormat = Constants.DECIMAL_NUMBERFORMAT;
                        dtmC1Num.FormatType   = FormatTypeEnum.CustomFormat;
                    }
                    string strMsg = ErrorMessageBO.GetErrorMessage(ErrorCode.MESSAGE_C1NUMBER_INPUT_VALUE);
                    strMsg = strMsg.Replace(Chara, string.Empty);
                    string strSecondMsg = ErrorMessageBO.GetErrorMessage(ErrorCode.MESSAGE_C1NUMBER_OR_MSG);
                    // if it has no Intervals
                    if (dtmC1Num.PostValidation.Intervals.Count == 0)
                    {
                        continue;
                    }
                    strMsg = dtmC1Num.PostValidation.Intervals.Cast <ValueInterval>().Aggregate(strMsg, (current, vlInterval) => current + (Constants.OPEN_SBRACKET + vlInterval.MinValue + Constants.COMMA + Constants.WHITE_SPACE + vlInterval.MaxValue + Constants.CLOSE_SBRACKET + Constants.WHITE_SPACE + strSecondMsg + Constants.WHITE_SPACE));
                    strMsg = strMsg.Substring(0, strMsg.Length - strSecondMsg.Length - 1);
                    dtmC1Num.ErrorInfo.ShowErrorMessage    = true;
                    dtmC1Num.ErrorInfo.ErrorMessageCaption = Constants.APPLICATION_NAME;
                    dtmC1Num.ErrorInfo.ErrorMessage        = strMsg;
                    dtmC1Num.ErrorInfo.CanLoseFocus        = false;

                    #endregion
                }

                else if (objControl.GetType().Equals(typeof(C1Combo)))
                {
                    #region // if it is C1Combo
                    var cboC1 = (C1Combo)objControl;
                    cboC1.DropDownWidth = Constants.DEFAULT_C1COMBO_DROPDOWNWIDTH;
                    cboC1.KeyDown      += FormControlComponents.C1Combo_KeyDown;
                    cboC1.ComboStyle    = ComboStyleEnum.DropdownList;
                    // Enable cboCCN control
                    if (cboC1.Name == Cboccn)
                    {
                        cboC1.Enabled         = true;
                        cboC1.EnabledChanged += EnabledChanged;
                    }

                    #endregion
                }
                else if (objControl.GetType().Equals(typeof(C1TrueDBGrid)))
                {
                    #region // if is C1TrueDBGrid control
                    var grid = (C1TrueDBGrid)objControl;
                    grid.RowHeight    = Constants.DEFAULT_ROW_HEIGHT;
                    grid.MarqueeStyle = MarqueeEnum.HighlightCell;
                    grid.HighLightRowStyle.BackColor = Color.FromArgb(Constants.BACKGROUND_COLOUR_R, Constants.BACKGROUND_COLOUR_G, Constants.BACKGROUND_COLOUR_B);
                    grid.HighLightRowStyle.ForeColor = Color.FromArgb(Constants.FORE_COLOUR_R, Constants.FORE_COLOUR_R, Constants.FORE_COLOUR_R);
                    grid.Style.VerticalAlignment     = AlignVertEnum.Center;
                    if (grid.Splits.Count > 0)
                    {
                        // Set default alignment
                        foreach (C1DisplayColumn c1Column in grid.Splits[0].DisplayColumns)
                        {
                            c1Column.HeadingStyle.HorizontalAlignment = AlignHorzEnum.Center;
                        }
                    }
                    // Not allow user change column order
                    grid.AllowColMove = false;
                    grid.Anchor       = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                    // Set Maximize and Resize
                    pForm.MaximizeBox     = true;
                    pForm.FormBorderStyle = FormBorderStyle.Sizable;

                    #endregion
                }
            }
            #endregion

            if (!pstrUserName.Equals(Constants.SUPER_ADMIN_USER))
            {
                #region // Scan data from datatable to set visible control
                if (dtbTable != null)
                {
                    foreach (DataRow drowData in dtbTable.Rows)
                    {
                        Control objCon = pForm.GetNextControl(pForm, true);
                        while (objCon != null)
                        {
                            // if is C1TrueDBGrid control
                            if (objCon.GetType().Equals(typeof(C1TrueDBGrid)))
                            {
                                var grid = (C1TrueDBGrid)objCon;
                                foreach (C1DisplayColumn objCol in grid.Splits[0].DisplayColumns)
                                {
                                    // do not process if col is invisible
                                    if (!objCol.Visible)
                                    {
                                        objCol.AllowSizing = objCol.Visible = false;
                                        continue;
                                    }
                                    if ((objCol.DataColumn.DataField == drowData[Sys_HiddenControlsTable.CONTROLNAME_FLD].ToString().Trim()) &&
                                        (drowData[Sys_VisibilityItemTable.TYPE_FLD].ToString() == VisibilityItemTypeEnum.ColumnTrueDBGrid.GetHashCode().ToString()))
                                    {
                                        objCol.AllowSizing = objCol.Visible = false;
                                    }
                                }
                            }
                            // If control is C1TabControl
                            else if (objCon.GetType().Equals(typeof(C1DockingTab)))
                            {
                                var c1DockingTab = (C1DockingTab)objCon;
                                for (int k = 0; k < c1DockingTab.TabCount; k++)
                                {
                                    if (c1DockingTab.TabPages[k].Name == drowData[Sys_HiddenControlsTable.CONTROLNAME_FLD].ToString().Trim())
                                    {
                                        c1DockingTab.TabPages[k].TabVisible = false;
                                    }
                                }
                            }
                            // set visible if it is normal control
                            else if (objCon.Name == drowData[Sys_HiddenControlsTable.CONTROLNAME_FLD].ToString().Trim())
                            {
                                objCon.Visible = false;
                            }
                            // Get next control
                            objCon = pForm.GetNextControl(objCon, true);
                        }
                    }
                }
                #endregion
            }

            // return full permission
            return(intFullPermission);
        }