如何在asp.net C#web应用程序中维护库存?

时间:2016-05-13 06:42:26

标签: c# asp.net web-applications

我正在使用visual studio 2008,在Web应用程序C#(前端)& SQL作为后端。在用户输入数量的文本框中,我想首先检查数量是否可用然后进行处理&在gridview中显示特定产品信息,如果Quantity不可用则显示消息...请参阅我正在尝试的代码...

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();
        }    

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();

当我运行项目时,两个语句都被执行。我希望如果First得到假,那么第二次执行,反之亦然。 任何人都有任何想法.. 笨蛋此致

1 个答案:

答案 0 :(得分:1)

不确定我是否知道你想要做什么......但是这样做是否有效:

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;
    }    

然后检查是否为

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();
}

如果完全关闭,请指出您的问题。