Exemplo n.º 1
0
        public void SetEditValues(string recordId, string columnCode, string value)
        {
            // show button
            btnAcceptChange.Hidden = false;
            btnCancelChange.Hidden = false;

            List <SalaryBoardDynamicColumnModel> list;

            SalaryBoardDynamicColumnModel salaryBoardDynamicColumn;

            // get edit column
            var salaryBoardDynamicColumns = SalaryBoardDynamicColumnController.GetAll(null, recordId, int.Parse(hdfSalaryBoardListID.Text), columnCode, true, null, 1);

            if (salaryBoardDynamicColumns == null || salaryBoardDynamicColumns.Count == 0)
            {
                // create new column value
                salaryBoardDynamicColumn = new SalaryBoardDynamicColumnModel
                {
                    RecordId      = int.Parse(recordId),
                    SalaryBoardId = int.Parse(hdfSalaryBoardListID.Text),
                    ColumnCode    = columnCode,
                    Value         = value,
                    IsInUsed      = true
                };
            }
            else
            {
                // update column value
                salaryBoardDynamicColumn       = salaryBoardDynamicColumns.First();
                salaryBoardDynamicColumn.Value = value;
            }

            // set text hidden field
            if (!string.IsNullOrEmpty(hdfEditList.Text))
            {
                list = JSON.Deserialize <List <SalaryBoardDynamicColumnModel> >(hdfEditList.Text);
                list.Add(salaryBoardDynamicColumn);
            }
            else
            {
                list = new List <SalaryBoardDynamicColumnModel> {
                    salaryBoardDynamicColumn
                };
            }

            hdfEditList.Text = JSON.Serialize(list);
        }
Exemplo n.º 2
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));

                    // 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
                                                             );

                    // get config by ID
                    var salaryBoardConfig = SalaryBoardConfigController.GetAll(int.Parse(hdfConfigId.Text), null, null, null,
                                                                               SalaryConfigDataType.DynamicValue, 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 item in salaryBoardConfig)
                            {
                                // check column name exists
                                if (item.Display != col.ColumnName)
                                {
                                    continue;
                                }

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

                                // check if dynamic column value exists
                                var salaryBoardDynamicColumn = SalaryBoardDynamicColumnController.GetAll(null, record.Id.ToString(), int.Parse(hdfPayrollId.Text), item.ColumnCode, true, null, null);

                                if (salaryBoardDynamicColumn.Count > 0)
                                {
                                    // update dynamic column value
                                    salaryBoardDynamicColumn.First().Value = value;
                                    SalaryBoardDynamicColumnController.Update(salaryBoardDynamicColumn.First());
                                }
                                else
                                {
                                    // create dynamic column value
                                    var salaryBoardConfigColumn = new SalaryBoardDynamicColumnModel()
                                    {
                                        RecordId      = record.Id,
                                        SalaryBoardId = int.Parse(hdfPayrollId.Text),
                                        ColumnCode    = item.ColumnCode,
                                        Value         = value,
                                        Display       = item.Display
                                    };
                                    SalaryBoardDynamicColumnController.Create(salaryBoardConfigColumn);
                                }
                            }
                        }
                    }
                }
            }
            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");
            grpPayrollDetail.Reload();
        }