I have an order page where customer order is been inserted, most times the very sales person inserting the order may insert quantity higher than quantity in stock and the application will insert -0 or -1 or -34 into table.
So i need to stock the user from inserting quantity less than the quantity in stock by displaying error message.
html
<asp:Content ID="Content1" runat="server" contentplaceholderid="ContentPlaceHolder4">
<div class="row">
<div class="">
<div class="box col-md-12">
<div class="pull-left">
<h3 style="margin-top:4px">
<asp:Label ID="Label3" runat="server" Text="" CssClass="glyphicon glyphicon-map-marker"></asp:Label>
Insert page
</h3>
</div>
<div class="pull-right">
<div class="btn-group open" >
<button class="btn btn-default btn-lg">MOLD CATEGORY</button>
<button class="btn dropdown-toggle btn-default btn-lg" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu" style="width:100%">
<li><a href="../AnambraOrder/5InchesSolidMMOrder.aspx"><i class="glyphicon glyphicon-tag"></i> 5 Inches Solid Machine M</a></li>
<li><a href="/AnambraOrder/5InchesSolidHMOrder.aspx"><i class="glyphicon glyphicon-tag"></i> 5 Inches Solid Hand M</a></li>
<li><a href="#"><i class="glyphicon glyphicon-tag"></i> 6 Inches Solid Machine M</a></li>
<li><a href="#"><i class="glyphicon glyphicon-tag"></i> 6 Inches Solid Hand M</a></li>
<li><a href="#"><i class="glyphicon glyphicon-tag"></i> 6 Inches Hollow Machine M</a></li>
<li><a href="#"><i class="glyphicon glyphicon-download-alt"></i> Something else here</a></li>
<li class="divider"></li>
<li><a href="#"><i class="glyphicon glyphicon-tint"></i> Separated link</a></li>
</ul>
</div>
</div>
<div class="clearfix"></div>
<hr />
<h4 style="margin-top:4px">
<asp:Label ID="Label2" runat="server" Text="" CssClass="glyphicon glyphicon-shopping-cart"></asp:Label>
6 Inches Solid Machine Mold Order Sales Input
</h4>
</div>
<div class="clearfix"></div>
<div class="col-md-6">
<div class="clearfix"></div>
<br />
<div id="" class=" ">
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
<div class="box-inner homepage-box" style="height:auto">
<div class="box-header well">
<h2><i class="glyphicon glyphicon-th"></i>Customer Order Form </h2>
<div class="box-icon">
<a href="#" class="btn btn-setting btn-round btn-default"><i
class="glyphicon glyphicon-cog"></i></a><a href="#" class="btn btn-minimize btn-round btn-default"><i
class="glyphicon glyphicon-chevron-up"></i></a><a href="#" class="btn btn-close btn-round btn-default"><i
class="glyphicon glyphicon-remove"></i></a>
</div>
</div>
<div class="box-content" >
<div>
<div id="" class="">
<div class=" ">
<div class="">
<div class=" ">
<div class="clearfix"></div>
<div id="" class="">
<p class="input-group">
<asp:TextBox ID="txtname" runat="server" placeholder="Customer Name " class="form-control" ></asp:TextBox>
<span class="input-group-btn">
<asp:Button ID="LoginButton" runat="server" Text="Search" class="btn btn-default" type="button" Font-Bold="True" />
<span class="glyphicon glyphicon-search"></span>
</span>
</p>
<div class="clearfix"></div>
<p class="">
<asp:DropDownList ID="ddlLocation" runat="server" CssClass="btn btn-default dropdown-toggle" Width="100%" Font-Bold="False" Font-Size="Larger" Visible="False">
<asp:ListItem>Branch 1</asp:ListItem>
</asp:DropDownList>
</p>
</div>
<div class="clearfix"></div>
<div id="" class="">
<p class="">
<asp:DropDownList ID="ddlItems" runat="server" CssClass="btn btn-default dropdown-toggle" Width="100%" Font-Bold="False" Font-Size="Larger" Visible="False">
<asp:ListItem Text="Block" Value="Block" />
</asp:DropDownList>
</p>
</div>
<div id="" class="">
<p class="">
<asp:DropDownList ID="ddlCategory" runat="server" CssClass="btn btn-default dropdown-toggle" Width="100%" Font-Bold="False" Font-Size="Larger" Visible="False">
<asp:ListItem Text="6inches Solid Machine Mold" Value="Select" />
</asp:DropDownList>
</p>
</div>
<div class="clearfix"></div>
<div id="" class="">
<p class="">
<asp:DropDownList ID="ddlstock" runat="server" CssClass="btn btn-default dropdown-toggle" Width="100%" Font-Bold="False" Font-Size="Larger" Enabled="false" Visible="False">
</asp:DropDownList>
</p>
</div>
<div class="clearfix"></div>
<div id="" class="">
<p class="">
<asp:DropDownList ID="ddlpaymentmethod" runat="server" CssClass="btn btn-default dropdown-toggle" Width="100%" Font-Bold="False" Font-Size="Larger">
<asp:ListItem>Select Payment Method</asp:ListItem>
<asp:ListItem>Cash</asp:ListItem>
<asp:ListItem>Bank Payment</asp:ListItem>
</asp:DropDownList>
</p>
</div>
<div class="clearfix"></div>
<div id="" class="">
<p class="">
<asp:DropDownList ID="ddlorderstatus" runat="server" CssClass="btn btn-default dropdown-toggle" Width="100%" Font-Bold="False" Font-Size="Larger">
<asp:ListItem>Select Order Status</asp:ListItem>
<asp:ListItem>Supplied</asp:ListItem>
<asp:ListItem>Pending </asp:ListItem>
</asp:DropDownList>
</p>
</div>
<div class="clearfix"></div>
<p class="">
<asp:TextBox ID="txtcustomerqty" runat="server" CssClass="form-control " placeholder="Customer Quantity "></asp:TextBox>
</p>
<div class="clearfix"></div>
<p class="">
<asp:TextBox ID="txtdiscount" runat="server" CssClass="form-control " placeholder="Discount "></asp:TextBox>
</p>
<div class="clearfix"></div>
<p class="">
<asp:TextBox ID="txtunitprice" runat="server" CssClass="form-control " placeholder="Unit Price "></asp:TextBox>
</p>
<div class="clearfix"></div>
<p class=" pull-right">
<asp:LinkButton ID="btnSave" runat="server" CssClass="btn btn-info btn-circle" Text="" Height="50px" Width="100px" CausesValidation="true" OnClick="btnSave_Click"> <asp:Label ID="Label5" runat="server" Text="" CssClass=" glyphicon glyphicon-cloud-upload" Font-Size="Large"></asp:Label></asp:LinkButton>
<asp:Button ID="btnReset2" runat="server" CssClass="btn btn-default btn-circle" Text="Edit Record" Height="50px" Width="100px" OnClick="btnReset2_Click" Font-Bold="True"/>
<asp:Label ID="Label1" runat="server"></asp:Label>
</p>
</div>
</div>
</div>
<div class="" >
</div>
<!--/#content.col-md-0-->
<div class="row" style="width: 100%">
<!--/span-->
</div>
<!--/span-->
</div>
</div>
</div>
</div>
</div>
</div>
<div class="box col-md-6">
</div>
</div>
</asp:Content>
<asp:Content ID="Content2" runat="server" contentplaceholderid="ContentPlaceHolder3">
<div class="col-md-12">
</div>
<div class="box-content alerts">
<asp:Label ID="lblMessage2" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="#669900" CssClass=""></asp:Label>
</div>
</asp:Content>
C Sharpe
protected void btnSave_Click(object sender, EventArgs e)
{
lblMessage2.Visible = false;
if (txtname.Text == "")
{
// MessageBox1.ShowError("Enter Date Please");
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter Customer Name ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (ddlItems.SelectedIndex < 1)
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Select Item ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (ddlCategory.SelectedIndex < 1)
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Select Block Category ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (ddlpaymentmethod.SelectedIndex < 1)
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Select Payment Method ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (ddlorderstatus.SelectedIndex < 1)
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Select Order Status ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (txtcustomerqty.Text == "")
{
// MessageBox1.ShowError("Enter Date Please");
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter Customer Quantity ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (txtunitprice.Text == "")
{
// MessageBox1.ShowError("Enter Date Please");
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter Selling Price ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
// int availableInventoryQty = AvailableInventoryQty();
if (ddlstock.Text.Length > 0 && txtcustomerqty.Text.Length > 0)
{
double stock = Convert.ToDouble(ddlstock.Text);
double customerqty = Convert.ToDouble(txtcustomerqty.Text);
double tqty = stock - customerqty;
double gqty = tqty;
{
if (txtunitprice.Text.Length > 0 && txtcustomerqty.Text.Length > 0)
{
double unitprice2 = Convert.ToDouble(txtunitprice.Text);
double customerqty2 = Convert.ToDouble(txtcustomerqty.Text);
double grandtotal = unitprice2 * customerqty;
double total = grandtotal;
{
if (txtunitprice.Text.Length > 0 && txtdiscount.Text.Length > 0)
{
double unitprice = Convert.ToDouble(txtunitprice.Text);
double discount = Convert.ToDouble(txtdiscount.Text);
double sum = grandtotal - discount;
double sumb = sum;
//if (txtunitprice.Text.Length > 0 && txtquantity.Text.Length > 0)
{
string Currency = ("N");
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("InsertSixInchesSolidMachineMoldORDER"))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", Session["userName"]);
cmd.Parameters.AddWithValue("@Name", txtname.Text.Trim());
cmd.Parameters.AddWithValue("@Location", ddlLocation.Text.Trim());
cmd.Parameters.AddWithValue("@Item", ddlItems.Text.Trim());
// cmd.Parameters.AddWithValue("@Inches", ddlInches.Text.Trim()); //Name of rep
// cmd.Parameters.AddWithValue("@MouldType", ddlmouldcategory.Text.Trim());
cmd.Parameters.AddWithValue("@Category", ddlCategory.Text.Trim());
cmd.Parameters.AddWithValue("@StockRemaining", tqty);
cmd.Parameters.AddWithValue("@PaymentMethod", ddlpaymentmethod.Text.Trim());
cmd.Parameters.AddWithValue("@OrderStatus", ddlorderstatus.Text.Trim());
//Address
cmd.Parameters.AddWithValue("@QuantityOrdered", txtcustomerqty.Text.Trim());
cmd.Parameters.AddWithValue("@Discount", txtdiscount.Text.Trim());
cmd.Parameters.AddWithValue("@UnitPrice", txtunitprice.Text.Trim());
cmd.Parameters.AddWithValue("@TotalAmount", sum);
cmd.Parameters.AddWithValue("@OrderDate", DateTime.Today);
// cmd.Parameters.AddWithValue("@Location", ddlLocation.Text.Trim());
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
string message = string.Empty;
{
lblMessage2.Visible = true;
lblMessage2.Text = "Data Submitted Successfully";
}
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Data Submitted Successfully ... !!')</script>", false);
}
}
}
// else
string a = "33a";
if (a == "a")
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "btnModalPopup();", true);
}
else if (a != "a")
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "btnModalPopup();", true);
}
// {
// ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Please quantity required is more than the stock, Stock is 1 or less than 1, update stock ... !!')</script>", false);
// lbl.Text = "Data Submitted Sucessfully";
// btnSave.Show();
}
}
}
}
}
}
}
}
}
}
}
}
}