Thursday, 9 October 2014

Generate Date Time as a random no.

            int n1, s1 = 0;
            int z1 = 2;
            string m1 = "";
            string reverse1 = "";

            string i1 = System.DateTime.Now.ToShortDateString();               \\Current  Date
            string j1 = System.DateTime.Now.ToLongTimeString();                \\Current Time
            string[] a1 = i1.Split('-');
            int k1 = Convert.ToInt32(a1[0]);
            while (z1 != 0)
            {
                n1 = k1 % 10;
                m1 += (s1 * 10 + n1).ToString();
                k1 = k1 / 10;
                z1 = z1 - 1;
            }

            for (int eb = m1.Length - 1; eb > -1; eb--)                               \\ Find last 2 digit of the year
            {
                reverse1 += m1[eb];
            }
            string[] b1 = j1.Split(' ');
            string x01 = b1[0];
            string[] c01 = x01.Split(':');
            string ran = reverse1 + a1[1] + a1[2] + c01[0] + c01[1];
            string bno = "R" + ran;                                         \\ Add "R" in starting of the random no                                      

Ajax Modal Popup Example

Design Page
<div style="width:20px;float:right; position:fixed;">
                           <asp:ImageButton ID="ImageButton1" runat="server"
                               ImageUrl="~/Images/feedback1.png"  Height="120px" Width="25px" />
                           
    </div>    
Add ModalPopupExtender
  <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
                                 TargetControlID="ImageButton1" PopupControlID="panel_feedback"
                                  DropShadow="True" BackgroundCssClass="modalBackground"
                                 CancelControlID="cross1" / >
Design Panel
<asp:Panel ID="panel_feedback" runat="server"  >
                             <center>
                             <div class="form_enquiry"><div style="float:right"><asp:ImageButton ID="cross1" runat="server" ImageUrl="~/images/cross.jpg" Width="20px" Height="20px" /></div>
                          <center><h4>FEEDBACK </h4></center>  <div>

<table>
<tr>
    <td>
        <asp:Label ID="Label4" runat="server" Text="Name"></asp:Label>
    </td>
</tr>
   <tr>
        <td>
            <asp:TextBox ID="TextBox1" runat="server" Width="221px"></asp:TextBox>
       
        </td>
   </tr>
   <tr>
    <td>
        <asp:Label ID="Label1" runat="server" Text="Email"></asp:Label>
    </td>
</tr>
   <tr>
        <td>
            <asp:TextBox ID="TextBox2" runat="server" Width="222px"></asp:TextBox>
        </td>
   </tr>
<tr>
    <td>
        <asp:Label ID="Label2" runat="server" Text="Message"></asp:Label>
    </td>
</tr>
   <tr>
        <td>
            <asp:TextBox ID="TextBox3" runat="server" Height="44px" TextMode="MultiLine"
                Width="222px" MaxLength="499" />
        </td>  </tr><tr> <td></td>
        <td style="float:right;">
 <asp:Button ID="feedButton1" runat="server" Text="Submit" onclick="feedButton1_Click" />
        </td>
   </tr>
</table></div>     </div>  </center>  </asp:Panel>
Ajax Modal Popup

Wednesday, 8 October 2014

Add text in a Gridview using RowDatabound in ASP.NET using C#

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label l1 = (Label)e.Row.FindControl("Label5");
            if (!string.IsNullOrEmpty(l1.Text))
            {
                if (l1.Text != "300" && l1.Text != "450")
                {
                    e.Row.Cells[3].Text = "Rs. " + l1.Text + " per hour";
                    //e.Row[].Cells[3].Text = "Rs. " + l1.Text + " ";
                }
                else
                {
                    e.Row.Cells[3].Text = "Rs. " + l1.Text + " ";
                }
            }
        }
    }

Email Integration

 public void sendMail()
    {
        try
        {
            mailmsg = "Name - " + txtname.Text + "<br />Email - "+txtemail.Text+"<br />Mobile no. - " + txtmobileno.Text + "<br />" + "Message - " + txturreq.Text + "<br /><b>ABC Team</b>";
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress("#####@gmail.com");
            mail.To.Add("customer1@gmail.com");
            mail.To.Add("customer2@gmail.com");
         
            mail.Subject = "Subject";
            mail.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
            System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(System.Text.RegularExpressions.Regex.Replace(mailmsg, @"<(.|\n)*?>", string.Empty), null, "text/plain");
            System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(mailmsg, null, "text/html");
            mail.AlternateViews.Add(plainView);
            mail.AlternateViews.Add(htmlView);
            mail.Body = mailmsg;
            mail.IsBodyHtml = true;

            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Host = "smtpout.asia.secureserver.net";
            smtpClient.Port = 25;
            smtpClient.EnableSsl = false;
            smtpClient.UseDefaultCredentials = true;
            smtpClient.Credentials = new System.Net.NetworkCredential("#####@gmail.com", "*********");
                       smtpClient.Send(mail);

        }
        catch (Exception ex)
        {
             Response.Write(ex);
        }
    }

SMS Integration in ASP.NET

HttpWebRequest myReq =(HttpWebRequest)WebRequest.Create("http://###.###.##.#/SendSMS/sendmsg.php?uname=*****&pass=*****&send=*****%20&dest=" + mobile_no. + "&msg=Dear " + "Mr./Mrs " + Name_of_user+ " Thanks! for Feedback !!! ");
             
                HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
                System.IO.StreamReader respStreamReader = new                                                                                  System.IO.StreamReader(myResp.GetResponseStream());
                string responseString = respStreamReader.ReadToEnd();
                respStreamReader.Close();
                myResp.Close();

Highlight values in Gridview using Rowdatabound in ASP.NET

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label chk1 = (Label)e.Row.FindControl("Label9");
            if (!string.IsNullOrEmpty(chk1.Text))
            {
                if (chk1.Text == "Approved")
                {
                    e.Row.Cells[9].ForeColor = System.Drawing.Color.Green;
                }
                else
                {
                    e.Row.Cells[9].ForeColor = System.Drawing.Color.Red;
                }
            }
        }
}


Friday, 19 September 2014

Alert box




Response.Write("<script>alert('your message') ; location.href='MainView.aspx?LineNumber=" + customer.LineNumber.ToString() + "&id=" + CustomerId.ToString()+ "'</script>")

Monday, 11 August 2014

Encrypt and decrypt the value or password.

// Encrypt and decrypt the value or password and save in database.



        con.Open();                        // connection open
        byte[] encData_byte = new byte[b.Length];                     // Encrypt the code and store in "b1" string variable
        encData_byte = System.Text.Encoding.UTF8.GetBytes(b);    // " b " is the value which you want to encrypt
        string b1 = Convert.ToBase64String(encData_byte);                  // Encrypted result

        System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();     // Encrypt the code and store in "b2" string 
        System.Text.Decoder utf8Decode = encoder.GetDecoder();
        byte[] todecode_byte = Convert.FromBase64String(b1);       // " b1 " is the value which you want to decrypt
        int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
        char[] decoded_char = new char[charCount];
        utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
        string b2= new String(decoded_char);           // Decrypted result
       
        string sq = "insert into testlogin values('" + a.ToString() + "','" + b.ToString() + "','" + b1.ToString() + "','" + b2.ToString() + "')";
        SqlCommand cmd = new SqlCommand(sq, con);
        cmd.ExecuteNonQuery();    // Execute the query

Thursday, 7 August 2014

Date Picker Calender

//  Date Picker Calender.

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#firstdate" ).datepicker();
    $( "#lastdate" ).datepicker();
  });
  </script>

Saturday, 19 July 2014

SQL using GROUP BY .

 Table which is used for  GROUP BY :-




1.  select MIN(score) AS 'total' from test1 GROUP BY id



2.  select COUNT(score) AS 'total' from test1 GROUP BY id






3.  select SUM(score) AS 'total' from test1 GROUP BY id





4. select MAX(score) AS 'total' from test1 GROUP BY id