示例#1
0
        /// <summary>
        ///
        /// </summary>
        private void AddColumnToGridPanel()
        {
            var arguments = ArgumentController.GetAll(null, false, KpiStatus.Active, null, null, null);
            var count     = 0;

            foreach (var item in arguments)
            {
                var recordField = new RecordField()
                {
                    Name    = item.Code,
                    Mapping = "ArgumentDetailModels[{0}].Value".FormatWith(count++)
                };

                var col = new Column
                {
                    ColumnID  = recordField.Name,
                    Header    = item.Name,
                    DataIndex = recordField.Name,
                    Width     = 150,
                    Renderer  = { Fn = "RenderArgument" }
                };
                switch (item.ValueType)
                {
                case KpiValueType.Percent:
                    col.Renderer.Fn = "RenderPercent";
                    col.Align       = Alignment.Left;
                    break;

                case KpiValueType.String:
                    col.Align = Alignment.Center;
                    break;

                case KpiValueType.Number:
                    break;

                case KpiValueType.Formula:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                storeEmployeeArgument.AddField(recordField);
                gpEmployeeArgument.ColumnModel.Columns.Add(col);
            }
        }
示例#2
0
        /// <summary>
        /// get unused caculated code
        /// </summary>
        /// <returns></returns>
        private static List <ArgumentCalculateCodeModel> GetCalculateCodes(int num)
        {
            var codes = new List <ArgumentCalculateCodeModel>();

            var argument = ArgumentController.GetAll(null, false, null, null, null, null);

            for (var i = 1; i < num + argument.Count; i++)
            {
                codes.Add(new ArgumentCalculateCodeModel {
                    Code = i.ToExcelColumnName()
                });
            }

            //check calculateCode exist
            var argumentCodes = argument.Select(a => a.CalculateCode).ToList();

            codes.RemoveAll(o => argumentCodes.Contains(o.Code));

            return(codes);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void DownloadTemplate_Click(object sender, DirectEventArgs e)
        {
            // init table
            var dataTable = new DataTable();

            // adjust table
            dataTable.Rows.Add();
            dataTable.Columns.Add(new DataColumn(EmployeeCode));
            dataTable.Columns.Add(new DataColumn(FullName));

            //add argument
            var argumentModels = ArgumentController.GetAll(null, false, KpiStatus.Active, null, null, null);

            foreach (var argument in argumentModels)
            {
                dataTable.Columns.Add(new DataColumn(argument.Name));
            }

            // get record by department
            var departmentIds = DepartmentIds;

            if (!string.IsNullOrEmpty(hdfDepartmentId.Text))
            {
                departmentIds = hdfDepartmentId.Text;
            }
            var records = RecordController.GetAll(null, null, departmentIds, RecordType.Default, null, null);

            // fill employee name and code
            for (var i = 0; i < records.Count; i++)
            {
                dataTable.Rows.Add();
                dataTable.Rows[i][EmployeeCode] = records[i].EmployeeCode;
                dataTable.Rows[i][FullName]     = records[i].FullName;
            }

            ExportToExcel(dataTable, "~/" + Constant.PathTemplate, ImportEmployeeArgumentExcelFile);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdateImportExcel_Click(object sender, DirectEventArgs e)
        {
            var workbook = new WorkBook();

            // upload file

            if (fileExcel.HasFile)
            {
                var path = UploadFile(fileExcel, Constant.PathTemplate);
                if (path != null)
                {
                    // Read data from excel
                    workbook.readXLSX(Path.Combine(Server.MapPath("~/"), Constant.PathTemplate, path));

                    // Check validation workbook
                    if (CheckValidation(workbook, out _, out _, txtFromRow, txtToRow, txtSheetName) == false)
                    {
                        return;
                    }

                    // Export to datatable
                    var dataTable = workbook.ExportDataTable(0,                    //first row
                                                             0,                    //first col
                                                             workbook.LastRow + 1, //last row
                                                             workbook.LastCol + 1, //last col
                                                             true,                 //first row as header
                                                             false                 //convert to DateTime object if it match date pattern
                                                             );

                    var argumentModels = ArgumentController.GetAll(null, false, KpiStatus.Active, null, null, null);
                    foreach (DataRow row in dataTable.Rows)
                    {
                        //get employee code
                        var employeeCode = row[EmployeeCode].ToString();
                        if (string.IsNullOrEmpty(employeeCode))
                        {
                            continue;
                        }

                        // get record by employee code
                        var record = RecordController.GetByEmployeeCode(employeeCode);

                        foreach (DataColumn col in dataTable.Columns)
                        {
                            foreach (var argument in argumentModels)
                            {
                                //check column name exists
                                if (argument.Name != col.ColumnName)
                                {
                                    continue;
                                }

                                //check empty string
                                var value = Convert.ToString(row[col], CultureInfo.InvariantCulture);
                                if (string.IsNullOrEmpty(value))
                                {
                                    continue;
                                }

                                //check if value exists
                                var employeeArgument = EmployeeArgumentController.GetUnique(Convert.ToInt32(hdfGroup.Text), record.Id, argument.Id,
                                                                                            Convert.ToInt32(hdfMonth.Text), Convert.ToInt32(hdfYear.Text));
                                if (employeeArgument != null)
                                {
                                    //update value
                                    employeeArgument.Value   = value;
                                    employeeArgument.GroupId = !string.IsNullOrEmpty(hdfGroup.Text)
                                        ? Convert.ToInt32(hdfGroup.Text)
                                        : 0;
                                    employeeArgument.EditedBy   = CurrentUser.User.UserName;
                                    employeeArgument.EditedDate = DateTime.Now;
                                    EmployeeArgumentController.Update(employeeArgument);
                                }
                                else
                                {
                                    var model = new EmployeeArgumentModel()
                                    {
                                        RecordId   = record.Id,
                                        ArgumentId = argument.Id,
                                        GroupId    = !string.IsNullOrEmpty(hdfGroup.Text)
                                            ? Convert.ToInt32(hdfGroup.Text)
                                            : 0,
                                        Month = Convert.ToInt32(hdfMonth.Text),
                                        Year  = Convert.ToInt32(hdfYear.Text),
                                        Value = value
                                    };

                                    EmployeeArgumentController.Create(model);
                                }
                            }
                        }
                    }
                    //reset
                    hdfGroup.Reset();
                    cboGroup.Reset();
                    hdfDepartmentId.Reset();
                    cboDepartment.Reset();
                }
            }
            else
            {
                Dialog.Alert("Bạn chưa chọn tệp tin đính kèm. Vui lòng chọn.");
                return;
            }

            Dialog.Alert("Cập nhật thành công");
            //Reset form excel
            fileExcel.Reset();
            txtSheetName.Reset();
            //reload grid
            gpEmployeeArgument.Reload();
        }