i have a sells page that insert is not working , the idea is to insert customer order then update the inventory quantity by minusing the customer quantity from the inventory then insert remaining quantity to Remaining qty column in inventory
<p class="col-md-6" style="margin-bottom: 6px">
<span></span>
<asp:DropDownList ID="ddlSalesPoint" runat="server" CssClass="btn btn-default dropdown-toggle"
Width="100%">
</asp:DropDownList>
</p>
<div class="clearfix">
</div>
<p class="col-md-6">
<asp:TextBox ID="txtPostedBy" runat="server" placeholder=" Posted By " TextMode="SingleLine"
CssClass="form-control"></asp:TextBox>
</p>
<div class="clearfix">
</div>
<p class="col-md-6">
<asp:TextBox ID="txtcustomerphone" runat="server" placeholder=" Customer Phone "
TextMode="SingleLine" CssClass="form-control"></asp:TextBox>
</p>
<div class="clearfix">
</div>
<p class="col-md-6">
<asp:DropDownList ID="ProductNo" runat="server" CssClass="btn btn-default dropdown-toggle"
Width="100%">
<asp:ListItem>Please Select Product Code</asp:ListItem>
<asp:ListItem>0909M </asp:ListItem>
<asp:ListItem>F0909</asp:ListItem>
<asp:ListItem>-------------------------------</asp:ListItem>
</asp:DropDownList>
</p>
<div class="clearfix">
</div>
<p class="col-md-6">
<asp:TextBox ID="Description" runat="server" placeholder=" Description" TextMode="SingleLine"
CssClass="form-control"></asp:TextBox>
</p>
<div class="clearfix">
</div>
<p class="col-md-6" style="margin-bottom: 6px">
<span></span>
<asp:DropDownList ID="ddlBrandSales" runat="server" CssClass="btn btn-default dropdown-toggle"
Width="100%">
</asp:DropDownList>
</p>
<div class="clearfix">
</div>
<div class="clearfix">
</div>
<p class="col-md-6" style="">
<asp:DropDownList ID="ddlpaymentmethode" runat="server" CssClass="btn btn-default dropdown-toggle"
Width="100%">
<asp:ListItem>Select Payment Method</asp:ListItem>
<asp:ListItem>Cash</asp:ListItem>
<asp:ListItem>Deposit</asp:ListItem>
<asp:ListItem>Bank Tranfer</asp:ListItem>
<asp:ListItem>POS</asp:ListItem>
<asp:ListItem>Cheque</asp:ListItem>
</asp:DropDownList>
</p>
<div class="clearfix">
</div>
<p class="col-md-6">
<asp:TextBox ID="txtquantity" runat="server" placeholder=" Quantity" TextMode="SingleLine"
CssClass="form-control"></asp:TextBox>
</p>
<div class="clearfix">
</div>
<p class="col-md-6">
<asp:TextBox ID="txtdiscount2" runat="server" placeholder=" Discount" CssClass="form-control"></asp:TextBox>
</p>
<div class="clearfix">
</div>
<p class="col-md-6">
<asp:TextBox ID="txtunitprice" runat="server" placeholder=" Unit Price" TextMode="SingleLine"
CssClass="form-control"></asp:TextBox>
</p>
<div class="clearfix">
</div>
<p class="col-md-8">
<asp:Button ID="btnSave" runat="server" CssClass="btn btn-info btn-circle" Text="Save"
Height="50px" Width="100px" CausesValidation="true" OnClick="btnSave_Click" />
<asp:Button ID="btnReset2" runat="server" CssClass="btn btn-default btn-circle" Text="Reset"
Height="50px" Width="100px" OnClick="btnReset_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>
</p>
code
protected void btnSave_Click(object sender, EventArgs e)
{
// lblMessage3.Visible = true;
lblMessage2.Visible = false;
if (ddlSalesPoint.SelectedIndex < 1)
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter Method Of Payment ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (txtPostedBy.Text == "")
{
// MessageBox1.ShowError("Enter Date Please");
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter Date ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (ProductNo.SelectedIndex < 1)
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter ProductNo ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (ProductNo.SelectedIndex < 1)
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter ProductNo ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (ddlBrandSales.SelectedIndex < 1)
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter Branch ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (txtquantity.Text == "")
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter Quantity By Customer ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (txtdiscount2.Text == "")
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter Quantity By Customer ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (txtunitprice.Text == "")
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter Quantity By Customer ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (ddlpaymentmethode.SelectedIndex < 1)
{
ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Enter Category ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (txtunitprice.Text.Length > 0 && txtdiscount.Text.Length > 0)
{
double unitprice = Convert.ToDouble(txtunitprice.Text);
double discount = Convert.ToDouble(txtdiscount2.Text);
double sum = unitprice - discount;
double sumb = sum;
if (txtunitprice.Text.Length > 0 && txtquantity.Text.Length > 0)
{
double setunitprice = Convert.ToInt32(txtunitprice.Text);
double quantity1 = Convert.ToDouble(txtquantity.Text);
double suma = quantity1 * sum;
double GrandT = suma;
if (txtunitprice.Text.Length > 0 && txtquantity.Text.Length > 0)
{
// int availableInventoryQty = AvailableInventoryQty();
// if (availableInventoryQty >= Convert.ToDouble(txtQuantityByCustomer.Text))
{
string Currency = ("N");
string constr = ConfigurationManager.ConnectionStrings["SC"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("InsertCustomerOrder"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Parameters.AddWithValue("@SalesPoint", ddlSalesPoint.Text.Trim());
cmd.Parameters.AddWithValue("@PostedBy", txtPostedBy.Text.Trim()); //Name of rep
cmd.Parameters.AddWithValue("@CustomerPhone", txtcustomerphone.Text.Trim());
cmd.Parameters.AddWithValue("@CompanyUserName", this.User.Identity.Name);
cmd.Parameters.AddWithValue("@ProductNo", ProductNo.Text.Trim());
cmd.Parameters.AddWithValue("@Description", Description.Text.Trim());
cmd.Parameters.AddWithValue("@Brand", ddlBrandSales.Text.Trim());
cmd.Parameters.AddWithValue("@PaymentMethod", ddlpaymentmethode.Text.Trim());
cmd.Parameters.AddWithValue("@Quantity", txtquantity.Text.Trim());
cmd.Parameters.AddWithValue("@Discount", txtdiscount2.Text.Trim());
cmd.Parameters.AddWithValue("@UnitPrice", txtunitprice.Text.Trim()); //Address
cmd.Parameters.AddWithValue("@TotalCost", sum);
cmd.Parameters.AddWithValue("@GrandTotal", suma);
cmd.Connection = con;
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
con.Close();
string message = string.Empty;
{
}
}
// Response.Redirect("Order_Submit.aspx?Message=Data Submitted Successfully");
}
}
}
// 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();
}
}
}
}
}
}
}
}
}
}
}
}
}
procedure
ALTER PROCEDURE [dbo].[InsertCustomerOrder]
@SalesPoint nvarchar (50),
@PostedBy nvarchar(50),
@CustomerPhone varchar (50),
@CompanyUserName nvarchar (50),
@ProductNo nvarchar (50),
@Description nvarchar (50),
@Brand nvarchar (50),
@PaymentMethod nvarchar (50),
@Quantity int,
@Discount money,
@UnitPrice money,
@TotalCost money,
@GrandTotal money
AS
INSERT INTO [DailySales]
([SalesPoint]
,[PostedBy]
,[CustomerPhone]
,[CompanyUserName]
,[ProductNo]
,[Description]
,[Brand]
,[PaymentMethod]
,[Quantity]
,[Discount]
,[UnitPrice]
,[TotalCost]
,[GrandTotal])
VALUES
(
@SalesPoint,
@PostedBy,
@CustomerPhone,
@CompanyUserName,
@ProductNo,
@Description,
@Brand,
@PaymentMethod,
@Quantity,
@Discount,
@UnitPrice,
@TotalCost,
@GrandTotal
)
------Update Quantity by subtracting it from @Qty
UPDATE NewStock SET [QuantityRemaining] = [QuantityRemaining]- @Quantity WHERE [Brand]= @Brand AND [ProductNo] = @ProductNo AND [CompanyUserName] =@CompanyUserName
select SCOPE_IDENTITY() as UserID