Thursday, April 17, 2014

Create Identity Card for like Membership in C# windows application










 










 Codebehind C#:


public static  Bitmap CreateFirstCard(string Name,string MembNo,string Mobile,string Phone,
          Bitmap objBmpImage, Image img ,int Width,int Height )
      {
          //Bitmap objBmpImage = new Bitmap(pbPhoto.Width, pbPhoto.Height);

          int intWidth = Width;
          int intHeight = Height;

          // Create the Font object for the image text drawing.
          System.Drawing.Font objFont = new System.Drawing.Font("Arial", 13, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);

          // Create a graphics object to measure the text's width and height.
          Graphics objGraphics = Graphics.FromImage(objBmpImage);

       

          // Create the bmpImage again with the correct size for the text and font.
          //objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight));


          // Add the colors to the new bitmap.
          objGraphics = Graphics.FromImage(objBmpImage);

          // Set Background color

          //objGraphics.Clear(System.Drawing.Color.White);
          objGraphics.SmoothingMode = SmoothingMode.HighQuality;



          objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;

          objGraphics.DrawString(Name, objFont, new SolidBrush(System.Drawing.Color.Black), 95, 75, StringFormat.GenericDefault);

          objGraphics.DrawString(MembNo, objFont, new SolidBrush(System.Drawing.Color.Black), 157, 95, StringFormat.GenericDefault);

          objGraphics.DrawString(Phone, objFont, new SolidBrush(System.Drawing.Color.Black), 95, 120, StringFormat.GenericDefault);

          objGraphics.DrawString(Mobile, objFont, new SolidBrush(System.Drawing.Color.Black), 105, 140, StringFormat.GenericDefault);


          System.Drawing.Rectangle rec = new System.Drawing.Rectangle(310, 70, 102, 94);
          objGraphics.DrawImage(img, rec);

          objGraphics.Flush();

          return (objBmpImage);
      }

      public static Bitmap CreateSecondCard(string Address,string DOB,string BG,
          Bitmap objBmpImage, Image img, int Width, int Height)
      {
          //Bitmap objBmpImage = new Bitmap(pbPhoto.Width, pbPhoto.Height);

          int intWidth = Width;
          int intHeight = Height;

          // Create the Font object for the image text drawing.
          System.Drawing.Font objFont = new System.Drawing.Font("Arial", 13, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);

          // Create a graphics object to measure the text's width and height.
          Graphics objGraphics = Graphics.FromImage(objBmpImage);

      

          // Create the bmpImage again with the correct size for the text and font.
          //objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight));


          // Add the colors to the new bitmap.
          objGraphics = Graphics.FromImage(objBmpImage);

          // Set Background color

          //objGraphics.Clear(System.Drawing.Color.White);
          objGraphics.SmoothingMode = SmoothingMode.HighQuality;



          objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;

          objGraphics.DrawString(Address.TrimStart(), objFont, new SolidBrush(System.Drawing.Color.Black), 157, 32, StringFormat.GenericDefault);

          objGraphics.DrawString(DOB, objFont, new SolidBrush(System.Drawing.Color.Black), 157, 72, StringFormat.GenericDefault);

          objGraphics.DrawString(BG, objFont, new SolidBrush(System.Drawing.Color.Black), 157, 100, StringFormat.GenericDefault);


          objGraphics.Flush();

          return (objBmpImage);
      }

private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                SqlCommand cmd;

                if (con.con.State == ConnectionState.Closed)
                {
                    con.con.Open();
                }

                System.IO.FileInfo imageInfo;

               

                da = new SqlDataAdapter("select * from MembershipCard where CardNO='" + cmbMemberNo.Text + "'", con.con);
                ds = new DataSet();
                da.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    int.TryParse(ds.Tables[0].Rows[0]["Id"].ToString(), out Id);
                    Photocontent = (byte[])ds.Tables[0].Rows[0]["Photo"];
                    ThumbPhotocontent = (byte[])ds.Tables[0].Rows[0]["ThumbPhoto"];

                    pbImage.Image = CommonFunctions.byteArrayToImage(Photocontent);

                    pbPhoto.Image = Properties.Resources.ID_card_3;
                    pbPhoto2.Image = Properties.Resources.ID_card_4;

                    da = new SqlDataAdapter("select SlNo,TITLE,MEMBNO,NAME,ADDR1,ADDR2,ROAD,CITY,PIN,BLOODGRP,PHONE,MOBILE from " +
                                                                               "Members where MEMBNO='" + cmbMemberNo.Text + "'", con.con);
                    ds = new DataSet();
                    da.Fill(ds);

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        lblMembNo.Text = cmbMemberNo.Text;
                        lblName.Text = ds.Tables[0].Rows[0]["TITLE"].ToString() + " " + ds.Tables[0].Rows[0]["NAME"].ToString();
                        lblAddress.Text = ds.Tables[0].Rows[0]["ADDR1"].ToString() + "\r\n" +
                                          ds.Tables[0].Rows[0]["ADDR2"].ToString() +
                                          ds.Tables[0].Rows[0]["CITY"].ToString() + "\r\n";
                        lblAddress.Text = ds.Tables[0].Rows[0]["ROAD"].ToString() == "" ? lblAddress.Text + ds.Tables[0].Rows[0]["PIN"].ToString() :
                                            lblAddress.Text + ds.Tables[0].Rows[0]["ROAD"].ToString() + " - " + ds.Tables[0].Rows[0]["PIN"].ToString();

                        lblBg.Text = ds.Tables[0].Rows[0]["BLOODGRP"].ToString() == "" ? "" : ds.Tables[0].Rows[0]["BLOODGRP"].ToString();
                        lblMobile.Text = ds.Tables[0].Rows[0]["MOBILE"].ToString();
                        lblPhone.Text = ds.Tables[0].Rows[0]["PHONE"].ToString();
                        lbldob.Text = "";
                    }

                }
                else
                {
                    Id = 0;
                }

                if (txtFileName.Text == "")
                {
                    if (Photocontent.Length == 0)
                    {
                        imageInfo = new System.IO.FileInfo(Path.GetDirectoryName(
                                                                            System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\face_outline.gif");

                        Photocontent = new byte[imageInfo.Length];
                        imagestream = imageInfo.OpenRead();
                        imagestream.Read(Photocontent, 0, Photocontent.Length);

                        ThumbPhotocontent = CommonFunctions.createThumnail(imagestream, 50, 50);
                        pbImage.Image = CommonFunctions.byteArrayToImage(Photocontent);
                    }
                    else if (clearflag == true)
                    {
                        imageInfo = new System.IO.FileInfo(Path.GetDirectoryName(
                                                                           System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\face_outline.gif");

                        Photocontent = new byte[imageInfo.Length];
                        imagestream = imageInfo.OpenRead();
                        imagestream.Read(Photocontent, 0, Photocontent.Length);

                        ThumbPhotocontent = CommonFunctions.createThumnail(imagestream, 50, 50);
                        pbImage.Image = CommonFunctions.byteArrayToImage(Photocontent);
                    }
                    //imagestream.Close();
                }
                else
                {
                    imageInfo = new System.IO.FileInfo(txtFileName.Text);

                    Photocontent = new byte[imageInfo.Length];
                    imagestream = imageInfo.OpenRead();
                    imagestream.Read(Photocontent, 0, Photocontent.Length);

                    pbImage.Image = CommonFunctions.byteArrayToImage(Photocontent);

                    ThumbPhotocontent = CommonFunctions.createThumnail(imagestream, 50, 50);

                    //imagestream.Close();
                }

               

                //contain our picturebox image bytes.
                MemoryStream stream = new MemoryStream();
                //through the instruction below, we save the
                //image to byte in the object "stream".
                //pbPhoto.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);

                //pbPhoto.Image.Save(@"E:\Members\Member1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

                Bitmap bmp = new Bitmap(pbPhoto.Image, pbPhoto.Width, pbPhoto.Height);

                string AppPath = System.IO.Path.GetDirectoryName(
                                 System.Reflection.Assembly.GetExecutingAssembly().Location);

                bool isExists = System.IO.Directory.Exists(AppPath + @"\Members");

                if (!isExists)
                    System.IO.Directory.CreateDirectory(AppPath + @"\Members");

                bmp.Save(AppPath + @"\Members\Member1.bmp");

                Bitmap bmp1 = CommonFunctions.CreateFirstCard(lblName.Text,lblMembNo.Text,lblMobile.Text,lblPhone.Text,
                    bmp, pbImage.Image,pbPhoto.Width,pbPhoto.Height);
               
                bmp1.Save(AppPath + @"\Members\" + lblName.Text  + "1.bmp");

                Bitmap bmp2 = new Bitmap(pbPhoto2.Image, pbPhoto2.Width, pbPhoto2.Height);

                bmp2.Save(AppPath + @"\Members\Member2.bmp");

                Bitmap bmp3 = CommonFunctions.CreateSecondCard(lblAddress.Text,lbldob.Text,lblBg.Text,
                    bmp2, pbImage.Image,pbPhoto2.Width,pbPhoto2.Height);

                bmp3.Save(AppPath + @"\Members\" + lblName.Text + "2.bmp");

                imageInfo = new System.IO.FileInfo(AppPath + @"\Members\" + lblName.Text + "1.bmp");
                Cardcontent = new byte[imageInfo.Length];
                imagestream = imageInfo.OpenRead();
                imagestream.Read(Cardcontent, 0, Cardcontent.Length);


                imageInfo = new System.IO.FileInfo(AppPath + @"\Members\" + lblName.Text + "2.bmp");
                Cardcontent2 = new byte[imageInfo.Length];
                imagestream = imageInfo.OpenRead();
                imagestream.Read(Cardcontent2, 0, Cardcontent2.Length);


                //if (cmbStatus.Text != "Select")
                {

                    cmd = new SqlCommand("MembershipCard_Insert_SP", con.con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    if (Id != 0)
                    {


                        cmd.Parameters.Add("@Opt", SqlDbType.BigInt).Value = 2;
                        cmd.Parameters.Add("@Id", SqlDbType.BigInt).Value = Id;

                    }
                    else
                    {
                        cmd.Parameters.Add("@Opt", SqlDbType.BigInt).Value = 1;
                        cmd.Parameters.Add("@Id", SqlDbType.BigInt).Value = 1;
                    }


                    cmd.Parameters.Add("@CardNO", SqlDbType.NVarChar, 50).Value = cmbMemberNo.Text;
                    cmd.Parameters.Add("@Photo", SqlDbType.Image).Value = Photocontent;
                    cmd.Parameters.Add("@ThumbPhoto", SqlDbType.Image).Value = ThumbPhotocontent;
                    cmd.Parameters.Add("@MembershipCard", SqlDbType.Image).Value = Cardcontent;
                    cmd.Parameters.Add("@MembershipCard2", SqlDbType.Image).Value = Cardcontent2;
                    cmd.Parameters.Add("@CardStatus", SqlDbType.NVarChar, 50).Value = "Card ready";// cmbStatus.Text;

                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Data saved successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                //string template = "Your Membershipcard is ready. Please collect from Office." +
                //                   "\r\n " +
                //                   "General Secretary, Ernakulam Karayogam.";

                //if (con.con.State == ConnectionState.Closed)
                //{
                //    con.con.Open();
                //}

                //cmd = new SqlCommand("select SmsText from SmsMaster where Id=5", con.con);
                //string template = cmd.ExecuteScalar().ToString();

                //string Message = template;

                //System.Diagnostics.Process proc = new System.Diagnostics.Process();
                //proc.EnableRaisingEvents = false;
                //proc.StartInfo.FileName = "iexplore";
                //proc.StartInfo.Arguments = "http://bulksmsalert.in/SendSms.aspx?username=ekmkgm&password=ekmkgm25&to=" + txtMobile.Text + "&from=ekmkgm&message=" + Message + "";
                //proc.Start();

                clearflag = false;
                cmbMemberNo.Text = "";
                txtFileName.Text = "";
                lblName.Text = "";
                lblMembNo.Text = "";
                lblPhone.Text = "";
                lblMobile.Text = "";
                lblAddress.Text = "";
                lbldob.Text = "";
                lblBg.Text = "";
                pbImage.Image = null;
                con.con.Close();


            }
            catch (Exception ex)
            {
                ErrorLog.WriteErrorLog(ErrorLog.GetLogFilePath(), ex);
            }
        }

Create Thumbnail in C# windows application

//This function creates the Thumbnail image and returns the
      //image created in Byte() format
      public static byte[] createThumnail(Stream ImageStream, Double tWidth, Double tHeight)
      {
          System.Drawing.Image g = System.Drawing.Image.FromStream(ImageStream);
          Size thumbSize = new Size();
          thumbSize = NewThumbSize(g.Width, g.Height, tWidth, tHeight);
          Bitmap imgOutput = new Bitmap(g, thumbSize.Width, thumbSize.Height);
          MemoryStream imgStream = new MemoryStream();
          System.Drawing.Imaging.ImageFormat thisFormat = g.RawFormat;
          imgOutput.Save(imgStream, thisFormat);
          int imgBinLength = (int)imgStream.Length;
          byte[] imgBin = new byte[imgBinLength];
          imgStream.Position = 0;
          int n = imgStream.Read(imgBin, 0, imgBinLength);
          g.Dispose();
          imgOutput.Dispose();
          return imgBin;
      }
      public static Size NewThumbSize(Double currentwidth, Double currentheight, Double newWidth, Double newHeight)
      {
          //Calculate the Size of the New image
          Double tempMultiplier;
          if (currentheight > currentwidth)        // Then it's portrait
          {
              tempMultiplier = newHeight / currentheight;
          }
          else
          {
              tempMultiplier = newWidth / currentwidth;
          }

          Size NewSize = new Size(Convert.ToInt16(currentwidth * tempMultiplier), Convert.ToInt16(currentheight * tempMultiplier));
          return NewSize;
      }


      public static Image byteArrayToImage(byte[] byteArrayIn)
      {
          MemoryStream ms = new MemoryStream(byteArrayIn);
          Image returnImage = Image.FromStream(ms);
          return returnImage;
      }

Export DataTable To Excel in c# windows application

 public static void ExportDTToExcel(System.Data.DataTable dt,string FileName)
      {

        Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
        app.Visible = false; 

        Workbook wb = app.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);

        Worksheet ws = (Worksheet)wb.ActiveSheet; 
        
        // Headers.

        for (int i = 1; i < dt.Columns.Count; i++)
        {
          ws.Cells[1, i] = dt.Columns[i].ColumnName;
        } 

        // Content.

        for (int i = 0; i < dt.Rows.Count; i++)
        {

          for (int j = 1; j < dt.Columns.Count; j++)
          {

            ws.Cells[i + 2, j ] = dt.Rows[i][j].ToString();

          }

        } 

        // Lots of options here. See the documentation.

        wb.SaveAs(FileName );


        wb.Close();

        app.Quit();

      }

SMS Gateway Integration in windows application


                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.EnableRaisingEvents = false;
                    proc.StartInfo.FileName = "iexplore";
                    proc.StartInfo.Arguments = "http://bulksmsalert.in/SendSms.aspx?username=ekmkgm&password=ekmkgm25&to=" + txtMobile.Text + "&from=ekmkgm&message=" + Message + "";
                    proc.Start();

Label Printing using C# windows application





RDLC XML Code for Design:

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">
  <DataSources>
    <DataSource Name="LMSDataSet">
      <ConnectionProperties>
        <DataProvider>System.Data.DataSet</DataProvider>
        <ConnectString>/* Local Connection */</ConnectString>
      </ConnectionProperties>
      <rd:DataSourceID>dc9db719-e783-439b-8a6a-21c2d68ef8d9</rd:DataSourceID>
    </DataSource>
  </DataSources>
  <DataSets>
    <DataSet Name="LabelDataSet">
      <Fields>
        <Field Name="SlNo">
          <DataField>SlNo</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="TITLE">
          <DataField>TITLE</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="MEMBNO">
          <DataField>MEMBNO</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="NAME">
          <DataField>NAME</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="ADDR1">
          <DataField>ADDR1</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="ADDR2">
          <DataField>ADDR2</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="CITY">
          <DataField>CITY</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="ROAD">
          <DataField>ROAD</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="PHONE">
          <DataField>PHONE</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="PIN">
          <DataField>PIN</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
      </Fields>
      <Query>
        <DataSourceName>LMSDataSet</DataSourceName>
        <CommandText>/* Local Query */</CommandText>
      </Query>
      <rd:DataSetInfo>
        <rd:DataSetName>LabelManagementSystem</rd:DataSetName>
        <rd:TableName>AddressDetailsDataTable</rd:TableName>
        <rd:ObjectDataSourceType>LabelManagementSystem.LMSDataSet+AddressDetailsDataTable, LMSDataSet.Designer.cs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>
      </rd:DataSetInfo>
    </DataSet>
  </DataSets>
  <Body>
    <ReportItems>
      <Tablix Name="Tablix2">
        <TablixBody>
          <TablixColumns>
            <TablixColumn>
              <Width>2.67717in</Width>
            </TablixColumn>
          </TablixColumns>
          <TablixRows>
            <TablixRow>
              <Height>1.3061in</Height>
              <TablixCells>
                <TablixCell>
                  <CellContents>
                    <Rectangle Name="Rectangle1">
                      <ReportItems>
                        <Tablix Name="Tablix1">
                          <TablixBody>
                            <TablixColumns>
                              <TablixColumn>
                                <Width>2.67717in</Width>
                              </TablixColumn>
                            </TablixColumns>
                            <TablixRows>
                              <TablixRow>
                                <Height>1.1811in</Height>
                                <TablixCells>
                                  <TablixCell>
                                    <CellContents>
                                      <Textbox Name="Name">
                                        <CanGrow>true</CanGrow>
                                        <KeepTogether>true</KeepTogether>
                                        <Paragraphs>
                                          <Paragraph>
                                            <TextRuns>
                                              <TextRun>
                                                <Value>=System.Environment.NewLine+System.Environment.NewLine+ trim(IIF(Fields!MEMBNO.Value="","",Fields!MEMBNO.Value)) +UCase(trim(IIF(Fields!NAME.Value="","",System.Environment.NewLine+Fields!TITLE.Value+". "+Fields!NAME.Value)) +Trim(IIF(Fields!ADDR1.Value="","",System.Environment.NewLine+ Fields!ADDR1.Value))+Trim(IIF(Fields!ADDR2.Value="","",System.Environment.NewLine+ Fields!ADDR2.Value))+Trim(IIF(Fields!ROAD.Value="","",System.Environment.NewLine+ Replace(Fields!ROAD.Value,",","")))  +Trim(IIF(Fields!CITY.Value="","",System.Environment.NewLine+ Replace(Fields!CITY.Value,",","")))+Trim(IIF(Fields!PIN.Value="","","-"+Replace(Fields!PIN.Value,",",""))))</Value>
                                                <Style>
                                                  <FontFamily>Times New Roman</FontFamily>
                                                  <FontSize>9pt</FontSize>
                                                </Style>
                                              </TextRun>
                                            </TextRuns>
                                            <Style />
                                          </Paragraph>
                                        </Paragraphs>
                                        <rd:DefaultName>Name</rd:DefaultName>
                                        <Style>
                                          <Border>
                                            <Color>White</Color>
                                            <Style>Solid</Style>
                                          </Border>
                                        </Style>
                                      </Textbox>
                                      <rd:Selected>true</rd:Selected>
                                    </CellContents>
                                  </TablixCell>
                                </TablixCells>
                              </TablixRow>
                            </TablixRows>
                          </TablixBody>
                          <TablixColumnHierarchy>
                            <TablixMembers>
                              <TablixMember>
                                <Group Name="ColumnGroup">
                                  <GroupExpressions>
                                    <GroupExpression>=RowNumber("list1_Details_Group")</GroupExpression>
                                  </GroupExpressions>
                                </Group>
                              </TablixMember>
                            </TablixMembers>
                          </TablixColumnHierarchy>
                          <TablixRowHierarchy>
                            <TablixMembers>
                              <TablixMember>
                                <TablixMembers>
                                  <TablixMember />
                                </TablixMembers>
                              </TablixMember>
                            </TablixMembers>
                          </TablixRowHierarchy>
                          <KeepTogether>true</KeepTogether>
                          <DataSetName>ListDS</DataSetName>
                          <Height>2.99999cm</Height>
                          <Width>6.80001cm</Width>
                          <Style>
                            <Border>
                              <Color>White</Color>
                              <Style>Solid</Style>
                            </Border>
                            <Color>White</Color>
                          </Style>
                        </Tablix>
                      </ReportItems>
                      <KeepTogether>true</KeepTogether>
                      <Style>
                        <Border>
                          <Style>None</Style>
                        </Border>
                      </Style>
                    </Rectangle>
                  </CellContents>
                </TablixCell>
              </TablixCells>
            </TablixRow>
          </TablixRows>
        </TablixBody>
        <TablixColumnHierarchy>
          <TablixMembers>
            <TablixMember />
          </TablixMembers>
        </TablixColumnHierarchy>
        <TablixRowHierarchy>
          <TablixMembers>
            <TablixMember>
              <Group Name="list1_Details_Group">
                <GroupExpressions>
                  <GroupExpression>=Ceiling(RowNumber(Nothing)/3)</GroupExpression>
                </GroupExpressions>
              </Group>
            </TablixMember>
          </TablixMembers>
        </TablixRowHierarchy>
        <KeepTogether>true</KeepTogether>
        <DataSetName>LabelDataSet</DataSetName>
        <Left>1.28796cm</Left>
        <Height>3.31749cm</Height>
        <Width>6.80001cm</Width>
        <Style>
          <Border>
            <Style>None</Style>
          </Border>
        </Style>
      </Tablix>
    </ReportItems>
    <Height>33.91957cm</Height>
    <Style />
  </Body>
  <Width>8.08797cm</Width>
  <Page>
    <PageHeight>29.7cm</PageHeight>
    <PageWidth>21cm</PageWidth>
    <LeftMargin>2.54cm</LeftMargin>
    <RightMargin>2.54cm</RightMargin>
    <TopMargin>1.27cm</TopMargin>
    <BottomMargin>1.27cm</BottomMargin>
    <Columns>3</Columns>
    <ColumnSpacing>0.3cm</ColumnSpacing>
    <Style />
  </Page>
  <rd:ReportID>a4333754-f838-4002-9f3b-41e041186bf6</rd:ReportID>
  <rd:ReportUnitType>Cm</rd:ReportUnitType>
</Report>

Codebehind C#:

   private void FillReport(DataTable dt)
        {
            reportViewer1.ProcessingMode = ProcessingMode.Local;           
            reportViewer1.LocalReport.ReportPath = System.IO.Path.GetDirectoryName(
                System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Sowhridam.rdlc";
            reportViewer1.LocalReport.DataSources.Add(new ReportDataSource(reportViewer1.LocalReport.GetDataSourceNames()[0], dt));
            this.reportViewer1.RefreshReport();
        }

Paging in DataGridView of Windows Application

Preview of Paging Control
Add Toolstrip and change properties like above



























Codebehind:

 private void FillGrid(string SortColumn)
        {

            if (con.con.State == ConnectionState.Closed)
            {
                con.con.Open();
            }
            string City = "" ;
            string PinCode = "" ;
            string PostOffice =  "" ;
            string District ="" ;
            string State =  "";
            string Name = cmbName.Text == "Select" ? "" : cmbName.Text;
            string MEMBNO = cmbMemberNo.Text == "Select" ? "" : cmbMemberNo.Text;
            string BloodGroup =  "" ;

            string query = "";
            query = "SELECT * FROM( select row_number() OVER (ORDER BY " + SortColumn + ") AS SlNo,SlNo as Id,TITLE," +
                    " MEMBNO,NAME,ADDR1,ADDR2,ROAD,CITY," +
                    " PIN,BLOODGRP,PHONE,ThumbPhoto from Members " +
                    "left join MembershipCard  on MEMBNO=CardNO " +
                    "where CITY like '%" + City + "%' and  PIN like '%" + PinCode + "%' and  ROAD like '%" + PostOffice + "%' " +
                    "and NAME like '%" + Name + "%' and MEMBNO like '%" + MEMBNO + "%' and BLOODGRP like '%" + BloodGroup +
                    "%'  and Status=1 ) AS alias  WHERE  SlNo BETWEEN (@PageIndex - 1) * @PageSize + 1 " +
                    " AND @PageIndex * @PageSize  order by " + SortColumn + " asc ";
            query = query.Replace("@PageSize", pageRows.ToString());
            query = query.Replace("@PageIndex", CurrentPage.ToString());

            SqlDataAdapter da = new SqlDataAdapter(query, con.con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dt = ds.Tables[0];

         

            dt1 = new DataTable();
            dt1.Columns.Add("Select", System.Type.GetType("System.Boolean"));
            dt1.Columns.Add("SlNo");
            dt1.Columns.Add("Id");
            dt1.Columns.Add("TITLE");
            dt1.Columns.Add("MEMBNO");
            dt1.Columns.Add("NAME");
            dt1.Columns.Add("ADDR1");
            dt1.Columns.Add("ADDR2");
            dt1.Columns.Add("ROAD");
            dt1.Columns.Add("CITY");
            dt1.Columns.Add("PIN");
            dt1.Columns.Add("BLOODGRP");
            dt1.Columns.Add("PHONE");
            //dt1.Columns.Add("Photo", typeof(Bitmap));
            //dt1.Columns["Photo"].AllowDBNull = true;


            tempdt = new DataTable();
            tempdt.Columns.Add("Select", System.Type.GetType("System.Boolean"));
            tempdt.Columns.Add("SlNo");
            tempdt.Columns.Add("Id");
            tempdt.Columns.Add("TITLE");
            tempdt.Columns.Add("MEMBNO");
            tempdt.Columns.Add("NAME");
            tempdt.Columns.Add("ADDR1");
            tempdt.Columns.Add("ADDR2");
            tempdt.Columns.Add("ROAD");
            tempdt.Columns.Add("CITY");
            tempdt.Columns.Add("PIN");
            tempdt.Columns.Add("BLOODGRP");
            tempdt.Columns.Add("PHONE");
            //tempdt.Columns.Add("Photo", typeof(Bitmap));
            //tempdt.Columns["Photo"].AllowDBNull = true;

            DataRow dr;

            for (int i = 0; i <= dt.Rows.Count - 1; i++)
            {
                dr = dt1.NewRow();

                dr["Select"] = false;
                dr["SlNo"] = dt.Rows[i]["SlNo"].ToString();
                dr["Id"] = dt.Rows[i]["Id"].ToString();
                dr["TITLE"] = dt.Rows[i]["TITLE"].ToString();
                dr["MEMBNO"] = dt.Rows[i]["MEMBNO"].ToString();
                dr["NAME"] = dt.Rows[i]["NAME"].ToString();
                dr["ADDR1"] = dt.Rows[i]["ADDR1"].ToString();
                dr["ADDR2"] = dt.Rows[i]["ADDR2"].ToString();
                dr["ROAD"] = dt.Rows[i]["ROAD"].ToString();
                dr["CITY"] = dt.Rows[i]["CITY"].ToString();
                dr["PIN"] = dt.Rows[i]["PIN"].ToString();
                dr["BLOODGRP"] = dt.Rows[i]["BLOODGRP"].ToString();
                //dr["PHONE"] = dt.Rows[i]["PHONE"].ToString();
                //if (dt.Rows[i]["ThumbPhoto"] == DBNull.Value)
                //{

                //    System.IO.FileInfo imageInfo = new System.IO.FileInfo(Path.GetDirectoryName(
                //                                                        System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\face_outline.gif");

                //    Photocontent = new byte[imageInfo.Length];
                //    imagestream = imageInfo.OpenRead();
                //    imagestream.Read(Photocontent, 0, Photocontent.Length);
                //    Photocontent = CommonFunctions.createThumnail(imagestream, 50, 50);
                //    dr["Photo"] = CommonFunctions.byteArrayToImage(Photocontent);
                //}
                //else
                //{
                //    dr["Photo"] = CommonFunctions.byteArrayToImage((byte[])dt.Rows[i]["ThumbPhoto"]);
                //}
                dt1.Rows.Add(dr);
            }

            dgvUsers.AllowUserToAddRows = false;
            dgvUsers.AllowUserToDeleteRows = false;
            dgvUsers.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgvUsers.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

            dgvUsers.DataSource = dt1;


         
            dgvUsers.Refresh();
            con.con.Close();
        }
       
        private void RefreshGrid(string SortColumn)
        {
            FillGrid(SortColumn);

            if (con.con.State == ConnectionState.Closed)
            {
                con.con.Open();
            }
            cmd = new SqlCommand("select COUNT(*) from Members", con.con);
            int count = int.Parse(cmd.ExecuteScalar().ToString());
            lblmsg.Text = "Total Number : " + count;

            PagesCount = Convert.ToInt32(Math.Ceiling(count * 1.0 / pageRows));
            CurrentPage = 1;

            RefreshPagination();
            RebindGridForPageChange();
        }

        private void RebindGridForPageChange()
        {
            //Rebinding the Datagridview with data
            int datasourcestartIndex = (CurrentPage - 1) * pageRows;

            tempdt = dt1.Clone();
            DataRow dr = null;
            int ii = 0;
            int jj = 0;
            tempdt.Rows.Clear();

          

            for (int i = datasourcestartIndex; i < datasourcestartIndex + pageRows; i++)
            {
                if (i >= dt1.Rows.Count)
                    break;


                dr = tempdt.NewRow();
                for (jj = 0; jj <= dgvUsers.Columns.Count - 1; jj++)
                {
                    if (jj == 13)
                    {
                        dr[jj] = (Bitmap)dt1.Rows[i][jj];
                    }
                    else
                    {
                        dr[jj] = dt1.Rows[i][jj].ToString();
                    }
                }
                tempdt.Rows.Add(dr);
            }

            dgvUsers.DataSource = tempdt;
            dgvUsers.Refresh();
        }

        private void RefreshPagination()
        {
            ToolStripButton[] items = new ToolStripButton[] { toolStripButton1, toolStripButton2, toolStripButton3, toolStripButton4, toolStripButton5 };

            //pageStartIndex contains the first button number of pagination.
            int pageStartIndex = 1;

            if (PagesCount > 10 && CurrentPage > 2)
                pageStartIndex = CurrentPage - 2;

            if (PagesCount > 10 && CurrentPage > PagesCount - 2)
                pageStartIndex = PagesCount - 4;

            for (int i = pageStartIndex; i < pageStartIndex + 5; i++)
            {
                if (i > PagesCount)
                {
                    items[i - pageStartIndex].Visible = false;
                }
                else
                {
                    //Changing the page numbers
                    items[i - pageStartIndex].Text = i.ToString(CultureInfo.InvariantCulture);

                    //Setting the Appearance of the page number buttons
                    if (i == CurrentPage)
                    {
                        items[i - pageStartIndex].BackColor = Color.Black;
                        items[i - pageStartIndex].ForeColor = Color.White;
                    }
                    else
                    {
                        items[i - pageStartIndex].BackColor = Color.White;
                        items[i - pageStartIndex].ForeColor = Color.Black;
                    }
                }
            }

            //Enabling or Disalbing pagination first, last, previous , next buttons
            if (CurrentPage == 1)
                btnBackward.Enabled = btnFirst.Enabled = false;
            else
                btnBackward.Enabled = btnFirst.Enabled = true;

            if (CurrentPage == PagesCount)
                btnForward.Enabled = btnLast.Enabled = false;

            else
                btnForward.Enabled = btnLast.Enabled = true;
        }

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...