fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Data;
  10. using System.Drawing;
  11.  
  12.  
  13. namespace onetierarchitecture1
  14. {
  15. public partial class onetier : System.Web.UI.Page
  16. {
  17. SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
  18. internal void BINDDEPT()
  19. {
  20. SqlCommand cmd = new SqlCommand("select * from dept", conn);
  21. SqlDataAdapter da = new SqlDataAdapter(cmd);
  22. DataSet ds = new DataSet();
  23. da.Fill(ds, "dept new");
  24. dddeptname.DataSource = ds.Tables["deptnew"];
  25. dddeptname.DataTextField = "deptid ";
  26. dddeptname.DataTextField = "deptname";
  27. dddeptname.DataBind();
  28. dddeptname.Items.Insert(0, "_select_");
  29.  
  30. }
  31.  
  32. protected void Page_Load(object sender, EventArgs e)
  33. {
  34. if (!IsPostBack)
  35. {
  36. BINDDEPT();
  37. }
  38. }
  39. internal int autoempid()
  40. {
  41. SqlCommand cmd = new SqlCommand("select IsNull(max(id),0) from employee", conn);
  42. conn.Open();
  43. int empid = (int)cmd.ExecuteScalar();
  44. conn.Close();
  45. empid++;
  46. return empid;
  47.  
  48.  
  49. }
  50.  
  51. protected void btninsert_Click(object sender, EventArgs e)
  52. {
  53. int empid = autoempid();
  54. SqlCommand cmd = new SqlCommand("insert into employee values(@empid,@ename, @esalary,@deptid)", conn);
  55. cmd.Parameters.AddWithValue("@empid", empid);
  56. cmd.Parameters.AddWithValue("@ename", txtename.Text);
  57. cmd.Parameters.AddWithValue("@deptid", dddeptname.SelectedValue);
  58. cmd.Parameters.AddWithValue("@esalary", calgrosssal());
  59.  
  60. conn.Open();
  61. int i = cmd.ExecuteNonQuery();
  62. conn.Close();
  63.  
  64. ClearControls();
  65. displaymsg(i);
  66. }
  67. internal void ClearControls()
  68. {
  69. txtename.Text = " ";
  70. txtesal.Text = " ";
  71. dddeptname.SelectedIndex = 0;
  72. txtename.Focus();
  73.  
  74. }
  75. internal void displaymsg(int i)
  76. {
  77.  
  78. lblmsg.Visible = true;
  79.  
  80. if (i != 0)
  81. {
  82. lblmsg.Text = "Record inserted";
  83. }
  84. else
  85. {
  86. lblmsg.Text = "record not inserted";
  87.  
  88. }
  89.  
  90.  
  91. }
  92. internal double calgrosssal()
  93. {
  94. double bsal = double.Parse(txtesal.Text);
  95. double hra = bsal * 20 / 100;
  96. double da = bsal * 15 / 100;
  97. double ta = bsal * 10 / 100;
  98. double grosssal = bsal + hra + da + ta;
  99. return grosssal;
  100.  
  101. }
  102. }
  103. }
Success #stdin #stdout 0.02s 26028KB
stdin
Standard input is empty
stdout
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;


namespace onetierarchitecture1
{
    public partial class onetier : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
        internal void BINDDEPT()
        {
            SqlCommand cmd = new SqlCommand("select * from dept", conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "dept new");
            dddeptname.DataSource = ds.Tables["deptnew"];
            dddeptname.DataTextField = "deptid ";
            dddeptname.DataTextField = "deptname";
            dddeptname.DataBind();
            dddeptname.Items.Insert(0, "_select_");

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BINDDEPT();
            }
        }
        internal int autoempid()
        {
            SqlCommand cmd = new SqlCommand("select IsNull(max(id),0) from  employee", conn);
            conn.Open();
            int empid = (int)cmd.ExecuteScalar();
            conn.Close();
            empid++;
            return empid;


        }

        protected void btninsert_Click(object sender, EventArgs e)
        {
            int empid = autoempid();
            SqlCommand cmd = new SqlCommand("insert into employee values(@empid,@ename, @esalary,@deptid)", conn);
            cmd.Parameters.AddWithValue("@empid", empid);
            cmd.Parameters.AddWithValue("@ename", txtename.Text);
            cmd.Parameters.AddWithValue("@deptid", dddeptname.SelectedValue);
            cmd.Parameters.AddWithValue("@esalary", calgrosssal());

            conn.Open();
            int i = cmd.ExecuteNonQuery();
            conn.Close();

            ClearControls();
            displaymsg(i);
        }
        internal void ClearControls()
        {
            txtename.Text = " ";
            txtesal.Text = " ";
            dddeptname.SelectedIndex = 0;
            txtename.Focus();

        }
        internal void displaymsg(int i)
        {

            lblmsg.Visible = true;

            if (i != 0)
            {
                lblmsg.Text = "Record inserted";
            }
            else
            {
                lblmsg.Text = "record not inserted";

            }
            

        }
        internal double calgrosssal()
        {
            double bsal = double.Parse(txtesal.Text);
            double hra = bsal * 20 / 100;
            double da = bsal * 15 / 100;
            double ta = bsal * 10 / 100;
            double grosssal = bsal + hra + da + ta;
            return grosssal;

        }
    }
}