Dear All,
Based on below C# code i have wrote the statement when inv_qty == 2 , then pop up alert message.
But i found out that after show the alert message. The data transaction has been recorded. May i know how to stop the transaction if pop up the alert message, then return back?
Kindly advsie. thank you.
public void insertData(string TransID, string Item, string FromLocation, string Qty, string Requestor, string RefNum, string Remark, string ReasonID, string ReasonRemark, string CreateDate, string CreateUser, string ToLocation)
{
string constr = ConfigurationManager.ConnectionStrings["CIMProRPT01ConnectionString"].ConnectionString;
using (SqlConnection _cn = new SqlConnection(constr))
{
using (SqlCommand _cmd = new SqlCommand("MMSIssue_InsertOrUpdate", _cn))
{
using (SqlDataAdapter da = new SqlDataAdapter(_cmd))
{
_cn.Open();
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.AddWithValue("@INV_TRANS_ID", TransID);
_cmd.Parameters.AddWithValue("@INV_ID", Item);
_cmd.Parameters.AddWithValue("@INV_LOCATION", FromLocation );
_cmd.Parameters.AddWithValue("@INV_QTY", Qty);
_cmd.Parameters.AddWithValue("@INV_TRANS_REQUESTOR", Requestor);
_cmd.Parameters.AddWithValue("@INV_TRANS_REFNO", RefNum);
_cmd.Parameters.AddWithValue("@INV_TRANS_REMARK", Remark);
_cmd.Parameters.AddWithValue("@INV_REASON_ID", ReasonID);
_cmd.Parameters.AddWithValue("@INV_REASON_REMARK", ReasonRemark);
_cmd.Parameters.AddWithValue("@INV_CREATE_DATE", CreateDate);
_cmd.Parameters.AddWithValue("@INV_CREATE_USER", CreateUser);
_cmd.Parameters.AddWithValue("@INV_FROMLOC", ToLocation);
_cmd.Parameters.Add("@RecordFound", SqlDbType.Int, 0);
_cmd.Parameters["@RecordFound"].Direction = ParameterDirection.Output;
_cmd.ExecuteNonQuery();
string DeleteWMMRSQL = "DELETE FROM [CIMProRPT01].[dbo].[OTH_INV_QTY_LOC] WHERE INV_QTY = 0 OR INV_QTY is null OR INV_QTY <= '-1'";
SqlCommand cmd3 = new SqlCommand(DeleteWMMRSQL, _cn);
cmd3.ExecuteNonQuery();
_cn.Close();
float INV_QTY = Convert.ToInt32(_cmd.Parameters["@RecordFound"].Value.ToString());
if (INV_QTY == 2)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('" + Item + " Qty is more than exist Qty');window.location.href = 'MMS_Issue.aspx';", true);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Transaction completed');", true);
// Response.Redirect("MMS_Issue.aspx?stat=insert");
}
}
}
}
}
USE [CIMProRPT01]
GO
/****** Object: StoredProcedure [dbo].[MMSIssue_InsertOrUpdate] Script Date: 12/31/2013 16:45:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[MMSIssue_InsertOrUpdate]
@INV_TRANS_ID VARCHAR(40)
,@INV_ID VARCHAR(40)
,@INV_LOCATION VARCHAR(40)
,@INV_QTY FLOAT
,@INV_TRANS_REQUESTOR VARCHAR(40)
,@INV_TRANS_REFNO VARCHAR(40)
,@INV_TRANS_REMARK VARCHAR(255)
,@INV_REASON_ID VARCHAR(40)
,@INV_REASON_REMARK VARCHAR(255)
,@INV_CREATE_DATE DATETIME
,@INV_CREATE_USER VARCHAR (255)
--,@INV_VENDORS VARCHAR (40)
,@INV_FROMLOC VARCHAR (40)
,@RecordFound INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS(SELECT * FROM OTH_INV_QTY_LOC WHERE INV_ID = @INV_ID and INV_LOCATION = @INV_LOCATION)
BEGIN
UPDATE OTH_INV_QTY_LOC SET [INV_ID] = @INV_ID,INV_LOCATION = @INV_LOCATION , INV_QTY = INV_QTY - @INV_QTY WHERE INV_ID = @INV_ID AND INV_LOCATION = @INV_LOCATION
INSERT INTO OTH_INV_TRANSACTION (INV_TRANS_ID,INV_ID,INV_TRANS_LOCATION,INV_TRANS_QTY,INV_TRANS_REQUESTOR,INV_TRANS_REFNO,INV_TRANS_REMARK,INV_REASON_ID,INV_REASON_REMARK,INV_CREATE_DATE,INV_CREATE_USER,INV_FROMLOC)VALUES (@INV_TRANS_ID,@INV_ID,@INV_LOCATION,@INV_QTY,@INV_TRANS_REQUESTOR,@INV_TRANS_REFNO,@INV_TRANS_REMARK,@INV_REASON_ID,@INV_REASON_REMARK,@INV_CREATE_DATE,@INV_CREATE_USER,@INV_FROMLOC)
DECLARE @InvFindQTY FLOAT SET @InvFindQTY = ( SELECT INV_QTY FROM OTH_INV_QTY_LOC WHERE INV_ID=@INV_ID AND INV_LOCATION = @INV_LOCATION)
IF @INV_QTY > @InvFindQTY
BEGIN
SELECT @RecordFound = 2
END
ELSE
BEGIN
SELECT @RecordFound = 1
END
END
ELSE
BEGIN
SELECT @RecordFound = 0
END
END