Search This Blog

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}




Thursday, May 14, 2015

Find last row Telerik RadGridView

Telerik > RadGridView > Find last row
GridViewRowInfo lastRow = radGridView.Rows[radGridView.Rows.Count - 1];
lastRow.IsSelected = true;






Wednesday, May 13, 2015

C# Generic Interface Example

C# > Generics > Generic Interface 

Example


class Serializer1 { public string Name { get; set; } };
class Serializer2 { public string Name { get; set; } };

interface GenericSerializer<T>
{
      string Name(T tValue);
}

class Serializer<T>: GenericSerializer<T>
{
public string Name(T tValue)
        {
            var prop = tValue.GetType().GetProperty("Name");
            return prop.GetValue(tValue, null) as string;
        }
}

Serializer1 s1 = new Serializer1() { Name = "Serializer1" };
Serializer2 s2 = new Serializer2() { Name = "Serializer2" };

Serializer<Serializer1> serializer1 = new Serializer<Serializer1>();
string name1 = serializer1.Name(s1);

Serializer<Serializer2> serializer2 = new Serializer<Serializer2>();

string name2 = serializer2.Name(s2);