コード例 #1
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //string str1 = "SELECT * from JobFunctionCategory  where CategoryName='" + txtCategoryName.Text + "' and Whid='" + ddlbusiness.SelectedValue + "'";
        //SqlCommand cmd1 = new SqlCommand(str1, con);
        //SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
        //DataTable dt1 = new DataTable();
        //da1.Fill(dt1);

        if (btnSubmit.Text == "Submit")
        {
            CLS_JobFunctionCategory jfc = new CLS_JobFunctionCategory();
            jfc.Whid         = ddlbusiness.SelectedValue;
            jfc.CategoryName = txtCategoryName.Text;

            DataTable dt1 = jfc.cls_jobfunctioncategory2();


            if (dt1.Rows.Count > 0)
            {
                lblmsg.Visible = true;
                lblmsg.Text    = "Category already exist";
            }

            else
            {
                jfc.Name   = txtCategoryName.Text;
                jfc.Whid   = ddlbusiness.SelectedValue;
                jfc.Status = Convert.ToInt32(ddlStatus.SelectedValue);
                int i = jfc.cls_jobfunctioncategory1();
                if (i > 0)
                {
                    lblmsg.Visible = true;
                    lblmsg.Text    = "Record inserted successfully";
                    fillgrid();
                }
            }
        }
        if (btnSubmit.Text == "Update")
        {
            SqlCommand cmd = new SqlCommand("update JobFunctionCategory set CategoryName='" + txtCategoryName.Text + "',Whid='" + ddlbusiness.SelectedValue + "',Status='" + ddlStatus.SelectedValue + "' where id='" + ViewState["EID"] + "'", con);
            if (con.State.ToString() != "Open")
            {
                con.Open();
            }
            cmd.ExecuteNonQuery();
            con.Close();

            lblmsg.Visible = true;
            lblmsg.Text    = "Record updated successfully";
            fillgrid();

            btnSubmit.Text = "Submit";
        }

        txtCategoryName.Text    = "";
        ddlStatus.SelectedIndex = 0;
        pnladdd.Visible         = false;
        btnnewcat.Visible       = true;
        lbllegend.Text          = "";
    }
コード例 #2
0
    protected void fillDDl(DropDownList ddl, string Textfild, string valfild)
    {
        CLS_JobFunctionCategory jfc = new CLS_JobFunctionCategory();

        jfc.comid = Session["comid"].ToString();

        DataTable dt11 = jfc.cls_fillddl();

        ddl.DataSource     = dt11;
        ddl.DataTextField  = Textfild;
        ddl.DataValueField = valfild;
        ddl.DataBind();
    }
コード例 #3
0
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            int dk = Convert.ToInt32(GridView1.DataKeys[GridView1.EditIndex].Value);


            TextBox cat = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCategory1");

            DropDownList wh = (DropDownList)GridView1.Rows[GridView1.EditIndex].FindControl("ddlBusiness1");

            CheckBox cb = (CheckBox)GridView1.Rows[e.RowIndex].FindControl("cbxStatus1");

            //string str1 = "SELECT * from JobFunctionCategory  where CategoryName ='" + cat.Text + "' and Whid='" + wh.SelectedValue + "' and Id<>'" + dk + "'";
            //SqlCommand cmd1 = new SqlCommand(str1, con);
            //SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
            //DataTable dt1 = new DataTable();
            //da1.Fill(dt1);
            CLS_JobFunctionCategory jfc = new CLS_JobFunctionCategory();
            jfc.Whid         = wh.SelectedValue;
            jfc.CategoryName = cat.Text;
            jfc.Id           = dk.ToString();

            DataTable dt1 = jfc.cls_jobfunctioncategory5();

            if (dt1.Rows.Count > 0)
            {
                lblmsg.Visible = true;
                lblmsg.Text    = "Category already exist";
            }

            else
            {
                int i;
                if (cb.Checked == true)
                {
                    i = 1;
                }
                else
                {
                    i = 0;
                }

                string     sr51   = ("update JobFunctionCategory set CategoryName ='" + cat.Text + "',Whid='" + wh.SelectedValue + "',Status = " + i + " where Id='" + dk + "' ");
                SqlCommand cmd801 = new SqlCommand(sr51, con);

                if (con.State.ToString() != "Open")
                {
                    con.Open();
                }
                cmd801.ExecuteNonQuery();
                con.Close();
                //jfc.Whid = wh.SelectedValue;
                //jfc.CategoryName = cat.Text;
                //jfc.Id = dk.ToString();
                //jfc.cls_update_jobfunction();

                GridView1.EditIndex = -1;
                fillgrid();
                lblmsg.Visible = true;
                lblmsg.Text    = "Record updated successfully";
                //ddl();
            }
        }
        catch (Exception ert)
        {
            lblmsg.Visible = true;
            lblmsg.Text    = "Error :" + ert.Message;
        }
    }