Ejemplo n.º 1
0
        public override void ExecuteImport(ServiceJobContext context, IDictionary <string, object> parameters)
        {
            string currentTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");

            _logger.LogInfo($"Execution Proces Started for {context.JobKey} at {currentTime}.");
            dataProvider = SumtContainer.Resolve <IDataProvider>();
            dataProvider.Open();
            try
            {
                string    importConfigFilePath = parameters["ImportConfigFilepath"].ToString();
                string    OrgFilePath          = parameters["OrganizationListFilePath"].ToString();
                DataTable dtOrgnization        = Helper.FileContentToDataTable(OrgFilePath, true);
                dtOrgnization.PrimaryKey = new DataColumn[] {
                    dtOrgnization.Columns["code"]
                };
                DataTable dtpersist = Helper.FileContentToDataTable(importConfigFilePath, false);
                DataTable dtDBOrg   = GetOrgDetails();
                UpdatePersist(dtpersist, dtOrgnization, dtDBOrg);
            }
            catch (Exception ex)
            {
                _logger.LogError("Error while processing configurations extract.", ex);
                throw (ex);
            }
            finally
            {
                dataProvider.Close();
            }
        }
Ejemplo n.º 2
0
        public override void ExecuteExport(ServiceJobContext context, IDictionary <string, object> parameters)
        {
            string currentTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");

            _logger.LogInfo($"Execution Proces Started for {context.JobKey} at {currentTime}.");
            dataProvider = SumtContainer.Resolve <IDataProvider>();
            dataProvider.Open();

            try
            {
                string settingstoExport = string.Empty;
                //Load job parameters
                settingstoExport = parameters["SettingsExport"].ToString();
                string reportPath = parameters["ExtractPath"].ToString();

                ISystemJobRepository  systemJobRepository = SumtContainer.Resolve <ISystemJobRepository>();
                ICodeDefinitionFacade facade         = SumtContainer.Resolve <ICodeDefinitionFacade>();
                CodeDefinitionDTO     codeDefinition = facade.GetCodeDefinitionWithAttributes(_configurationParameters.MasterCategoryCode);

                IList <CodeDTO> codes = codeDefinition.Codes.Where(c => c.CodeAttributeDTO.Attr1Val.Equals(_configurationParameters.Group)).ToList();
                // codeDefinition.Codes.Where(c => c.ItemText.Equals(settingstoExport)).ToList();
                string sectionLookupClause = string.Empty;
                foreach (CodeDTO code in codes)
                {
                    String[] sectionLookups = code.CodeAttributeDTO.Attr2Val.Split(',');
                    for (int i = 0; i < sectionLookups.Length; i++)
                    {
                        sectionLookups[i] = " p.Section like '%" + sectionLookups[i] + "%'";
                    }
                    sectionLookupClause += String.Join(" OR ", sectionLookups);
                }
                orgDomains = GetOrgDetails(_configurationParameters.Domains);
                foreach (KeyValuePair <string, int> kvp in orgDomains)
                {
                    GetPersistData(reportPath, sectionLookupClause, kvp);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Error while processing configurations extract.", ex);
                throw (ex);
            }
            finally
            {
                dataProvider.Close();
            }
        }
        public override void Execute(ServiceJobContext context, IDictionary <string, object> parameters)
        {
            string currentTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");

            _logger.LogInfo($"Execution Proces Started for {context.JobKey} at {currentTime}.");
            dataProvider = SumtContainer.Resolve <IDataProvider>();
            dataProvider.Open();
            try
            {
                string reportPath = parameters["ExtractPath"].ToString();
                string filePrefix = parameters["FilePrefix"].ToString();
                //added new line  code test

                ISystemJobRepository  systemJobRepository = SumtContainer.Resolve <ISystemJobRepository>();
                ICodeDefinitionFacade facade         = SumtContainer.Resolve <ICodeDefinitionFacade>();
                CodeDefinitionDTO     codeDefinition = facade.GetCodeDefinitionWithAttributes(_configurationParameters.MasterCategoryCode);

                var finalPath = Path.Combine(reportPath, filePrefix + "_" + DateTime.Now.ToString("yyyyMMdd'_'HHmmss") + ".xlsx");

                IList <CodeDTO> codes = codeDefinition.Codes.Where(c => c.CodeAttributeDTO.Attr1Val.Equals(_configurationParameters.Group)).ToList();
                if (codes.Count == 0)
                {
                    _logger.LogError("Please recheck master category code in system job parameters");
                    return;
                }
                var workbook = new XLWorkbook();
                foreach (CodeDTO code in codes)
                {
                    CodeDefinitionDTO sectionCode = facade.GetCodeDefinitionWithAttributes(Convert.ToInt32(code.ItemCode));
                    try
                    {
                        var sectionData = sectionCode.Codes.Select(c => new SectionTemplate()
                        {
                            SettingName     = c.CodeAttributeDTO.Attr1Val,
                            SettingKey      = c.ItemCode,
                            Itmtxt          = c.ItemText,
                            Sequence        = String.IsNullOrEmpty(c.CodeAttributeDTO.Attr2Val) ? 0 : Convert.ToInt32(c.CodeAttributeDTO.Attr2Val),
                            CodeLookupCatcd = String.IsNullOrEmpty(c.CodeAttributeDTO.Attr4Val) ? "" : c.CodeAttributeDTO.Attr4Val.ToString()
                        }).ToList();

                        DataTable dt2 = new DataTable();
                        dt2.Columns.Add("Securitykey", typeof(String));
                        dt2.Columns.Add("SecurityName", typeof(String));
                        dt2.Columns.Add("bitvalue", typeof(String));
                        dt2.Columns.Add("Sequence", typeof(Decimal));

                        object[] values = new object[4];


                        foreach (SectionTemplate sec in sectionData)
                        {
                            values[0] = sec.SettingKey;
                            values[1] = sec.SettingKey;
                            values[3] = sec.Sequence;
                            dt2.Rows.Add(values);
                            string[] securitykeys = sec.SettingName.Split(',');
                            int      i            = 0;
                            // Part 3: loop over result array.
                            foreach (string securitykey in securitykeys)
                            {
                                if (securitykeys[0] != "")
                                {
                                    values[0] = securitykey;
                                    values[1] = sec.SettingKey;
                                    values[3] = sec.Sequence + "." + i;
                                    dt2.Rows.Add(values);
                                    i++;
                                }
                            }
                        }

                        //Get Security name hexadecimal value and bit value
                        CodeDefinitionDTO hexadecimal = facade.GetCodeDefinitionWithAttributes(Convert.ToInt32("100900"));

                        var hexadecimalData = hexadecimal.Codes.Select(c => new RoleMaskSettings()
                        {
                            SecurityName = c.ItemCode,
                            HexaDecimal  = c.CodeAttributeDTO.Attr1Val,
                            bitvalue     = c.CodeAttributeDTO.Attr2Val,
                            Itmtxt       = c.ItemText
                        }).ToList();

                        //convert list to data table
                        DataTable code100900 = new DataTable();
                        code100900 = Helper.ToDataTable(hexadecimalData);

                        dt2.AsEnumerable()
                        .Join(code100900.AsEnumerable(),
                              dt1_Row => dt1_Row.ItemArray[0],
                              dt2_Row => dt2_Row.ItemArray[0],
                              (dt1_Row, dt2_Row) => new { dt1_Row, dt2_Row })
                        .ToList()
                        .ForEach(o =>
                                 o.dt1_Row.SetField(2, o.dt2_Row.ItemArray[2]));

                        dt2.AsEnumerable()
                        .Join(code100900.AsEnumerable(),
                              dt1_Row => dt1_Row.ItemArray[0],
                              dt2_Row => dt2_Row.ItemArray[0],
                              (dt1_Row, dt2_Row) => new { dt1_Row, dt2_Row })
                        .ToList()
                        .ForEach(o =>
                                 o.dt1_Row.SetField(0, o.dt2_Row.ItemArray[3]));

                        Tuple <DataTable, DataTable> RoleMaskOrgData = GetRoleMaskData();
                        DataTable RoleMaskData = RoleMaskOrgData.Item1;
                        DataTable OrgData      = RoleMaskOrgData.Item2;
                        var       distinctIds  = RoleMaskData.AsEnumerable()
                                                 .Select(s => new {
                            id = s.Field <int>("Role_DomainFK"),
                        })
                                                 .Distinct().ToList();
                        for (int i = 3; i < distinctIds.Count + 3; i++)
                        {
                            DataTable rolemaskDomainData = new DataTable();
                            int       domainId           = Int32.Parse(distinctIds[i - 3].id.ToString());
                            string    Domian_Name        = null;
                            var       DomainName         = from row in OrgData.AsEnumerable()
                                                           where row.Field <int>("OrganizationPK") == domainId
                                                           select new
                            {
                                DomainName = row.Field <string>("Name")
                            };

                            rolemaskDomainData = GetRolemaskDetails(domainId, RoleMaskData, dt2);
                            rolemaskDomainData.Columns.Remove("bitvalue");
                            rolemaskDomainData.Columns.Remove("Sequence");

                            foreach (var dom in DomainName)
                            {
                                Domian_Name = dom.DomainName;
                            }
                            workbook = Helper.AddWorkSheet(rolemaskDomainData, Domian_Name, workbook);
                        }
                        foreach (IXLWorksheet xLWorksheet in workbook.Worksheets)
                        {
                            xLWorksheet.Style.Border.RightBorder      = XLBorderStyleValues.Thick;
                            xLWorksheet.Style.Border.RightBorderColor = XLColor.Black;
                            xLWorksheet.Style.Border.OutsideBorder    = XLBorderStyleValues.Thick;
                            var rows = xLWorksheet.RangeUsed().RowsUsed().Skip(1);
                            // First possible address of the company table:
                            var firstPossibleAddress = xLWorksheet.Row(1).FirstCell().Address;
                            // Last possible address of the company table:
                            var lastPossibleAddress = xLWorksheet.LastCellUsed().Address;

                            // Get a range with the remainder of the worksheet data (the range used)
                            var companyRange = xLWorksheet.Range(firstPossibleAddress, lastPossibleAddress).RangeUsed();

                            var firstTableCell = xLWorksheet.FirstCellUsed();
                            var lastTableCell  = xLWorksheet.LastCellUsed();
                            xLWorksheet.Style.Font.FontSize = 9;
                            var rngData = xLWorksheet.Range(firstTableCell.Address, lastTableCell.Address);

                            rngData.Rows(); // From all rows
                            rngData.Style.Border.SetInsideBorder(XLBorderStyleValues.Thin);
                            var range = xLWorksheet.Range("A1:" + lastTableCell.Address.ColumnLetter + "1");
                            range.Style.Font.FontSize        = 11;
                            range.Style.Font.FontColor       = XLColor.White;
                            range.Style.Fill.BackgroundColor = XLColor.RichElectricBlue;



                            foreach (var row in rows)
                            {
                                if (row.Cell(1).Value.ToString() == row.Cell(2).Value.ToString())
                                {
                                    var    rowNumber      = row.RowNumber();
                                    string pagebreakValue = xLWorksheet.Cell(rowNumber, 2).Value.ToString();
                                    xLWorksheet.Cell(rowNumber, 1).Style.Font.Bold = true;
                                }
                            }

                            xLWorksheet.Column(2).Delete();

                            xLWorksheet.Columns(1, lastTableCell.Address.ColumnNumber).Width = 35;
                            xLWorksheet.Style.Alignment.WrapText   = true;
                            xLWorksheet.Columns(1, 1).Width        = 50;
                            xLWorksheet.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
                            xLWorksheet.Style.Alignment.Vertical   = XLAlignmentVerticalValues.Top;
                        }

                        workbook.SaveAs(finalPath);
                    }
                    catch (Exception ex2)
                    {
                        _logger.LogError("No codes for catcd " + sectionCode.CodeName);
                    }
                }
            }
            finally
            {
                dataProvider.Close();
            }
        }
Ejemplo n.º 4
0
        public static DataTable JoinTwoDataTablesOnOneColumn(DataTable dtblLeft, DataTable dtblRight, string colToJoinOn)
        {
            //Change column name to a temp name so the LINQ for getting row data will work properly.
            string            strTempColName   = "settingkey_db";
            IPersonRepository personRepository = SumtContainer.Resolve <IPersonRepository>();

            if (dtblRight.Columns.Contains(colToJoinOn))
            {
                dtblRight.Columns[colToJoinOn].ColumnName = strTempColName;
            }

            //Get columns from dtblLeft
            DataTable dtblResult = dtblLeft.Clone();

            dtblResult.Columns["Sequence"].DataType = typeof(Int32);

            //Get columns from dtblRight
            var dt2Columns = dtblRight.Columns.OfType <DataColumn>().Select(dc => new DataColumn(dc.ColumnName, dc.DataType, dc.Expression, dc.ColumnMapping));

            //Get columns from dtblRight that are not in dtblLeft
            var dt2FinalColumns = from dc in dt2Columns.AsEnumerable()
                                  where !dtblResult.Columns.Contains(dc.ColumnName)
                                  select dc;

            //Add the rest of the columns to dtblResult
            dtblResult.Columns.AddRange(dt2FinalColumns.ToArray());


            //No reason to continue if the colToJoinOn does not exist in both DataTables.
            if (!dtblLeft.Columns.Contains(colToJoinOn) || (!dtblRight.Columns.Contains(colToJoinOn) && !dtblRight.Columns.Contains(strTempColName)))
            {
                if (!dtblResult.Columns.Contains(colToJoinOn))
                {
                    dtblResult.Columns.Add(colToJoinOn);
                }
                return(dtblResult);
            }

            dtblLeft.DefaultView.Sort = colToJoinOn;
            dtblLeft = dtblLeft.DefaultView.ToTable();

            dtblRight.DefaultView.Sort = strTempColName;
            dtblRight = dtblRight.DefaultView.ToTable();

            var rowDataLeftOuter = from rowLeft in dtblLeft.AsEnumerable()
                                   join rowRight in dtblRight.AsEnumerable() on rowLeft[colToJoinOn].ToString().ToLower().Trim() equals rowRight[strTempColName].ToString().ToLower().Trim() into gj
                                   from subRight in gj.DefaultIfEmpty()
                                   select rowLeft.ItemArray.Concat((subRight == null)?(dtblRight.NewRow().ItemArray) : subRight.ItemArray).ToArray();


            foreach (object[] values in rowDataLeftOuter)
            {
                dtblResult.Rows.Add(values);
            }



            foreach (DataRow dr in dtblResult.Rows)
            {
                if (Convert.ToBoolean(dr.Field <String>("HasLookup")))
                {
                    var lookupData = new Dictionary <String, string>();
                    var list       = dr.Field <string>("LookupData").ToString().Split(';').ToList();
                    if (list.Count > 0)
                    {
                        list.ForEach(l =>
                        {
                            var item = l.Split(':');
                            if (item.Length > 1)
                            {
                                lookupData.Add(item[0], item[1]);
                            }
                        });
                        for (int c = 1; c < dt2Columns.Count(); c++)
                        {
                            var values = dr.Field <string>(dt2Columns.ElementAt(c).ColumnName);
                            if (values != null)
                            {
                                //Any specific char want remove
                                values = values.Trim(new Char[] { '\'' });
                                List <String> valueFromLookup = new List <string>();
                                foreach (var value in values.Split(','))
                                {
                                    if (value != null && lookupData.ContainsKey(value))
                                    {
                                        valueFromLookup.Add(lookupData[value].ToString());
                                    }
                                }
                                dr[dt2Columns.ElementAt(c).ColumnName] = String.Join(",", valueFromLookup);
                            }
                        }
                    }
                }
                for (int i = 1; i <= dt2Columns.Count() - 1; i++)
                {
                    var value = dr.Field <string>(dt2Columns.ElementAt(i).ColumnName);
                    if (value != null && value.Equals("NOTAPL"))
                    {
                        dr[dt2Columns.ElementAt(i).ColumnName] = String.Empty;
                    }
                }

                if (!String.IsNullOrEmpty(dr.Field <String>("IsPerson").Trim()))
                {
                    DataRow row = dtblResult.Rows
                                  .Cast <DataRow>()
                                  .Where(x => x[colToJoinOn].ToString().Equals(dr.Field <String>("IsPerson").ToString(), StringComparison.OrdinalIgnoreCase)).ToList().FirstOrDefault();
                    for (int c = 1; c < dt2Columns.Count() - 1; c++)
                    {
                        //DataRow row = dtblResult.Select()

                        var value = row.Field <string>(dt2Columns.ElementAt(c).ColumnName);
                        if (value != null && value.ToString() != "0")
                        {
                            if (Int32.TryParse(value.ToString(), out int PersonPk))
                            {
                                Person personInfo = personRepository.LoadPersonById(PersonPk);
                                if (personInfo != null)
                                {
                                    dr[dt2Columns.ElementAt(c).ColumnName] = personInfo.PersonNumber;
                                }
                            }
                        }
                    }
                }
            }

            var personRecords = dtblResult.Rows
                                .Cast <DataRow>()
                                .Where(x => x["IsPerson"].ToString().Trim().Length > 0)
                                .Select(p => p.Field <string>("IsPerson")).ToList();

            var rowsToBeDeleted = dtblResult.Rows
                                  .Cast <DataRow>()
                                  .Where(x => personRecords.Contains(x[strTempColName].ToString()))
                                  .ToList();

            foreach (DataRow row in rowsToBeDeleted)
            {
                dtblResult.Rows.Remove(row);
            }

            dtblResult.AcceptChanges();

            //Change column name back to original
            dtblRight.Columns[strTempColName].ColumnName = colToJoinOn;

            dtblResult.DefaultView.Sort = "Sequence";
            dtblResult = dtblResult.DefaultView.ToTable();
            dtblResult.AcceptChanges();
            //Remove extra column from result and setting name also
            dtblResult.Columns.Remove(strTempColName);
            dtblResult.Columns.Remove("Sequence");
            dtblResult.Columns.Remove("HasLookup");
            dtblResult.Columns.Remove("IsPerson");
            dtblResult.Columns.Remove("IsRule");
            dtblResult.Columns.Remove("MergeColumns");
            dtblResult.Columns.Remove("LookupData");

            return(dtblResult);
        }
Ejemplo n.º 5
0
        public override void Execute(ServiceJobContext context, IDictionary <string, object> parameters)
        {
            string currentTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");

            _logger.LogInfo($"Execution Proces Started for {context.JobKey} at {currentTime}.");
            dataProvider = SumtContainer.Resolve <IDataProvider>();
            dataProvider.Open();

            try
            {
                string reportPath = parameters["ExtractPath"].ToString();
                string filePrefix = parameters["FilePrefix"].ToString();


                ISystemJobRepository  systemJobRepository = SumtContainer.Resolve <ISystemJobRepository>();
                ICodeDefinitionFacade facade         = SumtContainer.Resolve <ICodeDefinitionFacade>();
                CodeDefinitionDTO     codeDefinition = facade.GetCodeDefinitionWithAttributes(_configurationParameters.MasterCategoryCode);

                var finalPath = Path.Combine(reportPath, filePrefix + "_" + DateTime.Now.ToString("yyyyMMdd'_'HHmmss") + ".xlsx");

                IList <CodeDTO> codes = codeDefinition.Codes.Where(c => c.CodeAttributeDTO.Attr1Val.Equals(_configurationParameters.Group)).ToList();
                if (codes.Count == 0)
                {
                    _logger.LogError("Please recheck master category code in system job parameters");
                    return;
                }
                var workbook = new XLWorkbook();
                foreach (CodeDTO code in codes)
                {
                    CodeDefinitionDTO sectionCode = facade.GetCodeDefinitionWithAttributes(Convert.ToInt32(code.ItemCode));
                    try
                    {
                        var sectionData = sectionCode.Codes.Select(c => new SectionTemplate()
                        {
                            SettingName  = c.CodeAttributeDTO.Attr1Val,
                            SettingKey   = c.ItemCode,
                            Sequence     = String.IsNullOrEmpty(c.CodeAttributeDTO.Attr2Val) ? 0 : Convert.ToInt32(c.CodeAttributeDTO.Attr2Val),
                            HasLookup    = String.IsNullOrEmpty(c.CodeAttributeDTO.Attr3Val) ? false : Convert.ToBoolean(c.CodeAttributeDTO.Attr3Val),
                            IsPerson     = c.CodeAttributeDTO.Attr4Val,
                            IsRule       = String.IsNullOrEmpty(c.CodeAttributeDTO.Attr5Val) ? false : Convert.ToBoolean(c.CodeAttributeDTO.Attr5Val),
                            MergeColumns = String.IsNullOrEmpty(c.CodeAttributeDTO.Attr6Val) ? 0 : Convert.ToInt32(c.CodeAttributeDTO.Attr6Val),
                            LookupData   = String.IsNullOrEmpty(c.CodeAttributeDTO.Attr7Val) ? "" : c.CodeAttributeDTO.Attr7Val.ToString()
                        }).ToList();

                        String[] sectionLookups      = code.CodeAttributeDTO.Attr2Val.Split(',');
                        string   sectionLookupClause = string.Empty;
                        for (int i = 0; i < sectionLookups.Length; i++)
                        {
                            sectionLookups[i] = " p.Section like '%" + sectionLookups[i] + "%'";
                        }
                        sectionLookupClause = String.Join(" OR ", sectionLookups);
                        bool checkOnlyGlobal = false;
                        if (sectionLookupClause.Contains("GeneralSetting"))
                        {
                            checkOnlyGlobal = true;
                        }
                        var       tupleSectionData = PullSectionSettingvaluesIntoTemp(sectionLookupClause, checkOnlyGlobal);
                        DataTable settingsData     = JoinTwoDataTablesOnOneColumn(Helper.ToDataTable(sectionData), tupleSectionData, "SettingKey");
                        workbook = Helper.AddWorkSheet(settingsData, code.ItemText, workbook);
                    }
                    catch (Exception ex2)
                    {
                        _logger.LogError("No codes for catcd " + sectionCode.CodeName);
                    }
                }

                foreach (IXLWorksheet xLWorksheet in workbook.Worksheets)
                {
                    xLWorksheet.Style.Border.RightBorder      = XLBorderStyleValues.Thick;
                    xLWorksheet.Style.Border.RightBorderColor = XLColor.Black;
                    xLWorksheet.Style.Border.OutsideBorder    = XLBorderStyleValues.Thick;
                    var rows = xLWorksheet.RangeUsed().RowsUsed().Skip(1);
                    // First possible address of the company table:
                    var firstPossibleAddress = xLWorksheet.Row(1).FirstCell().Address;
                    // Last possible address of the company table:
                    var lastPossibleAddress = xLWorksheet.LastCellUsed().Address;

                    // Get a range with the remainder of the worksheet data (the range used)
                    var companyRange = xLWorksheet.Range(firstPossibleAddress, lastPossibleAddress).RangeUsed();

                    var firstTableCell = xLWorksheet.FirstCellUsed();
                    var lastTableCell  = xLWorksheet.LastCellUsed();
                    xLWorksheet.Style.Font.FontSize = 9;
                    var rngData = xLWorksheet.Range(firstTableCell.Address, lastTableCell.Address);

                    rngData.Rows(); // From all rows
                    rngData.Style.Border.SetInsideBorder(XLBorderStyleValues.Thin);
                    var range = xLWorksheet.Range("A1:" + lastTableCell.Address.ColumnLetter + "1");
                    range.Style.Font.FontSize        = 11;
                    range.Style.Font.FontColor       = XLColor.White;
                    range.Style.Fill.BackgroundColor = XLColor.RichElectricBlue;

                    xLWorksheet.Columns(2, 2).Style.Alignment.WrapText = true;

                    foreach (var row in rows)
                    {
                        if (row.Cell(1).Value.ToString().Contains("PageBreak"))
                        {
                            var      rowNumber      = row.RowNumber();
                            string   pagebreakValue = xLWorksheet.Cell(rowNumber, 2).Value.ToString();
                            string[] splitValue     = pagebreakValue.Split(':');
                            if (splitValue.Length == 2)
                            {
                                xLWorksheet.Cell(rowNumber, 2).Value = splitValue[0].ToString();
                                xLWorksheet.Cell(rowNumber, 2).Style.Font.FontSize = 10;
                                xLWorksheet.Range("C" + rowNumber.ToString() + ":" + lastTableCell.Address.ColumnLetter + rowNumber.ToString()).Row(1).Merge();
                                xLWorksheet.Range("C" + rowNumber.ToString() + ":" + lastTableCell.Address.ColumnLetter + rowNumber.ToString()).Style.Font.FontSize = 10;
                                xLWorksheet.Cell("C" + rowNumber.ToString()).Value = splitValue[1].ToString();
                            }
                            xLWorksheet.Cell(rowNumber, 2).Style.Font.Bold = true;
                        }
                        if (row.Cell(1).Value.ToString().Contains("EmptyRow"))
                        {
                            var rowNumber = row.RowNumber();

                            xLWorksheet.Cell(rowNumber, 2).Value = "";
                        }
                    }

                    xLWorksheet.Column(1).Delete();
                    //xLWorksheet.ColumnWidth = 28;
                    //xLWorksheet.Columns(1, 1).Style.Alignment.WrapText = true;

                    xLWorksheet.Columns(1, lastTableCell.Address.ColumnNumber).Width = 35;
                    xLWorksheet.Style.Alignment.WrapText   = true;
                    xLWorksheet.Columns(1, 1).Width        = 50;
                    xLWorksheet.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
                    xLWorksheet.Style.Alignment.Vertical   = XLAlignmentVerticalValues.Top;
                    //xLWorksheet.Style.Alignment.SetVertical(XLDrawingVerticalAlignment.Bottom);
                    //xLWorksheet.Comment.Style
                    //  .Alignment.SetVertical(XLDrawingVerticalAlignment.Bottom)
                    //  .Alignment.SetHorizontal(XLDrawingHorizontalAlignment.Right);

                    // xLWorksheet.ColumnWidth = 60;
                }
                workbook.SaveAs(finalPath);
            }
            catch (Exception ex)
            {
                _logger.LogError("Error while processing configurations extract.", ex);
                throw (ex);
            }
            finally
            {
                dataProvider.Close();
            }
        }
Ejemplo n.º 6
0
        public override void Execute(ServiceJobContext context, IDictionary <string, object> parameters)
        {
            string currentTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");

            _logger.LogInfo($"Execution Proces Started for {context.JobKey} at {currentTime}.");
            dataProvider = SumtContainer.Resolve <IDataProvider>();
            dataProvider.Open();

            try
            {
                int    masterCategoryCode;
                string group;
                string settingstoExport = string.Empty;
                //Load job parameters
                masterCategoryCode = Convert.ToInt32(parameters["MasterCategoryCode"]);
                group            = parameters["Group"].ToString();
                settingstoExport = parameters["SettingsExport"].ToString();
                string    reportPath       = parameters["ExtractPath"].ToString();
                string    orgCodestoExport = parameters["OrgCodestoExport"].ToString();
                DataTable dtOrgDetails     = GetOrgDetails(orgCodestoExport);
                if (string.IsNullOrEmpty(settingstoExport))
                {
                    ISystemJobRepository  systemJobRepository = SumtContainer.Resolve <ISystemJobRepository>();
                    ICodeDefinitionFacade facade         = SumtContainer.Resolve <ICodeDefinitionFacade>();
                    CodeDefinitionDTO     codeDefinition = facade.GetCodeDefinitionWithAttributes(masterCategoryCode);
                    List <string>         settings       = settingstoExport.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    IList <CodeDTO>       codes          = codeDefinition.Codes.Where(c => settings.Any(b => string.Compare(c.ItemCode, b, true) == 0)).ToList();
                    string domainCondition = "";
                    if (group == "I")
                    {
                        string sectionLookupClause = string.Empty;
                        foreach (CodeDTO code in codes)
                        {
                            String[] sectionLookups = code.CodeAttributeDTO.Attr2Val.Split(',');
                            for (int i = 0; i < sectionLookups.Length; i++)
                            {
                                if (dtOrgDetails != null && dtOrgDetails.Rows.Count != 0)
                                {
                                    domainCondition = "";
                                    foreach (DataRow row in dtOrgDetails.Rows)
                                    {
                                        domainCondition += " p.Section like '%" + "Domain/" + row[0] + "/" + sectionLookups[i] + "%'";
                                    }
                                    sectionLookups[i] = domainCondition;
                                }
                                else
                                {
                                    sectionLookups[i] = " p.Section like '%" + sectionLookups[i] + "%'";
                                }
                            }
                            sectionLookupClause += String.Join(" OR ", sectionLookups);
                        }
                        GetPersistData(reportPath, sectionLookupClause);
                    }
                    else if (group == "II")
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Error while processing configurations extract.", ex);
                throw (ex);
            }
            finally
            {
                dataProvider.Close();
            }
        }
Ejemplo n.º 7
0
        public override void Execute(ServiceJobContext context, IDictionary <string, object> parameters)
        {
            string configurationCode = string.Empty;

            configurationCode = Convert.ToString(parameters["ConfigCode"]);
            int  configCode        = 0;
            bool intResultTryParse = int.TryParse(configurationCode, out configCode);

            if (string.IsNullOrEmpty(configurationCode) || intResultTryParse == false)
            {
                _logger.LogError("Configure System Job Properly Missing Config Code or Invalid Input.");
                return;
            }
            ICodeDefinitionFacade facade         = SumtContainer.Resolve <ICodeDefinitionFacade>();
            CodeDefinitionDTO     codeDefinition = facade.GetCodeDefinitionWithAttributes(configCode);

            if (codeDefinition == null)
            {
                _logger.LogError("Invalid Category Code : " + configCode);
                return;
            }
            if (codeDefinition.Codes.Count == 0)
            {
                _logger.LogError("Configure Category Code properly for " + configCode);
                return;
            }

            if (codeDefinition.Codes[0].CodeAttributeDTO != null)
            {
                //Attr1Value == Groups to be processed.
                //Attr2Value == Master Category Code.
                //Attr3Value == Domains to be consider.
                ConfigurationParameters configurationParameters = new ConfigurationParameters();
                configurationParameters.MasterCategoryCode = String.IsNullOrEmpty(codeDefinition.Codes[0].CodeAttributeDTO.Attr2Val) ? 0 : Convert.ToInt32(codeDefinition.Codes[0].CodeAttributeDTO.Attr2Val);
                configurationParameters.Domains            = String.IsNullOrEmpty(codeDefinition.Codes[0].CodeAttributeDTO.Attr3Val)? null : codeDefinition.Codes[0].CodeAttributeDTO.Attr3Val.Split();
                bool processExport  = Boolean.TryParse(codeDefinition.Codes[0].CodeAttributeDTO.Attr4Val, out processExport);
                bool processExtract = Boolean.TryParse(codeDefinition.Codes[0].CodeAttributeDTO.Attr5Val, out processExtract);
                bool processImport  = Boolean.TryParse(codeDefinition.Codes[0].CodeAttributeDTO.Attr6Val, out processImport);
                configurationParameters.ProcessExport  = processExport;
                configurationParameters.ProcessExtract = processExtract;
                configurationParameters.ProcessImport  = processImport;
                string group;
                group = Convert.ToString(codeDefinition.Codes[0].CodeAttributeDTO.Attr1Val);
                string[] groups = group.Split(',');
                if (groups.Length > 0)
                {
                    foreach (var g in groups)
                    {
                        baseExtract = SettingsFactory.GetExtractor(g);
                        configurationParameters.Group = g;
                        baseExtract.LoadDependencies(_logger, configurationParameters);
                        if (configurationParameters.ProcessExtract)
                        {
                            baseExtract.Execute(context, parameters);
                        }
                        if (configurationParameters.ProcessExport)
                        {
                            baseExtract.ExecuteExport(context, parameters);
                        }
                        if (configurationParameters.ProcessImport)
                        {
                            baseExtract.ExecuteImport(context, parameters);
                        }
                    }
                }
                else
                {
                    _logger.LogError("Configure Groups to be processed properly.");
                }
            }
        }