Saturday, 26 March 2016

Send Email Through GoDaddy Server to other Email Account in Asp.net


Suppose in your website you have a contact us or career page in which user may send his data or can contact you and you want that data on y our Gmail, Outlook, Hotmail or other email account. First of all look at the form
In the above form if you want to receive user data on you different email accounts then one thing you should consider in your mind.

 Web browser is not going to directly send data in your email account (email will be send through other email account) , So you will have to give an interface through which your server can send data from client side.

So how you will do it in Asp.net ? for this you will have to go through following steps.

1. add name space
                         using System.Net;
                         using System.Net.Mail;
2. On click event of submit button write following code.
 1. Create an object of MailMessage class like this

         MailMessage msg = new MailMessage(); 
in this object you will get many properties and method to use in sending email

            string email = "Write Here The email ID on which you want to Receive Data";
            string name = "Email ID";
// Now mainmessage string will contain data in prescribe format in which you want 
            string mainmessage = "<html><body>Name : " + TextBox1.Text + "<br />" + "Email ID: : " +     TextBox2.Text + "<br />" + "Contact No : " + TextBox3.Text + "<br />" + "Website Name : " + TextBox4.Text + "<br />" +
                "Message : " + TextBox5.Text + "<br /></body></html>";
            MailMessage msg = new MailMessage();
            msg.Subject = "Message or Feedback From a User";
            msg.Body = mainmessage;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.High;
            msg.From = new MailAddress(TextBox2.Text);
            msg.To.Add(new MailAddress(email.Trim(), name));
            SmtpClient smptc = new SmtpClient(); // Here SMTP Client object is created
            smptc.Host = "smtpout.asia.secureserver.net";// here SMTP interface Address is passed
            smptc.Port = 25;// Use port No 25
            smptc.UseDefaultCredentials = false;
            smptc.EnableSsl = false;
            smptc.DeliveryMethod = SmtpDeliveryMethod.Network;
            NetworkCredential credentials = new NetworkCredential("Write Email or User name of GoDaddy Email Account", "Password here");
            smptc.Credentials = credentials;
            smptc.Send(msg);
            Response.Write("<script type='text/javascript'>alert('Thanks! for your feedback.')</script>");
            TextBox1.Text = "";
            TextBox2.Text = "";

Hope this would help you.

Similarly you can use Gmail and Hotmail but due to some security reason they do not like such activity.

Friday, 25 March 2016

cash handling income and expense using C#

// ------------------to check available cash ------------------------------

        private void CashHandling()
        {
            this.Refresh();
            Cursor.Current = Cursors.WaitCursor;
            string sTot = "";
            double totIncCus = 0.00;
            double totIncService = 0.00;
            double totIncomeMachine = 0.00;
            double totInc = 0.00;
            double totExp = 0.00;
            DateTime dFrdt = DateTime.Today;//DateTime.Parse(dtpNetTotal.Text);

            //Income

            string str = "Select IncDte,TotAmount from T_IncomeInv";
            Con = new OleDbConnection(dbCon());
            OleDbCommand cmd = new OleDbCommand(str, Con);
            Con.Open();
            OleDbDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                if (dr.IsDBNull(0) == false)
                {
                    string sDt = dr.GetValue(0).ToString();
                    DateTime dDt = Convert.ToDateTime(sDt);
                    if (dFrdt == dDt)
                    {
                        // string str1 = "Select GrandTotal from T_CustBill Where CBillNo=" + billNo;

                        sTot = dr.GetValue(1).ToString();
                        if (sTot != "")
                        {
                            totInc += Convert.ToDouble(sTot);
                        }
                    }
                }
            }
            dr.Close();
     
            // From Customer Income
            string strCus = "Select BillDate,GrandTotal from T_CustBill Where Status<>'Cancel'";
            OleDbCommand cmdCus = new OleDbCommand(strCus, Con);
            OleDbDataReader drCus = cmdCus.ExecuteReader();
            while (drCus.Read())
            {
                if (drCus.IsDBNull(0) == false)
                {
                    string sDt = drCus.GetValue(0).ToString();
                    DateTime dDt = Convert.ToDateTime(sDt);
                    if (dFrdt == dDt)
                    {
                        // string str1 = "Select GrandTotal from T_CustBill Where CBillNo=" + billNo;

                        sTot = drCus.GetValue(1).ToString();
                        if (sTot != "")
                        {
                            totIncCus += Convert.ToDouble(sTot);
                        }
                    }
                }
            }
            drCus.Close();      
            // ----------------------- Service Income ----------------------
            // From Customer Income
            string strService = "Select BillDate,NetRs from T_ServiceInv";
            OleDbCommand cmdService = new OleDbCommand(strService, Con);
            OleDbDataReader drService = cmdService.ExecuteReader();
            while (drService.Read())
            {
                if (drService.IsDBNull(0) == false)
                {
                    string sDt = drService.GetValue(0).ToString();
                    DateTime dDt = Convert.ToDateTime(sDt);
                    if (dFrdt == dDt)
                    {
                        // string str1 = "Select GrandTotal from T_CustBill Where CBillNo=" + billNo;

                        sTot = drService.GetValue(1).ToString();
                        if (sTot != "")
                        {
                            totIncService += Convert.ToDouble(sTot);
                        }
                    }
                }
            }
            drService.Close();
            //------------------------- Service Income End ----------------------
            // ----------------------- Machine Income ----------------------
            // From Customer Income
            string strMachine = "Select BillDate,NsuRs from T_QuoBillInvoice";
            OleDbCommand cmdMachine = new OleDbCommand(strMachine, Con);
            OleDbDataReader drMachine = cmdMachine.ExecuteReader();
            while (drMachine.Read())
            {
                if (drMachine.IsDBNull(0) == false)
                {
                    string sDt = drMachine.GetValue(0).ToString();
                    DateTime dDt = Convert.ToDateTime(sDt);
                    if (dFrdt == dDt)
                    {
                        // string str1 = "Select GrandTotal from T_CustBill Where CBillNo=" + billNo;

                        sTot = drMachine.GetValue(1).ToString();
                        if (sTot != "")
                        {
                            totIncomeMachine += Convert.ToDouble(sTot);
                        }
                    }
                }
            }
            drMachine.Close();
            //------------------------- Machine Income End ----------------------
         
            //
            //Expenditure
            string strExp = "Select ExpDte,TotAmount from T_ExpenditureInv";
            OleDbCommand cmdExp = new OleDbCommand(strExp, Con);
            OleDbDataReader drExp = cmdExp.ExecuteReader();
            while (drExp.Read())
            {
                if (drExp.IsDBNull(0) == false)
                {
                    string sDt = drExp.GetValue(0).ToString();
                    DateTime dDt = Convert.ToDateTime(sDt);
                    if (dFrdt == dDt)
                    {
                        // string str1 = "Select GrandTotal from T_CustBill Where CBillNo=" + billNo;

                        sTot = drExp.GetValue(1).ToString();
                        if (sTot != "")
                        {
                            totExp += Convert.ToDouble(sTot);
                        }
                    }
                }
            }
            drExp.Close();
            string SOthInc = totInc.ToString("N2");
            string Sexpense = totExp.ToString("N2");
            string SCusSpare = totIncCus.ToString("N2");
            string SMachine = totIncomeMachine.ToString("N2");
            string Sservice = totIncService.ToString("N2");
            string sNetTotal = "0.00";
            sNetTotal = ((totIncCus + totInc + totIncService + totIncomeMachine) - totExp).ToString("N2");
     
            timer1.Enabled = true;
            scrText = "Net Balance:" + sNetTotal.ToString() + "   " + "Expense:" + Sexpense.ToString() + "  " + "Other Income:" + SOthInc.ToString() + " " + "Spare:" + SCusSpare.ToString() + " " + "Invoice:" + SMachine.ToString()+" "+"Service:"+Sservice .ToString ();
           // tsslAmt.Text = scrText.ToString();
         
            Cursor.Current = Cursors.Default;
}








Dropdown Menu in Navbar

<!DOCTYPE html>
<html>
<head>
<style>
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li {
    float: left;
}

li a, .dropbtn {
    display: inline-block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover, .dropdown:hover .dropbtn {
    background-color: red;
}

li.dropdown {
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
    display: block;
}
</style>
</head>
<body>

<ul>
  <li><a class="active" href="#home">Home</a></li>
  <li><a href="#news">News</a></li>
  <li class="dropdown">
    <a href="#" class="dropbtn">Dropdown</a>
    <div class="dropdown-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </li>
</ul>

<h3>Dropdown Menu inside a Navigation Bar</h3>
<p>Hover over the "Dropdown" link to see the dropdown menu.</p>

</body>
</html>