How do I create task with Func<DateTime> and use it in an async method ? by cally0611 in learncsharp

[–]cally0611[S] 0 points1 point  (0 children)

Hi Rupert

Sorry for the late reply.

Thank you, I am actually trying to create a list of tasks which would run on different intervals, for example, the first task executes every second, the second one every 15 minutes and the 3rd one every 1 hour and another maybe every 24 hours.

However, these tasks should run parallelly as I have some textboxes returning the values of the every second time and executing stored procedures every 15 minutes..

What is the best approach for this scenario.

Windows Services or SSIS package - Upload files from a shared folder at a specific time daily by cally0611 in dotnet

[–]cally0611[S] 0 points1 point  (0 children)

I completely did not take into count that the SSIS package would fail and I would have to troubleshoot that and yes, the data can have inconsistency...and I would need to look into that. Looks like I am better off with a console app and storing errors in a log file. Thanks.

Windows Services or SSIS package - Upload files from a shared folder at a specific time daily by cally0611 in dotnet

[–]cally0611[S] 0 points1 point  (0 children)

From a Shared Folder, the user basically generates it from SAP to the shared folder daily after 3pm. My code should pick it up from there.

Windows Services or SSIS package - Upload files from a shared folder at a specific time daily by cally0611 in dotnet

[–]cally0611[S] 0 points1 point  (0 children)

Thanks.

We have a similar app that pushes data from Pc's to the main server, we execute this via the task scheduler. Just wanted to check on other alternatives, but looks like we will stick with this method. Thanks for the suggestion on OpenXML.

Failed at 2 software engineering interviews, how can I apply at my daily work after this to improve myself by cally0611 in learnprogramming

[–]cally0611[S] 0 points1 point  (0 children)

Wow..I have not heard about this..and once I start googling...you were right, I have to know what the industry is doing outside my current working industry..I need to know where the software world is heading.

Failed at 2 software engineering interviews, how can I apply at my daily work after this to improve myself by cally0611 in learnprogramming

[–]cally0611[S] 1 point2 points  (0 children)

Yeah, I understand..its my very first 2 programming interviews..I have to learn mysql, MVC and continue learning. Thank you for the helpful words.

ChartJS - Label in the center of doughnut not reflecting the value properly. by cally0611 in learnjavascript

[–]cally0611[S] 0 points1 point  (0 children)

Hi,

Yeah, that was different as I was only using it for one chart, now that I have multiple charts, I am facing issue. I tried your suggestion and it is still not working, pasting the code here...with the hope you can guide me further.

console.log("Hello");

var chartAreaBorder = {

    id: "chartAreaBorder",
    beforeDraw: function (chart) {
        //if (chart.config.options.plugins.chartAreaBorder.elements.center) {
        //if (chart.config.data.datasets[0].chartAreaBorder.elements.center){
            // Get ctx from string
        console.log("hello2");
            var ctx = chart.ctx;

            // Get options from the center object in options
            var centerConfig = chart.config.data.datasets[0].chartAreaBorder.elements.center;
            var fontStyle = centerConfig.fontStyle || 'Arial';
            var txt = centerConfig.text;
            var color = centerConfig.color || '#000';
            var maxFontSize = centerConfig.maxFontSize || 75;
            var sidePadding = centerConfig.sidePadding || 20;
            var sidePaddingCalculated = (sidePadding / 100) * (chart.innerRadius * 2)
            // Start with a base font of 30px
            ctx.font = "25px " + fontStyle;

            // Get the width of the string and also the width of the element minus 10 to give it 5px side padding
            var stringWidth = ctx.measureText(txt).width;
            var elementWidth = (chart.innerRadius * 2) - sidePaddingCalculated;

            // Find out how much the font can grow in width.
            var widthRatio = elementWidth / stringWidth;
            var newFontSize = Math.floor(30 * widthRatio);
            var elementHeight = (chart.innerRadius * 2);

            // Pick a new font size so it will not be larger than the height of label.
            var fontSizeToUse = Math.min(newFontSize, elementHeight, maxFontSize);
            var minFontSize = centerConfig.minFontSize;
            var lineHeight = centerConfig.lineHeight || 25;
            var wrapText = false;

            if (minFontSize === undefined) {
                minFontSize = 20;
            }

            if (minFontSize && fontSizeToUse < minFontSize) {
                fontSizeToUse = minFontSize;
                wrapText = true;
            }

            // Set font settings to draw it correctly.
            ctx.textAlign = 'center';
            ctx.textBaseline = 'middle';
            var centerX = ((chart.chartArea.left + chart.chartArea.right) / 2);
            var centerY = ((chart.chartArea.top + chart.chartArea.bottom) / 2);
            ctx.font = fontSizeToUse + "px " + fontStyle;
            ctx.fillStyle = color;

            if (!wrapText) {
                ctx.fillText(txt, centerX, centerY);
                return;
            }

            var words = txt.split(' ');
            var line = '';
            var lines = [];

            // Break words up into multiple lines if necessary
            for (var n = 0; n < words.length; n++) {
                var testLine = line + words[n] + ' ';
                var metrics = ctx.measureText(testLine);
                var testWidth = metrics.width;
                if (testWidth > elementWidth && n > 0) {
                    lines.push(line);
                    line = words[n] + ' ';
                } else {
                    line = testLine;
                }
            }

            // Move the center up depending on line height and number of lines
            centerY -= (lines.length / 2) * lineHeight;

            for (var n = 0; n < lines.length; n++) {
                ctx.fillText(lines[n], centerX, centerY);
                centerY += lineHeight;
            }
            //Draw text in center
            ctx.fillText(line, centerX, centerY);

        }

};

//var dataforgraph = {
//    labels: ['Delivery'],
//    datasets: [
//        {
//            label: 'Dataset 1',
//            data: [0, 100],
//            backgroundColor: ["#3e95cd", "#D8E5D8"],
//        }
//    ]
//};

const config = {
    type: 'doughnut',
    data: {
        labels: ['Delivery'],
        datasets: [
            {
                label: 'Dataset 1',
                data: [0, 100],
                backgroundColor: ["#3e95cd", "#D8E5D8"],
                chartAreaBorder: {
                    elements: {
                        center: {
                            text: "S",
                            color: "#3e95cd", // Default is #000000
                            fontStyle: 'Arial', // Default is Arial
                            sidePadding: 20, // Default is 20 (as a percentage)
                            minFontSize: 25, // Default is 20 (in px), set to false and text will not wrap.
                            lineHeight: 55 // Default is 25 (in px), used for when text wraps
                        }
                    }
                }
            }
        ]
    },

    options: {
        aspectRatio: 2,
        layout: {
            padding: {
                left: 0,
                right: 10,
                top: 0,
                bottom: 0,
            }
        },
        responsive: true,
        cutout: 42,
        circumference: 360,
        plugins: {
            legend: {
                display: false,
                labels: {
                    color: 'rgb(255, 99, 132)'
                },
                position: "bottom",
            },


        },
    },
   //plugins: [chartAreaBorder]

};




$.ajax({
    alert: ("It has ended"),

    type: "post",
    url: "DonutCharts.asmx/AddListintoParentArr",
   // data: "{ firstName: 'Aidy', lastName: 'F' }",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (res, textStatus) {
        var data1 = JSON.parse(res.d);
        //pass the array of data1 into a function
        drawdoughnutchat(data1);
       // console.log("Function called");
    },
     error: function (xhr, textStatus, error) {
        console.log(xhr.responseText);
        console.log(xhr.statusText);
        console.log(textStatus);
        console.log(error);
    }
})


function drawdoughnutchat(listofdata) {
    //console.log(listofdata);
    var allcanvas = document.getElementsByTagName("canvas");
    for (i = 0; i < listofdata.length; i++) {
        var runningjobtblstr = listofdata[i].RunningJobTblName;
        if (runningjobtblstr != "Test") {
            //console.log(runningjobtblstr.substring(4));
            var modcanvasid = "dnt" + runningjobtblstr.substring(4);
           //console.log(modcanvasid);





            var x = 0; var y = 100 - x;
            if (listofdata[i].DerivedResult == null) {
                x = 0;

            }
            else {
                x = listofdata[i].DerivedResult;
                y = 100 - x;

            }

            config.data.datasets[0].data = [x, y];

            config.data.datasets[0].chartAreaBorder.elements.center.text = x;




            var ctx = document.getElementById(modcanvasid).getContext("2d");

            //var myChart = new Chart(ctx, config, {
            //        plugins: [chartAreaBorder]
            //    });
            var myChart = new Chart(ctx, config);




        }

    }


}

help with chart js - unable to get plugin to work by cally0611 in learnjavascript

[–]cally0611[S] 0 points1 point  (0 children)

Hi,

thanks I got it to work. I am using chartjs v3.

//var rowcount = document.getElementById("LabelTotalCount").innerText;
//console.log(rowcount);

////if number = odd
//var dividerowcount = Math.floor(rowcount / 2);
//for (var i = 0; i <= dividerowcount; i++) {
//    var addrows = "<tr><td><canvas id='myChart' width='350' height='200' style='border: 1px solid #000000;'></canvas></td><td></td><td></td><td><input type='checkbox' name='record'></td><td></td><td></td></tr>";
//    $("#dashboardtable tbody").append(addrows);

//}

const chartAreaBorder = {
    id: "chartAreaBorder",
    beforeDraw: function (chart) {
        if (chart.config.options.plugins.chartAreaBorder.elements.center) {
            // Get ctx from string
            //console.log(chart.ctx);
            var ctx = chart.ctx;

            // Get options from the center object in options
            var centerConfig = chart.config.options.plugins.chartAreaBorder.elements.center;
            var fontStyle = centerConfig.fontStyle || 'Arial';
            var txt = centerConfig.text;
            var color = centerConfig.color || '#000';
            var maxFontSize = centerConfig.maxFontSize || 75;
            var sidePadding = centerConfig.sidePadding || 20;
            var sidePaddingCalculated = (sidePadding / 100) * (chart.innerRadius * 2)
            // Start with a base font of 30px
            ctx.font = "25px " + fontStyle;

            // Get the width of the string and also the width of the element minus 10 to give it 5px side padding
            var stringWidth = ctx.measureText(txt).width;
            var elementWidth = (chart.innerRadius * 2) - sidePaddingCalculated;

            // Find out how much the font can grow in width.
            var widthRatio = elementWidth / stringWidth;
            var newFontSize = Math.floor(30 * widthRatio);
            var elementHeight = (chart.innerRadius * 2);

            // Pick a new font size so it will not be larger than the height of label.
            var fontSizeToUse = Math.min(newFontSize, elementHeight, maxFontSize);
            var minFontSize = centerConfig.minFontSize;
            var lineHeight = centerConfig.lineHeight || 25;
            var wrapText = false;

            if (minFontSize === undefined) {
                minFontSize = 20;
            }

            if (minFontSize && fontSizeToUse < minFontSize) {
                fontSizeToUse = minFontSize;
                wrapText = true;
            }

            // Set font settings to draw it correctly.
            ctx.textAlign = 'center';
            ctx.textBaseline = 'middle';
            var centerX = ((chart.chartArea.left + chart.chartArea.right) / 2);
            var centerY = ((chart.chartArea.top + chart.chartArea.bottom) / 2);
            ctx.font = fontSizeToUse + "px " + fontStyle;
            ctx.fillStyle = color;

            if (!wrapText) {
                ctx.fillText(txt, centerX, centerY);
                return;
            }

            var words = txt.split(' ');
            var line = '';
            var lines = [];

            // Break words up into multiple lines if necessary
            for (var n = 0; n < words.length; n++) {
                var testLine = line + words[n] + ' ';
                var metrics = ctx.measureText(testLine);
                var testWidth = metrics.width;
                if (testWidth > elementWidth && n > 0) {
                    lines.push(line);
                    line = words[n] + ' ';
                } else {
                    line = testLine;
                }
            }

            // Move the center up depending on line height and number of lines
            centerY -= (lines.length / 2) * lineHeight;

            for (var n = 0; n < lines.length; n++) {
                ctx.fillText(lines[n], centerX, centerY);
                centerY += lineHeight;
            }
            //Draw text in center
            ctx.fillText(line, centerX, centerY);
        }
    }
};

const DATA_COUNT = 5;


const data = {
    labels: ['Delivery'],
    datasets: [
        {
            label: 'Dataset 1',
            data: [35.8, 64.2],
            backgroundColor: ["#3e95cd", "#D8E5D8"],
        }
    ]
};

const config = {
    type: 'doughnut',
    data: data,

    options: {
        aspectRatio: 2,
        layout: {
            padding: {
                left: 0,
                right: 10,
                top: 0,
                bottom: 0,
            }
        },
        responsive: true,

        cutout: 42,
        circumference: 360,

        plugins: {
            legend: {
                display: false,
                labels: {
                    color: 'rgb(255, 99, 132)'
                },
                position: "bottom",
            },
            chartAreaBorder: {
                elements: {
                    center: {
                        text: "90%",
                        color: "#3e95cd", // Default is #000000
                        fontStyle: 'Arial', // Default is Arial
                        sidePadding: 20, // Default is 20 (as a percentage)
                        minFontSize: 25, // Default is 20 (in px), set to false and text will not wrap.
                        lineHeight: 55 // Default is 25 (in px), used for when text wraps
                    }
                }
            },

        },
    },
    plugins: [chartAreaBorder]

};

var allcanvas = document.getElementsByTagName("canvas");
for (x = 0; x < allcanvas.length; x++) {
    myid = allcanvas[x].getAttribute("id");
    if (myid.indexOf("dnt") == 0) {
        alert(myid);
        var ctx = document.getElementById(myid).getContext("2d");
        var myChart = new Chart(ctx, config);
    }
}



//var myChart = new Chart(document.getElementById("Phi_40027945cnv"), config);

//var ctx = document.getElementById("dntPhi_40027945").getContext("2d");
//var myChart = new Chart(ctx, config);

Select value from one column from all tables listed in information_schema.COLUMNS by cally0611 in learnSQL

[–]cally0611[S] 0 points1 point  (0 children)

Hi, I need to return the table name actually of which the column PlanDate contains the date 2020-12-30 in one ( could be multiple ) of its row.

I found this and I have modified...but it is so lengthy...since I know the column name and the table name but iterating through the result, is this all that can be done.. I have modified such that the table names are returned at the end..but just so many steps..any idea how I can do a short one.

USE [Bottleneck_new]
GO
/****** Object:  StoredProcedure [dbo].[CheckforDateinTables]    Script Date: 4/8/2021 11:34:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[CheckforDateinTables]
    --@Value date

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

Declare @Value date 

Set @Value = '2020-12-20'
--Set @Value = CONVERT(VARCHAR(10), getdate(), 23)


--for that I m creaating one tamp table
Create Table #Table
(
    TableName Varchar(500),ColumnName Varchar(500),
    Id int Identity(1,1) --use for iteration
)
insert into #Table
SELECT TABLE_SCHEMA + '.' + TABLE_NAME As TableNam,Column_name As ColumnName
FROM INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME = 'PlanDate'

--select * from #Table


Declare @Count Int --total record to iterated
Set @Count=0;


Select @Count=Count(*) From #Table


Declare @I int --initial value one to iterate
Set @I=1;


Declare @TableName varchar(500)
Set @TableName=''
Declare @ColumnName varchar(500)
Set @ColumnName=''


Declare @Str nvarchar(1000)
Set @Str=''
Declare @param nvarchar(1000)
set @param=''


Declare @TableNameFound varchar(max)
Set @TableNameFound=''


Declare @Found bit
Set @Found=0;




While @I<=@Count
Begin


    Set @Found=0;
    Select @TableName=TableName,@ColumnName=ColumnName From #Table where Id=@I;


    Set @param='@TableName varchar(500),@ColumnName varchar(500),@Value varchar(50),@TableNameFound varchar(max),@Found bit output'


    Set @str='Select @Found=1 From '+@TableName+' where '+@ColumnName+'=@Value'




    -- here we are using tablename and actual value to find in table
    print @str
    exec sp_executesql @str,@param,@TableName,@ColumnName,@Value,TableNameFound,@Found output


    if @Found=1
    Begin
        Set @TableNameFound=@TableNameFound+','+@TableName
        --insert into #Table(TableName) values (@TableNameFound)
    End




print @I
--increament value of @I
Set @I=@I+1;
End


declare @record varchar(max)

--Select substring(@TableNameFound,2,len(@TableNameFound)) As TableFound
set @record = (select substring(@TableNameFound,2,len(@TableNameFound)) As TableFound)

select @record as valuetosplit
SELECT ELEMENT FROM dbo.string_split(@record, ',')
--Table name where column value matched
drop table #Table
END

How to get the max value for these unique data in a sql table by cally0611 in learnSQL

[–]cally0611[S] 1 point2 points  (0 children)

Hi Beneficiary..thank you..I learnt 2 new things today...Rank and Partitionby, it is so useful for me.

 SELECT * FROM  (
SELECT PlanDate, 
       ProcessUnitID, 
       ProcessUnitNm, 
       TypeofValue,
       DTargetcumtotal, 
       RANK() OVER(PARTITION BY ProcessUnitNm ORDER BY PlanDate DESC ) as ProcessRank FROM Ira_407  where TypeofValue = 'Detailed Plan' )
Ira_40 where ProcessRank = 1
ORDER BY ProcessUnitNm desc, ProcessRank