protected void BtnSave_Click(object sender, EventArgs e) { try { LblMessage.Text = ""; bool b = Validation(); for (int i = 0; i < gvDetails.Rows.Count; i++) { TextBox txtBoxQty = (TextBox)gvDetails.Rows[i].Cells[4].FindControl("txtQty"); if (txtBoxQty.Text == "") { string message = "alert('Qty cannot be left blank or Zero..!!');"; ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true); b = false; return; } else if (Convert.ToDecimal(txtBoxQty.Text) < 0) { string message = "alert('Qty must be greater than or equal to zero..!!');"; ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true); b = false; return; } } if (b == true) { conn = obj.GetConnection(); string strCode = string.Empty; cmd = new SqlCommand(); transaction = conn.BeginTransaction(); cmd.Connection = conn; cmd.Transaction = transaction; cmd.CommandTimeout = 3600; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "ACX_INVOICE_NSSTOCK_TRANSFER"; Int32 Movetype; Movetype = rdprimarytononsalable.Checked == true ? 1 : 0; string fromlocation, Tolocation; fromlocation = Tolocation = ""; string query1; DataTable dtloc = new DataTable(); query1 = "select MainWarehouse from ax.inventsite where siteid='" + Session["SiteCode"].ToString() + "' "; dtloc = obj.GetData(query1); if (dtloc.Rows.Count > 0) { if (Movetype == 1) { fromlocation = dtloc.Rows[0]["MainWarehouse"].ToString(); } else { Tolocation = dtloc.Rows[0]["MainWarehouse"].ToString(); } } query1 = "Select INVENTLOCATIONID from Ax.inventlocation where InventSiteid = '" + Session["SiteCode"].ToString() + "' and ACX_WAREHOUSETYPE = 1"; dtloc = obj.GetData(query1); if (dtloc.Rows.Count > 0) { if (Movetype == 1) { Tolocation = dtloc.Rows[0]["INVENTLOCATIONID"].ToString(); } else { fromlocation = dtloc.Rows[0]["INVENTLOCATIONID"].ToString(); } } for (int i = 0; i < gvDetails.Rows.Count; i++) { TextBox txtBoxQty = (TextBox)gvDetails.Rows[i].Cells[4].FindControl("txtQty"); string strqty = txtBoxQty.Text; if (Convert.ToDecimal(txtBoxQty.Text) > 0) { cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@SiteCode", Session["SiteCode"].ToString()); cmd.Parameters.AddWithValue("@DATAAREAID", Session["DATAAREAID"].ToString()); cmd.Parameters.AddWithValue("@TransType", Movetype.ToString()); string productNameCode = gvDetails.Rows[i].Cells[2].Text; string[] str = productNameCode.Split('-'); Label lbluom = (Label)gvDetails.Rows[i].Cells[7].FindControl("UT"); cmd.Parameters.AddWithValue("@ProductCode", str[0].ToString()); cmd.Parameters.AddWithValue("@TransQty", Convert.ToDecimal(strqty).ToString()); cmd.Parameters.AddWithValue("@TransUOM", gvDetails.Rows[i].Cells[8].Text.ToString()); cmd.Parameters.AddWithValue("@TransFromLocation", fromlocation.ToString()); cmd.Parameters.AddWithValue("@TransToLocation", Tolocation.ToString()); cmd.Parameters.AddWithValue("@Referencedocumentno", ddlInvoceNo.Text.ToString()); cmd.ExecuteNonQuery(); } } transaction.Commit(); //transaction.Rollback(); ClearAll(); LblMessage.Text = "Stock Moved Successfully ..!"; } } catch (Exception ex) { transaction.Rollback(); ErrorSignal.FromCurrentContext().Raise(ex); } }