2016-05-13 4 views
0

Ich benutze Visual Studio 2008, in der Webanwendung C# (Frontend) & SQL als Backend. In der Textbox, wenn Benutzer die Quantität eingeben, möchte ich zuerst überprüfen, ob die Quantität verfügbar ist, dann verarbeitet sie & zeigt bestimmte Produktinformationen in gridview an, wenn Quantität NICHT verfügbar ist, dann zeigt sie die Mitteilung ... sehen Sie den Code, den ich bin versuch ...Wie man Vorrat in asp.net C# Webanwendung erhält?

public void stkMaintain() 
     { 
      SqlDataReader drd; 
      var qty = 0; 
      SqlCommand cmd = new SqlCommand("SELECT * from StockMstrDetail where ItemId='" + Convert.ToString(txtScanBarcode.Text) + "'", con); 
      //cmd.CommandType = CommandType.Text; 
      con.Open(); 
      drd = cmd.ExecuteReader(); 
      if (drd.HasRows) 
      { 
       while (drd.Read()) 
       { 
        qty = Convert.ToInt32(drd["Quantity"].ToString()); 
       } 
       if (Convert.ToInt32(txtentrqty.Text) > (Convert.ToInt32(qty))) 
       { 
        Response.Write("Product Not In Stock...!); 
       } 
       if(txtentrqty.Text=="") 
       { 
        Response.Write("Quantity Should not be blank...!"); 
       } 
      } 
      con.Close(); 
     }  

und

protected void Button1_Click(object sender, EventArgs e) 
    { 
     stkMaintain(); 

      SqlDataReader rdr; 
      SqlCommand cmd = new SqlCommand("SELECT * from Purchase_Details where ItemId='" + Convert.ToString(txtScanBarcode.Text) + "'", con); 
      cmd.CommandType = CommandType.Text; 

      using (con) 
      { 
       con.Open(); 
       rdr = cmd.ExecuteReader(); 

       while (rdr.Read()) 
       { 
        var purTaxPer = Convert.ToInt32(rdr["VatPercent"].ToString()); 
        var salersdum = Convert.ToInt32(rdr["SaleRs"].ToString()); 
        var cal1 = (Convert.ToDouble(salersdum)) * ((Convert.ToDouble(purTaxPer))/100); 
        var cal2 = (100 + (Convert.ToDouble(purTaxPer))); 
        var Itemtax = Math.Round(((Convert.ToDouble(cal1))/(Convert.ToDouble(cal2))) * 100, 2); 
        var ratewidoutax = Math.Round((Convert.ToDouble(salersdum)) - (Convert.ToDouble(Itemtax)), 2); 
        var pricewidoutax = Math.Round((Convert.ToDouble(ratewidoutax)) * (Convert.ToInt32(rdr["Quantity"].ToString())), 2); 
        var discount = Math.Round((Convert.ToInt32(ddldisc.SelectedValue)) * (Convert.ToDouble(ratewidoutax))/100.0, 2); 
        var discountamt = Math.Round((Convert.ToDouble(ratewidoutax)) - (Convert.ToDouble(discount)), 2); 
        var newitemtax = Math.Round((Convert.ToDouble(discountamt)) * (Convert.ToDouble(purTaxPer))/100.0, 2); 
        var newrate = Math.Round((Convert.ToDouble(newitemtax)) + (Convert.ToDouble(discountamt)), 2); 

        //Session["SrNo"] += rdr["Srno"].ToString() + "|"; 
        Session["Barcode"] += rdr["ItemId"].ToString() + "|"; 
        Session["Product Name"] += rdr["ProdName"].ToString() + "|"; 
        Session["Desc"] += rdr["GroupName"].ToString() + "|"; 
        Session["Rate"] += rdr["SaleRs"].ToString() + "|"; 
        Session["Qty"] += rdr["Quantity"].ToString() + "|"; 
        Session["Tax(%)"] += (Convert.ToString(purTaxPer)) + "|"; 
        Session["Sale Price"] += Math.Round(Convert.ToInt32(rdr["Quantity"].ToString()) * Convert.ToDouble(rdr["SaleRs"].ToString()), 2) + "|"; 
        Session["Item Tax"] += (Convert.ToString(newitemtax)) + "|"; 
        Session["RateWithoutTax"] += (Convert.ToString(ratewidoutax)) + "|"; 
        Session["PriceWithoutTax"] += (Convert.ToString(pricewidoutax)) + "|"; 
        Session["Discount(%)"] += (Convert.ToString(ddldisc.SelectedValue)) + "|"; 
        Session["Discount"] += (Convert.ToString(discount)) + "|"; 
        Session["DiscountedAmt"] += (Convert.ToString(discountamt)) + "|"; 
        Session["TotDiscount"] += Math.Round((Convert.ToDouble(rdr["Quantity"])) * (Convert.ToDouble(discount)), 2) + "|"; 
        Session["TotDiscountedAmt"] += Math.Round((Convert.ToInt32(rdr["Quantity"])) * (Convert.ToDouble(discountamt)), 2) + "|"; 
        Session["Final Rate"] += (Convert.ToString(newrate)) + "|"; 
        Session["Final Amt"] += Math.Round((Convert.ToInt32(rdr["Quantity"])) * (Convert.ToDouble(newrate)), 2) + "|"; 
        Session["Type"] += rdr["SrNoType"].ToString() + "|"; 
        Session["IMEI/SrNo"] += rdr["IMEINO"].ToString() + "|"; 
        Session["Brand"] += rdr["BrandName"].ToString() + "|"; 
        Session["SaleDiscount"] += rdr["Colour"].ToString() + "|"; 
        Session["SaleDisAmt"] += rdr["Colour"].ToString() + "|"; 
        Session["Size"] += rdr["Colour"].ToString() + "|"; 
        CreateTable(); 

wenn ich das Projekt beiden Anweisungen erhalten ausgeführt laufen. Ich möchte, dass, wenn zunächst falsch erhalten dann Sekunde ausführen und umgekehrt .. jemand eine Idee haben, .. Thnks & Grüße

Antwort

1

nicht sicher, ob ich weiß, was Sie genau tun wollen ... aber das funktioniert der Trick tun :

public bool stkMaintain() 
    { 
     SqlDataReader drd; 
     var qty = 0; 
     SqlCommand cmd = new SqlCommand("SELECT * from StockMstrDetail where ItemId='" + Convert.ToString(txtScanBarcode.Text) + "'", con); 
     //cmd.CommandType = CommandType.Text; 
     con.Open(); 
     drd = cmd.ExecuteReader(); 
     if (drd.HasRows) 
     { 
      while (drd.Read()) 
      { 
       qty = Convert.ToInt32(drd["Quantity"].ToString()); 
      } 
      if (Convert.ToInt32(txtentrqty.Text) > (Convert.ToInt32(qty))) 
      { 
       Response.Write("Product Not In Stock...!); 
      } 
      if(txtentrqty.Text=="") 
      { 
       Response.Write("Quantity Should not be blank...!"); 
       Con.Close(); 
       return false; 
      } 
     } 
     con.Close(); 
     return true; 
    }  

dann prüfen, ob falsch

protected void Button1_Click(object sender, EventArgs e) 
{ 
    if(stkMaintain()){ 
     SqlDataReader rdr; 
     SqlCommand cmd = new SqlCommand("SELECT * from Purchase_Details where ItemId='" + Convert.ToString(txtScanBarcode.Text) + "'", con); 
     cmd.CommandType = CommandType.Text; 

     using (con) 
     { 
      con.Open(); 
      rdr = cmd.ExecuteReader(); 

      while (rdr.Read()) 
      { 
       var purTaxPer = Convert.ToInt32(rdr["VatPercent"].ToString()); 
       var salersdum = Convert.ToInt32(rdr["SaleRs"].ToString()); 
       var cal1 = (Convert.ToDouble(salersdum)) * ((Convert.ToDouble(purTaxPer))/100); 
       var cal2 = (100 + (Convert.ToDouble(purTaxPer))); 
       var Itemtax = Math.Round(((Convert.ToDouble(cal1))/(Convert.ToDouble(cal2))) * 100, 2); 
       var ratewidoutax = Math.Round((Convert.ToDouble(salersdum)) - (Convert.ToDouble(Itemtax)), 2); 
       var pricewidoutax = Math.Round((Convert.ToDouble(ratewidoutax)) * (Convert.ToInt32(rdr["Quantity"].ToString())), 2); 
       var discount = Math.Round((Convert.ToInt32(ddldisc.SelectedValue)) * (Convert.ToDouble(ratewidoutax))/100.0, 2); 
       var discountamt = Math.Round((Convert.ToDouble(ratewidoutax)) - (Convert.ToDouble(discount)), 2); 
       var newitemtax = Math.Round((Convert.ToDouble(discountamt)) * (Convert.ToDouble(purTaxPer))/100.0, 2); 
       var newrate = Math.Round((Convert.ToDouble(newitemtax)) + (Convert.ToDouble(discountamt)), 2); 

       //Session["SrNo"] += rdr["Srno"].ToString() + "|"; 
       Session["Barcode"] += rdr["ItemId"].ToString() + "|"; 
       Session["Product Name"] += rdr["ProdName"].ToString() + "|"; 
       Session["Desc"] += rdr["GroupName"].ToString() + "|"; 
       Session["Rate"] += rdr["SaleRs"].ToString() + "|"; 
       Session["Qty"] += rdr["Quantity"].ToString() + "|"; 
       Session["Tax(%)"] += (Convert.ToString(purTaxPer)) + "|"; 
       Session["Sale Price"] += Math.Round(Convert.ToInt32(rdr["Quantity"].ToString()) * Convert.ToDouble(rdr["SaleRs"].ToString()), 2) + "|"; 
       Session["Item Tax"] += (Convert.ToString(newitemtax)) + "|"; 
       Session["RateWithoutTax"] += (Convert.ToString(ratewidoutax)) + "|"; 
       Session["PriceWithoutTax"] += (Convert.ToString(pricewidoutax)) + "|"; 
       Session["Discount(%)"] += (Convert.ToString(ddldisc.SelectedValue)) + "|"; 
       Session["Discount"] += (Convert.ToString(discount)) + "|"; 
       Session["DiscountedAmt"] += (Convert.ToString(discountamt)) + "|"; 
       Session["TotDiscount"] += Math.Round((Convert.ToDouble(rdr["Quantity"])) * (Convert.ToDouble(discount)), 2) + "|"; 
       Session["TotDiscountedAmt"] += Math.Round((Convert.ToInt32(rdr["Quantity"])) * (Convert.ToDouble(discountamt)), 2) + "|"; 
       Session["Final Rate"] += (Convert.ToString(newrate)) + "|"; 
       Session["Final Amt"] += Math.Round((Convert.ToInt32(rdr["Quantity"])) * (Convert.ToDouble(newrate)), 2) + "|"; 
       Session["Type"] += rdr["SrNoType"].ToString() + "|"; 
       Session["IMEI/SrNo"] += rdr["IMEINO"].ToString() + "|"; 
       Session["Brand"] += rdr["BrandName"].ToString() + "|"; 
       Session["SaleDiscount"] += rdr["Colour"].ToString() + "|"; 
       Session["SaleDisAmt"] += rdr["Colour"].ToString() + "|"; 
       Session["Size"] += rdr["Colour"].ToString() + "|"; 
       CreateTable(); 
} 

wenn das vollständig ausgeschaltet ist, geben Sie bitte Ihre Frage spezifizieren.

+0

Es funktioniert einwandfrei ... – chirag

Verwandte Themen