コード例 #1
0
 protected void BtnCategoryAdd_Click(object sender, EventArgs e)
 {
     using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyWebsiteDB"].ConnectionString))
     {
         con.Open();
         SqlCommand cmd = new SqlCommand("Insert into Tbl_Category(CategoryName)Values('" + TxtCategoryName.Text + "')", con);
         cmd.ExecuteNonQuery();
         Response.Write("<script> alert ('Kategori Eklendi'); </script>");
         TxtCategoryName.Text = string.Empty;
         con.Close();
         TxtCategoryName.Focus();
         BindCategoryRepeater();
         Session["CategoryName"] = TxtCategoryName.Text;
     }
 }
コード例 #2
0
 private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
 {
     TxtCategoryName.Focus();
 }
コード例 #3
0
 private void WdwCategories_Loaded(object sender, RoutedEventArgs e)
 {
     TxtCategoryName.Focus();
 }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        try
        {
            //validation
            if (TxtCategoryName.Text.Length <= 0)
            {
                lblmsg.Text = "Enter category name"; return;
            }

            string strCount = objDb.ExecuteScaler("select count(*) from ProductCategory where CatName='" + TxtCategoryName.Text + "' and CatCompanyID=" + Convert.ToString(Session["UserID"]));


            string stractive = "0";
            if (ChkActive.Checked == true)
            {
                stractive = "1";
            }
            else
            {
                stractive = "0";
            }

            string strqr = "";
            if (Request.QueryString.Count > 0)
            {
                if (int.Parse(strCount) > 1)
                {
                    lblmsg.Text = "Duplicate product category name are not allowed.";

                    TxtCategoryName.Focus();
                    return;
                }

                strqr = "update ProductCategory set CatName='" + TxtCategoryName.Text.Replace("'", "''") + "', CatActive= " + stractive + " where CatID=" + Convert.ToString(Request.QueryString["id"]);
            }
            else
            {
                if (int.Parse(strCount) >= 1)
                {
                    lblmsg.Text = "Duplicate product category name are not allowed.";

                    TxtCategoryName.Focus();
                    return;
                }

                strqr = "insert into ProductCategory (CatName,CatCompanyID,CatActive) values ('" + TxtCategoryName.Text.Replace("'", "''") + "'," + Convert.ToString(Session["UserID"]) + "," + stractive + ")";
            }
            string ret = objDb.ExecuteInsertUpdate(strqr);
            if (ret == "" || ret == null || ret == "0")
            {
                lblmsg.Text = "Error : " + objDb.returnMsg; return;
            }
            //Response.Redirect("ProductCategory.aspx");

            this.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script language=\"javaScript\">" + "alert('Record Saved');" + "window.location.href='ProductCategory.aspx';" + "<" + "/script>");
        }
        catch (Exception ex)
        {
            lblmsg.Text = "Error : " + ex.Message.ToString();
        }
    }