How to resolve development Issues in C# Language ? - CodingPot | Programming Blog - C#, VB.Net, ASP.Net, MVC, Angularjs Tutorials

Sunday, 27 August 2017

How to resolve development Issues in C# Language ?

Hello Friend's, Today we will see development issues. This post is very useful for web development and software development.In this post, we will see how to resolve some development issues that are develop using C# Language.


                   Resolve Development Issues using C#



How to keep form centered to the middle of the screen after resize ?


Add method for ResizeEnd event. In method, when ResizeEnd is fired, get current screen size (on multiple monitors, screen that contains current form) and then calculate form's position. Take a look at this example

private void Form1_ResizeEnd(object sender, EventArgs e)
{
    Screen myScreen = Screen.FromControl(this);
    Rectangle area = myScreen.WorkingArea;

    this.Top = (area.Height - this.Height) / 2;
    this.Left = (area.Width - this.Width) / 2;
}


How to calculate sum of group values using C# Dictionary?

You could just iterate through the Dictionary using foreach as follows:
public override decimal CalculateDiscount(IDictionary<myObject, int> items)
{
    if (items == null) throw new ArgumentNullException(nameof(items));

    foreach (var kvp in items)
    {
        if (kvp.Key.Discount.Count == kvp.Value)
            _totalDiscount += kvp.Key.Discount.Price;
    }
    return _totalDiscount;
}

How to Hiding a particular row in grid view using different buttons?

You can try this, But first you need to identify which row you wanted to hide.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    
{    
    Label YourControl= (Label)e.Row.FindControl("YourControl");    
    if (YourControl != null)    
    {    
        if (YourControl.Text.Trim() == "0")    
        {    
            LinkButton YourControl= (LinkButton)e.Row.FindControl("YourControl");    
            YourControl.Visible = false;    
        }

    }

}


How to Read Related Data Using LINQ/C# [one to many]?


You should be using Where instead of SelectMany:
var result = _context.PatPar.Where(m => m.FileId == id);
SelectMany is used to retrieve a collection from each item of the iterated collection. However your condition is to check if the FileId equals some id - the resulted type is a boolean. I assume what you are trying to do is return all the times that have that FileId.
To have it with the await:
var result = await _context.PatPar.Where(m => m.FileId == id).ToListAsync();


How to Creating an exe for a Windows standalone application using C# in Visual Studio 2015?

Just download the Setup project templates and create an installer:
See my extensive guide here on how to make an Installer (one that upgrades itself as well): Install to same path when upgrading application


How to deserialize nested json?


Assuming your model class is defined like this:

public class DeviceInfo
{
    public string DeviceName { get; set; }
    public string TurbineName { get; set; }
    public string State { get; set; }
    public string TurbineType { get; set; }
    public string Version { get; set; }
}
Then, for the first JSON, you can deserialize like this:
var device = JsonConvert.DeserializeObject<DeviceInfo>(json);
And for the second case, you can deserialize to a dictionary, where the keys are the IP addresses, and the values are the devices:
var dict = JsonConvert.DeserializeObject<Dictionary<string, DeviceInfo>>(json2);


How to insert data into local SQL Server database from ASP.NET?

SqlCommand cmd = new SqlCommand("insert into [Table] (fname, lname, city) 
values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')", con);



How to choose which extensions do not encrypt?

foreach (string file in files)
{ 
   var escapeExtensions = new[] { ".dat" };
   string extension =Path.GetExtension(abc);
   if(!escapeExtensions.Contains(extension))
   { 
      EncryptFile(file, password); 
   }
}
References...


Notes : Above all solutions are from stackoverflow.com and solutions are briefly available at
            stackoverflow.com.

No comments:

Post a Comment