Esempio n. 1
0
        public async static void LoadUserPermission(string function_id, TextEdit txtID, SimpleButton btnSaveClose, SimpleButton btnSaveInsert, bool isDuplicate = false)
        {
            iPOS.DRO.Systems.SYS_tblPermissionDRO permission = new iPOS.DRO.Systems.SYS_tblPermissionDRO();
            permission = await iPOS.BUS.Systems.SYS_tblPermissionBUS.GetPermissionItem(CommonEngine.userInfo.UserID, ConfigEngine.Language, function_id);

            if (permission.ResponseItem.IsError)
            {
                CommonEngine.ShowHTTPErrorMessage(permission.ResponseItem);
                btnSaveClose.Enabled = btnSaveInsert.Enabled = false;
                return;
            }
            if (permission.PermissionItem != null)
            {
                if (string.IsNullOrEmpty(txtID.Text) || isDuplicate)
                {
                    btnSaveClose.Enabled = btnSaveInsert.Enabled = permission.PermissionItem.AllowInsert;
                }
                else
                {
                    btnSaveClose.Enabled  = permission.PermissionItem.AllowUpdate;
                    btnSaveInsert.Enabled = permission.PermissionItem.AllowInsert & permission.PermissionItem.AllowUpdate;
                }
            }
            else
            {
                btnSaveClose.Enabled = btnSaveInsert.Enabled = false;
            }
        }
Esempio n. 2
0
        public static string SaveExportCustom(Excel.Workbook Book, string report_name, bool isXlsFormat = false)
        {
            object Missing = System.Reflection.Missing.Value;
            string str     = "";

            try
            {
                report_name = report_name.Remove(report_name.LastIndexOf('.'));

                SaveFileDialog sDialog = new SaveFileDialog();
                str                      = string.Format(@"{0}_{1}_{2}", report_name, DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"), DateTime.Now.Ticks);
                sDialog.Filter           = isXlsFormat ? "Microsoft Excel (*.xls)|*.xls" : "Microsoft Excel 2007 (*.xlsx)|*.xlsx";
                sDialog.Title            = LanguageEngine.GetMessageCaption("000007", ConfigEngine.Language);
                sDialog.InitialDirectory = Temp;
                sDialog.FileName         = str;
                if (sDialog.ShowDialog() == DialogResult.OK)
                {
                    str = sDialog.FileName;
                    Book.SaveAs(str, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Missing, Missing, Missing, Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Missing, Missing, Missing, Missing, Missing);
                    CommonEngine.ShowMessage(ConfigEngine.Language.Equals("vi") ? "Tải tập tin mẫu thành công!" : "Download template success!", MessageType.Success);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(str);
        }
Esempio n. 3
0
        private async Task <bool> CheckLogin()
        {
            if (string.IsNullOrEmpty(txtUsername.Text))
            {
                CommonEngine.ShowMessage(LanguageEngine.GetMessageCaption("000011", ConfigEngine.Language), MessageType.Error);
                txtUsername.Focus();
                return(false);
            }
            if (string.IsNullOrEmpty(txtPassword.Text))
            {
                CommonEngine.ShowMessage(LanguageEngine.GetMessageCaption("000011", ConfigEngine.Language), MessageType.Error);
                txtPassword.Focus();
                return(false);
            }
            try
            {
                SYS_tblUserDRO user = await UserBUS.CheckLogin(txtUsername.Text.Trim(), EncryptEngine.Encrypt(txtPassword.Text.Trim()), ConfigEngine.Language);

                if (CommonEngine.CheckValidResponseItem(user.ResponseItem))
                {
                    if (user.UserItem != null)
                    {
                        CommonEngine.userInfo = user.UserItem;
                        string temp = user.UserItem.Username.Substring(user.UserItem.Username.IndexOf("|") + 1);
                        user.UserItem.Username      = user.UserItem.Username.Replace("|" + temp, "");
                        CommonEngine.SystemDateTime = Convert.ToDateTime(temp);

                        if (user.UserItem.Locked)
                        {
                            CommonEngine.ShowMessage(LanguageEngine.GetMessageCaption("000010", ConfigEngine.Language).Replace("$UserName$", user.UserItem.Username), MessageType.Error);
                            txtUsername.Focus();
                            return(false);
                        }
                    }
                    else
                    {
                        CommonEngine.ShowMessage(LanguageEngine.GetMessageCaption("000009", ConfigEngine.Language), MessageType.Error);
                        txtUsername.Focus();
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                CommonEngine.ShowExceptionMessage(ex);
                txtUsername.Focus();
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            if (await CheckLogin())
            {
                string username = (chkRemember.Checked) ? EncryptEngine.Encrypt(txtUsername.Text.Trim()) : "";
                string password = (chkRemember.Checked) ? EncryptEngine.Encrypt(txtPassword.Text.Trim()) : "";
                IOEngine.Write("Initialize", "Username", username);
                IOEngine.Write("Initialize", "Password", password);

                ResponseItem result = await SYS_tblActionLogBUS.InsertUpdateLog(new SYS_tblActionLogDTO
                {
                    ID             = string.Empty,
                    ActionVN       = "Đăng Nhập",
                    ActionEN       = "Login",
                    ActionTime     = DateTime.Now,
                    FunctionID     = string.Empty,
                    FunctionNameVN = "Đăng Nhập",
                    FunctionNameEN = "Login",
                    DescriptionEN  = string.Format("Account '{0}' has logined to system at {1}.", txtUsername.Text, DateTime.Now),
                    DescriptionVN  = string.Format("Tài khoản '{0}' vừa đăng nhập vào hệ thống vào lúc {1}.", txtUsername.Text, DateTime.Now),
                    FullName       = CommonEngine.userInfo.FullName,
                    Activity       = "Insert",
                    UserID         = CommonEngine.userInfo.UserID,
                    LanguageID     = ConfigEngine.Language
                });

                if (result.IsError)
                {
                    CommonEngine.ShowHTTPErrorMessage(result);
                }
                else
                {
                    if (!string.IsNullOrEmpty(result.Message))
                    {
                        CommonEngine.ShowMessage(result.Message, 0);
                        return;
                    }
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
Esempio n. 5
0
        public async static void LoadUserPermission(string function_id, BarLargeButtonItem btnDelete, BarLargeButtonItem btnPrint, BarLargeButtonItem btnImport, BarLargeButtonItem btnExport)
        {
            iPOS.DRO.Systems.SYS_tblPermissionDRO permission = new iPOS.DRO.Systems.SYS_tblPermissionDRO();
            permission = await iPOS.BUS.Systems.SYS_tblPermissionBUS.GetPermissionItem(CommonEngine.userInfo.UserID, ConfigEngine.Language, function_id);

            if (permission.ResponseItem.IsError)
            {
                CommonEngine.ShowHTTPErrorMessage(permission.ResponseItem);
                btnDelete.Enabled = btnPrint.Enabled = btnImport.Enabled = btnExport.Enabled = false;
                return;
            }
            if (permission.PermissionItem != null)
            {
                btnDelete.Enabled = permission.PermissionItem.AllowDelete;
                btnPrint.Enabled  = permission.PermissionItem.AllowPrint;
                btnImport.Enabled = permission.PermissionItem.AllowImport;
                btnExport.Enabled = permission.PermissionItem.AllowExport;
            }
            else
            {
                btnDelete.Enabled = btnPrint.Enabled = btnImport.Enabled = btnExport.Enabled = false;
            }
        }
Esempio n. 6
0
        public async static void GetFileWithReportCaption(string username, string language_id, string template, string function_id, string module_id)
        {
            Excel.Application App         = null;
            Excel.Workbook    Book        = null;
            Excel.Worksheet   Sheet       = null;
            Excel.Range       Range       = null;
            object            Missing     = System.Reflection.Missing.Value;
            string            strFilePath = "";

            try
            {
                App   = new Excel.Application();
                Book  = App.Workbooks.Open(string.Format(@"{0}\{1}\{2}", Temp, module_id, template));
                Sheet = (Excel.Worksheet)Book.Worksheets[1];
                Range = Sheet.UsedRange;
                int rowCount = Range.Rows.Count;
                int colCount = Range.Columns.Count;

                SYS_tblReportCaptionDRO captionList = new SYS_tblReportCaptionDRO();
                captionList = await iPOS.BUS.Systems.SYS_tblReportCaptionBUS.GetReportCaption(username, language_id, function_id, true);

                if (!CommonEngine.CheckValidResponseItem(captionList.ResponseItem))
                {
                    return;
                }

                int index = 1;
                if (captionList != null && captionList.ReportCaptionList.Count > 0)
                {
                    Excel.Range             cellRange;
                    SYS_tblReportCaptionDRO comboItems;

                    for (int i = 0; i < captionList.ReportCaptionList.Count; i++)
                    {
                        cellRange = Sheet.Cells.Find("$" + captionList.ReportCaptionList[i].ControlID + "$", Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, Missing, false);
                        if (cellRange != null && cellRange.Cells.Count > 0)
                        {
                            cellRange.Replace("$" + captionList.ReportCaptionList[i].ControlID + "$", captionList.ReportCaptionList[i].Caption, Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns, true, Missing, Missing, Missing);
                            int colIndex = cellRange.Cells.Column;
                            int rowIndex = cellRange.Cells.Row;

                            if (captionList.ReportCaptionList[i].IsComment)
                            {
                                cellRange.AddComment(captionList.ReportCaptionList[i].Comment);
                            }

                            if (captionList.ReportCaptionList[i].IsRequire)
                            {
                                cellRange.Font.Bold  = true;
                                cellRange.Font.Color = Color.Red;
                            }

                            if (captionList.ReportCaptionList[i].IsList)
                            {
                                comboItems = new SYS_tblReportCaptionDRO();
                                comboItems = await iPOS.BUS.Systems.SYS_tblReportCaptionBUS.GetComboDynamicList(username, language_id, "", captionList.ReportCaptionList[i].TableName, "Code");

                                index++;
                                if (comboItems != null && comboItems.ComboDynamicList.Count > 0)
                                {
                                    Excel.Worksheet SheetData = null;
                                    if (index > Book.Worksheets.Count)
                                    {
                                        SheetData = (Excel.Worksheet)Book.Worksheets.Add(Missing, index, Missing, Missing);
                                    }
                                    else
                                    {
                                        SheetData = (Excel.Worksheet)Book.Worksheets[index];
                                    }
                                    SheetData.Name = captionList.ReportCaptionList[i].TableName;
                                    Excel.Range RangeData = SheetData.Range[SheetData.Cells[1, 1], SheetData.Cells[1, 2]];
                                    RangeData.Interior.Color = System.Drawing.Color.Yellow;
                                    RangeData.Font.Bold      = true;
                                    RangeData.Font.Color     = System.Drawing.Color.Red;
                                    SheetData.Cells[1, 1]    = "Code";
                                    SheetData.Cells[1, 2]    = "Name";

                                    for (int k = 0; k < comboItems.ComboDynamicList.Count; k++)
                                    {
                                        SheetData.Cells[k + 2, 1] = comboItems.ComboDynamicList[k].Code;
                                        SheetData.Cells[k + 2, 2] = comboItems.ComboDynamicList[k].Name;
                                    }

                                    RangeData = SheetData.Range[SheetData.Cells[1, 1], SheetData.Cells[comboItems.ComboDynamicList.Count + 1, 2]];
                                    RangeData.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                                    Excel.Borders BorderData = RangeData.Borders;
                                    BorderData.LineStyle = Excel.XlLineStyle.xlContinuous;
                                    BorderData.Weight    = 2d;
                                    RangeData.Columns.AutoFit();
                                    RangeData = Sheet.Range[Sheet.Cells[3, colIndex], Sheet.Cells[rowCount, colIndex]];
                                    RangeData.Validation.Add(Excel.XlDVType.xlValidateList, Excel.XlDVAlertStyle.xlValidAlertStop, Excel.XlFormatConditionOperator.xlBetween, string.Format("={0}!$A$2:$A${1}", captionList.ReportCaptionList[i].TableName, comboItems.ComboDynamicList.Count + 1), Missing);
                                    Range.Cells.HorizontalAlignment     = Excel.XlHAlign.xlHAlignLeft;
                                    RangeData.Validation.InCellDropdown = true;
                                }
                            }
                        }
                    }
                }
                Range.Columns.AutoFit();

                strFilePath = SaveExportCustom(Book, template, false);
                Book.Close(false, Missing, Missing);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return;
            }
            finally
            {
                App.Quit();
                Marshal.FinalReleaseComObject(Range);
                Marshal.FinalReleaseComObject(Sheet);
                Marshal.FinalReleaseComObject(Book);
                Marshal.FinalReleaseComObject(App);
                App = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();

                System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("excel");
                foreach (System.Diagnostics.Process process in processes)
                {
                    if (process.MainWindowTitle.Length == 0)
                    {
                        process.Kill();
                    }
                }
            }

            System.Diagnostics.Process.Start(strFilePath);
        }