繁体   English   中英

如何在ASP.NET C#Web应用程序中维护库存?

[英]How to maintain stock in asp.net C# web application?

我正在使用Visual Studio 2008,在Web应用程序C#(前端)和SQL中作为后端。 当用户输入数量时,在文本框中,我想先检查数量是否可用,然后在网格视图中处理并显示特定产品信息,如果数量不可用,则显示消息...请参阅代码尝试是...

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错误,然后Second执行,反之亦然。..任何人都有任何想法..感谢和问候

不知道我是否确切知道您想做什么...但是可以做到这一点:

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

如果完全没有问题,请指定您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM