Tuesday, 23 April 2013

email sending Codes in windows application .net


System.Net.Mail.MailMessage objMMsg = new System.Net.Mail.MailMessage();
                                objMMsg.To.Add("haimrutyunjaya@gmail.com");// "mrutyunjaya.das@sagacityinfotech.co.in";
                                objMMsg.From = new System.Net.Mail.MailAddress("mrutyunjaya.das@sagacityinfotech.co.in");

                                objMMsg.Subject = "Tester mail";
                                objMMsg.Body = "This is atest mail no need to replay";

                                System.Net.Mail.SmtpClient smtpMail = new System.Net.Mail.SmtpClient();
                                smtpMail.Host = "smtp.gmail.com";
                                smtpMail.Port = 587;
                                smtpMail.EnableSsl = true;
                                smtpMail.Credentials = new System.Net.NetworkCredential("mrutyunjaya.das@sagacityinfotech.co.in", "sagacity");
                                smtpMail.Send(objMMsg);                              

                                //MessageBox.Show("Successfull");
                                //Mail objmail = new Mail();
                                //objmail.sendMail("mrutyunjaya.das@sagacityinfotech.co.in", "Testing1111111", "Test mail");

Row Duplicate(How to avoid) in table

select bcm_brcd,count(bcm_brcd) as dup_count  from vw_JSP_STOCK_SUMRY_TAX_INV_SALE where itm_id=101
group by bcm_brcd having (count(bcm_brcd)>1)

TextBox take only numeric in c# Code Behind

 private void vtbPhno_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (char.IsDigit(e.KeyChar) == false)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            catch (Exception)
            {
                e.Handled = false;
            }
        }

Update a table from another one



update dbo.ISSUE_BARCODES
set itm_code = t2.itm_code,im_code=t2.im_code,gross_wt=t2.obm_wght,net_wt=t2.obm_net_wt
from dbo.ISSUE_BARCODES t1 inner join temp_1 t2
on t1.barcode=t2.obm_brcd

Transanction for sql in store procedure

begin try
        begin transaction
    Update SubMenu_Master set Menu_Id=@Menu_Id,Sub_Menu_Name=@Sub_Menu_Name,
    Sub_Menu_Description=@Sub_Menu_Description,Sub_Menu_Shortcut=@Sub_Menu_Shortcut
   where Sub_Menu_Id=@Sub_Menu_Id;

Update Menu_List_Details set Menu_Id=@Menu_Id where Sub_Menu_Id=@Sub_Menu_Id;

    SET @message='Update Successfully';
    commit transaction
    end try
    begin catch
        rollback transaction
    end catch

Monday, 22 April 2013

Table's Column Name Count

SELECT count(*)
FROM information_schema.columns
WHERE table_name = 'DailyTransactions'

Sunday, 21 April 2013

Highest Salary of any, in sql query


select distinct sal from salary s1 where n = (select count(distinct sal) from salary s2 where s1.sal <= s2.sal)
--n is the no. of integer of any highest salary.

Caountry Name fetching in c# code without Database


private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = getcultureinfo();
        }
        private IList<string> getcultureinfo()
        {
            List<string> list = new List<string>();
            foreach (CultureInfo info in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                RegionInfo inforeg = new RegionInfo(info.LCID);
                if(!list.Contains(inforeg.EnglishName))
                {
                    list.Add(inforeg.EnglishName);
                    list.Sort();
                }
            }
            return list;
        }

Validation given to a project for some days

if ((System.DateTime.Today.Day >= 1 && System.DateTime.Today.Month == 12)||System.DateTime.Today.Year==2012)
                {
                    MessageBox.Show("Your Software already Collaspsed Please register your product");
                }
                 else
                {
                    if (System.DateTime.Today.Day >= 10 && System.DateTime.Today.Month == 12)//10 and 12 you can take it from xml file or other
                    {
                        MessageBox.Show("You Should Renew Your Software within 15 days Otherwise it will Collaspe","DJSplashSinglePoint",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    }
//this condition is given according to project requirement
                    blkPkt = null;
                    _modeType = FormModes.Add;
                    ResetControl(_modeType);
                    txtRefVrNo.Focus();
                }

Friday, 19 April 2013

Infragistics Report Using c# Code(Sample Example)



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using CTSERPSystem.BAL;
using Infragistics.Documents.Reports.Graphics;
using Infragistics.Documents.Reports.Report;
using Infragistics.Documents.Reports.Report.Table;
using Infragistics.Documents.Reports.Report.Section;
using Infragistics.Documents.Reports.Report.Shapes;
using Infragistics.Documents.Reports.Report.Text;
using CTSERPSystem.Entity;
using System.IO;
using Infragistics.Documents.Reports.Report.Band;


namespace CTSERPSystem
{
    public partial class TestForm : Form
    {
        public TestForm()
        {
            InitializeComponent();
        }

        private void TestForm_Load(object sender, EventArgs e)
        {

        }

        private void submitButton_Click(object sender, EventArgs e)
        {
            IList<ECRIssue> ecrIssues = new List<ECRIssue>();

            foreach (var ecrIssue in new ECRIssueManager().GetECRIssues())//retrieve datas from database,use ur own way  
                ecrIssues.Add(ecrIssue);
            CreateReport(ecrIssues, new string[] { "Name", "Requested By", "Issue Response", "Status", "Visible To Supplier", "Created By Id", "Created Time", "Last Modified Time", "Last Modified By Id" });//Title of the headrs);
            //CreateReport(ecrIssues, new string[] { "Name", "Requested By", "Issue Response", "Status", "Visible To Supplier", "Created By", "Created Time", "Last Modified Time", "Last Modified By" });//Title of the headrs
        }

        public static System.Drawing.Image ResizeImage(System.Drawing.Image sourceImage, System.Drawing.Size size)
        {
            decimal sourceImageHeight = sourceImage.Height, sourceImageWidth = sourceImage.Width, resizedImageHeight, resizedImageWidth;

            if (sourceImageHeight > sourceImageWidth)
            {
                if (sourceImageHeight > size.Height)
                    resizedImageHeight = size.Height;
                else
                    resizedImageHeight = sourceImageHeight;
                resizedImageWidth = (resizedImageHeight / sourceImageHeight) * sourceImageWidth;
            }
            else
            {
                if (sourceImageWidth > size.Width)
                    resizedImageWidth = size.Width;
                else
                    resizedImageWidth = sourceImageWidth;
                resizedImageHeight = (resizedImageWidth / sourceImageWidth) * sourceImageHeight;
            }
            System.Drawing.Image resizedImage = sourceImage.GetThumbnailImage(Convert.ToInt32(resizedImageWidth), Convert.ToInt32(resizedImageHeight), null, IntPtr.Zero);

            return resizedImage;
        }

        private void CreateReport(IList<ECRIssue> ecrIssues, string[] columnName)
        {
            Report report = new Report();
            ISection section = report.AddSection();

            //section.AddQuickText("MyHeader").Font.DoubleUnderline = true; ;
            IBand reportBand = section.AddBand();
            reportBand.Paddings.Bottom = 1;
            var reportImage = reportBand.AddImage(new Infragistics.Documents.Reports.Graphics.Image(ResizeImage(System.Drawing.Image.FromFile(@"Images\CTSLogo.jpg"), new System.Drawing.Size(100, 50))));
            reportImage.KeepRatio = true;
            //
            // Create a title for the Section.
            IText textForSection = section.AddText();
            textForSection.Margins.Bottom = 1;
            textForSection.Margins.Right = 10;
            textForSection.Alignment = TextAlignment.Right;
            textForSection.Style = new Infragistics.Documents.Reports.Report.Text.Style(Infragistics.Documents.Reports.Graphics.Fonts.ArialBold, Infragistics.Documents.Reports.Graphics.Brushes.Black);
            textForSection.AddContent("ECR Issues");


            //
            section.PageSize = new PageSize(800, 600);
            section.PagePaddings.Top = 10;
            section.PagePaddings.Left = 10;
            section.PagePaddings.Right = 10;
            section.PagePaddings.Bottom = 25;

            Infragistics.Documents.Reports.Report.Table.ITable table = section.AddTable();
            // Create a new pattern for the cells.
            Infragistics.Documents.Reports.Report.Table.TableCellPattern tableCellPattern =
              new Infragistics.Documents.Reports.Report.Table.TableCellPattern();
            tableCellPattern.Borders = new Borders(new Infragistics.Documents.Reports.Graphics.Pen(Infragistics.Documents.Reports.Graphics.Colors.Black));
            tableCellPattern.Background = new Background(Infragistics.Documents.Reports.Graphics.Brushes.White);
            tableCellPattern.Paddings = new Paddings(5, 10);
          
            table.Header.Repeat = true;           
            ITableCell theHeaderCell = null;          
            for (int titleOfTheHeader = 0; titleOfTheHeader < columnName.Length; titleOfTheHeader++)// cell name for header
            {
                theHeaderCell = table.Header.AddCell();
                theHeaderCell.Width = new RelativeWidth(150);
                tableCellPattern.Apply(theHeaderCell);
                theHeaderCell.Background = new Background(Infragistics.Documents.Reports.Graphics.Brushes.White);
                IText tableCellTextForHeader = theHeaderCell.AddText();
                tableCellTextForHeader.Alignment =
                          new TextAlignment(Alignment.Center, Alignment.Middle);
                tableCellTextForHeader.Style.Font.Bold = true;
                //stationeryText.Style = New Style(New Font("Verdana", 72), Brushes.Silver)
                tableCellTextForHeader.Style = new Style(new Infragistics.Documents.Reports.Graphics.Font("Arial Rounded MT Bold", 11), Infragistics.Documents.Reports.Graphics.Brushes.Black);
                tableCellTextForHeader.AddContent("" + columnName[titleOfTheHeader] + "");              
            }

            Infragistics.Documents.Reports.Report.Table.ITableRow tableRow;
            Infragistics.Documents.Reports.Report.Table.ITableCell tableCell;

            for (int row = 0; row < ecrIssues.Count; row++)
            {
                tableRow = table.AddRow();
                for (int column = 0; column < columnName.Length; column++)
                {
                    tableCell = tableRow.AddCell();
                    tableCell.Width = new RelativeWidth(150);//150 length for Issue Response              
                    tableCellPattern.Apply(tableCell);
                    tableCell.Background = new Background(Infragistics.Documents.Reports.Graphics.Brushes.White);
                    IText tableCellText = tableCell.AddText();
                    tableCellText.Style.Font.Bold = false;
                    tableCellText.Alignment =
                      new TextAlignment(Alignment.Center, Alignment.Middle);
                    if (column == 0)//Name
                        tableCellText.AddContent("" + ecrIssues.ElementAt(row).Name + "");
                    else if (column == 1)//Requested By
                        tableCellText.AddContent("" + new ECRManager().GetEcr(ecrIssues.ElementAt(row).RequestId).Name + "");
                    else if (column == 2)//Issue Response
                        tableCellText.AddContent("" + ecrIssues.ElementAt(row).IssueResponse + "");
                    else if (column == 3)//Status
                        tableCellText.AddContent("" + ((StatusTypes)ecrIssues.ElementAt(row).StatusId).ToString() + "");//((EnumDisplayStatus)value)
                    else if (column == 4)//Visible To Supplier
                    {
                        if (ecrIssues.ElementAt(row).IsVisibleToSupplier)
                            tableCellText.AddContent("Yes");
                        else tableCellText.AddContent("No");
                    }
                    else if (column == 5)//Created by user
                        tableCellText.AddContent("" + ecrIssues.ElementAt(row).CreatedByUserId + "");
                    else if (column == 6)//Created date
                        tableCellText.AddContent("" + ecrIssues.ElementAt(row).CreatedByDateTime + "");
                    else if (column == 7)//Last Modified time
                        tableCellText.AddContent("" + ecrIssues.ElementAt(row).LastModifiedDateTime + "");
                    else if (column == 8)//Last Modified user
                        tableCellText.AddContent("" + ecrIssues.ElementAt(row).LastModifiedUserId + "");
                }
            }
            // Get a reference to the section's PageNumbering object.
            Infragistics.Documents.Reports.Report.Section.PageNumbering pageNumbering = section.PageNumbering;
            // Create a style for the page numbering font.
            pageNumbering.Style = new Infragistics.Documents.Reports.Report.Text.Style(Fonts.Arial, Infragistics.Documents.Reports.Graphics.Brushes.Black);
            /* The Template property is the actual string that shows the page numbering. Use the [Page #] place-
             holder for the current page and the [TotalPages] place-holder for the total amount of pages in the entire document.*/
            pageNumbering.Template = "Page [Page #] of [TotalPages]";
            /* Setting SkipFirst to true does not place page numbering on the first page of the section. This
            is useful if the first page is a Title page.*/
            pageNumbering.SkipFirst = false;
            /* The page numbering will be aligned with the right side of the page. Valid values off the Alignment enum include Left, Center, and Right.*/
            pageNumbering.Alignment.Horizontal = Infragistics.Documents.Reports.Report.Alignment.Right;
            /* The page numbering will be located at the bottom of the page. Valid values off the lignment enum include Top and Bottom.*/
            pageNumbering.Alignment.Vertical = Infragistics.Documents.Reports.Report.Alignment.Bottom;
            /*The page numbering is at the extreme bottom of the page, so we need to change the Y Offset
             in order to bring it in line with the rest of the page footer text.*/
            pageNumbering.OffsetY = -18;
            ISectionFooter ftr = section.AddFooter();
            ftr.Height = 10;
            IText text = ftr.AddText(5, -18);
            text.AddContent(string.Format("    Date printed: {0}", DateTime.Now.ToString("dd-MMM-yyyy hh:mmtt")));

            string myDocuments = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
            report.Publish(myDocuments + "\\Report.pdf", FileFormat.PDF);
            System.Diagnostics.Process.Start(myDocuments + "\\Report.pdf");
        }

    }
}