Search This Blog

Thursday, June 18, 2015

Remove border Telerik RadGridView

Telerik > RadGridView > Remove border

radGridView1.GridViewElement.DrawBorder = false;
radGridView1.GridViewElement.GroupPanelElement.DrawBorder = false;






Monday, June 15, 2015

KeyNotFoundException Collection C# Example

Collections > Generic > KeyNotFoundException 

This is thrown when try to retrieve an element from a collection using a key that does not exist in that collection.

Example

   Dictionary<string, string> dict = new Dictionary<string, string>();
   dict.Add("key1","value1");
   try
   {
       string val = dict["key2"];
   }
   catch (KeyNotFoundException)
   {
       throw new KeyNotFoundException("KeyNotFoundException!");

   }





Wednesday, May 20, 2015

Print PictureBox Image C# Example Using PrintDocument

C# > Print  > PrintDocument

PrintDocument sends out to the printer.


Example

Print image



using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(pictureBox1.Image, 100, 100, 700, 600);
        }
    }
}





Tuesday, May 19, 2015

System tables SQL Server

SQL Server > System tables








Monday, May 18, 2015

Subtract SQL Server example

SQL Server > Operators > Subtract

- Operator (minus) subtracts two numbers or a number (in days) from date.





Example

1. Subtracts values from 2 numeric columns

create table #test(value int, fee int)
insert into #test(value, fee) values (500,50),(100,10)
  select 
   value - fee as 'diff'
  from 
   #test
drop table #test

Result
diff
450
90

2. Subtracts from date

SELECT getdate() - 1 AS 'Subtract Date';





C# unit test using Moq verify property has been set

C# > Unit test > Moq > Verify property has been set

SetupSet : Specifies a setup on the mocked type for a call to a property setter.
VerifySet : Verifies that a property has been set on the mock, regardless of its value.

Example

using System;

namespace UnitTestProject1
{
    public interface Interface1
    {
        int Id { get; set; }
    }
}

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            var mocker = new Mock<Interface1>();
            mocker.SetupSet(x => x.Id = 1);
            mocker.Object.Id = 1;
            mocker.VerifySet(x => x.Id);
        }
    }
}





Friday, May 15, 2015

Convert string to date C# example

C# > System Namespace > DateTime > Parse

Parse converts string to a date.


Example


string value = "5/15/2015";

var dte = DateTime.Parse(value, CultureInfo.InvariantCulture); // {5/15/2015 12:00:00 AM}