private void SaveStockTransferToDB() { try { //var watch = System.Diagnostics.Stopwatch.StartNew(); // the code that you want to measure comes here CreamBell_DMS_WebApps.App_Code.Global obj = new App_Code.Global(); conn = obj.GetConnection(); string queryInsert = " Insert Into AX.ACXINVENTTRANS " + " ([TransId],[SiteCode],[DATAAREAID],[RECID],[InventTransDate],[TransType],[DocumentType]," + " [DocumentNo],[DocumentDate],[ProductCode],[TransQty],[TransUOM],[TransLocation],[Referencedocumentno])" + " Values (@TransId,@SiteCode,@DATAAREAID,@RECID,@InventTransDate,@TransType,@DocumentType,@DocumentNo,@DocumentDate, " + " @ProductCode,@TransQty,@TransUOM,@TransLocation,@Referencedocumentno)"; string st = Session["SiteCode"].ToString(); string TransId = st.Substring(st.Length - 6) + System.DateTime.Now.ToString("yymmddhhmmss"); //SiteCode[6 Character] plus yymmddhhss of current time// //string TransId = obj.GetNumSequence(10, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString()); #region Generate New Code for Stock Transfer string _query = "SELECT ISNULL(MAX(CAST(RIGHT(DocumentNo,10) AS INT)),0)+1 FROM [ax].[ACXINVENTTRANS] " + "where SITECODE='" + Session["SiteCode"].ToString() + "' and TransType=6"; cmd = new SqlCommand(_query); transaction = conn.BeginTransaction(); cmd.Connection = conn; cmd.Transaction = transaction; cmd.CommandTimeout = 3600; cmd.CommandType = CommandType.Text; object vc = cmd.ExecuteScalar(); string strCodeforStockTransfer = "ST-" + ((int)vc).ToString("0000000000"); //--Stock Transfer Number [ST-0000000001] ---// #endregion cmd.CommandText = string.Empty; cmd.CommandText = queryInsert; #region Grid Data Insert for Warehouse A for (int i = 0; i < gridStockTransferItems.Rows.Count; i++) { string Siteid = Session["SiteCode"].ToString(); string DATAAREAID = Session["DATAAREAID"].ToString(); int TransType = 6; // For Stock Transfer TransType // int DocumentType = 6; // For Stock Transfer TransType // string DocumentNo = strCodeforStockTransfer; // Stock Transfer Number as generated by Code---// string productNameCode = gridStockTransferItems.Rows[i].Cells[3].Text; string[] str = productNameCode.Split('-'); string ProductCode = str[0].ToString(); decimal TransQty = Convert.ToDecimal(gridStockTransferItems.Rows[i].Cells[6].Text); string UOM = gridStockTransferItems.Rows[i].Cells[4].Text; int RecID = i + 1; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@TransId", TransId); cmd.Parameters.AddWithValue("@SiteCode", Siteid); cmd.Parameters.AddWithValue("@DATAAREAID", DATAAREAID); cmd.Parameters.AddWithValue("@RECID", RecID); cmd.Parameters.AddWithValue("@InventTransDate", DateTime.Now); cmd.Parameters.AddWithValue("@TransType", TransType); cmd.Parameters.AddWithValue("@DocumentType", DocumentType); cmd.Parameters.AddWithValue("@DocumentNo", DocumentNo); cmd.Parameters.AddWithValue("@Referencedocumentno", ""); cmd.Parameters.AddWithValue("@DocumentDate", Convert.ToDateTime(txtDate.Text)); cmd.Parameters.AddWithValue("@ProductCode", ProductCode); cmd.Parameters.AddWithValue("@TransQty", TransQty * -1); // for Stock less from WareHouse From Location// cmd.Parameters.AddWithValue("@TransUOM", UOM); cmd.Parameters.AddWithValue("@TransLocation", DDLWarehouseFrom.SelectedValue.ToString()); cmd.ExecuteNonQuery(); ViewState["AdjustmentNo"] = TransId; } #endregion StockTransferTOWareHouse(strCodeforStockTransfer, transaction, conn); //obj.UpdateLastNumSequence(10, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString(), conn, transaction); transaction.Commit(); //watch.Stop(); //var elapsedMs = watch.ElapsedMilliseconds; // this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Transfer No: " + strCodeforStockTransfer + " .Stock Transferred from "+DDLWarehouseTo.Text.ToString()+ " to "+DDLWarehouseTo.Text+ " Successfully !!. ');", true); string message = " alert('Transfer No: " + strCodeforStockTransfer + " .Stock Transferred from " + DDLWarehouseFrom.Text.ToString() + " to " + DDLWarehouseTo.Text + " Successfully !!. ');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", message, true); ResetAllControls(); cmd.Dispose(); conn.Close(); } catch (Exception ex) { transaction.Rollback(); LblMessage.Text = "► Stock Not Transffered. " + " Error: " + ex.Message.ToString(); ErrorSignal.FromCurrentContext().Raise(ex); } }
protected void btnBulkInv_Click(object sender, EventArgs e) { CreamBell_DMS_WebApps.App_Code.Global obj = new App_Code.Global(); SqlConnection con = obj.GetConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandTimeout = 3600; try { int count = 0; string SO_NO = string.Empty; string custname = string.Empty; foreach (GridViewRow rw in gvHeader.Rows) { CheckBox chkBx = (CheckBox)rw.FindControl("chkSONO"); Label lblCustName = (Label)rw.FindControl("Customer_Name"); if (chkBx != null && chkBx.Checked) { count += 1; int row = rw.RowIndex; custname = lblCustName.Text; LinkButton lblSOno = (LinkButton)gvHeader.Rows[row].FindControl("lnkbtn"); Label lblinv = (Label)gvHeader.Rows[row].FindControl("Invoice_No"); if (lblSOno.Text != "") { if (lblinv.Text == "") { SO_NO += "" + lblSOno.Text + ","; } } } lblMessge.Text = ""; } if (count > 8) { ScriptManager.RegisterStartupScript(this, typeof(Page), "alerts", "alert('Maximum 8 sale order selected in single bulk invoice generation');", true); return; } SO_NO = SO_NO.Remove(SO_NO.Length - 1); cmd.Connection = con; cmd.CommandText = "EXEC AX.ACX_SOTOINVOICECREATION_BULK '" + Session["TransLocation"] + "','" + Session["SiteCode"] + "','" + SO_NO + "'"; DataTable dt = new DataTable(); dt.Load(cmd.ExecuteReader()); gridviewRecords.DataSource = dt; gridviewRecords.Visible = true; gridviewRecords.DataBind(); ModalPopupExtender1.Show(); ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", "javascript:MyMessage(" + dt.Rows.Count + "," + dt.Select("Remarks='Success'").Count() + ");", true); //Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "javascript:MyMessage("+dt.Rows.Count+","+dt.Select("Remarks='Success'").Count() +");", true); //Response.Write("<script>alert('test');</script>"); //ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", "alert('test');", true); } catch (Exception ex) { ErrorSignal.FromCurrentContext().Raise(ex); } }
private void SaveDetails() { try { App_Code.Global obj = new App_Code.Global(); //string Number="DT16000001"; #region getnTUMBER string Number = string.Empty; string query = "SELECT ISNULL(MAX(CAST(RIGHT(DISTRUCTION_NO,6) AS INT)),0)+1 FROM [ax].[ACXDISTRUCTIONNOTE] where SITEID='" + Session["SiteCode"].ToString() + "'"; conn = obj.GetConnection(); cmd1 = new SqlCommand(query); transaction = conn.BeginTransaction(); cmd1.Connection = conn; cmd1.Transaction = transaction; cmd1.CommandTimeout = 3600; cmd1.CommandType = CommandType.Text; object vc = cmd1.ExecuteScalar(); Number = "DT" + System.DateTime.Today.ToString("yy") + ((int)vc).ToString("000000"); #endregion #region insert into distruction table if (Session["ProductDetails"] != null) { //conn = obj.GetConnection(); cmd = new SqlCommand("ACX_INSERTDISTRUCTIONNOTE"); // transaction = conn.BeginTransaction(); cmd.Connection = conn; cmd.Transaction = transaction; cmd.CommandTimeout = 3600; cmd.CommandType = CommandType.StoredProcedure; int i = 0; foreach (GridViewRow grv in gvDetails.Rows) { i = i + 1; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@SITEID", Session["SITECODE"].ToString()); cmd.Parameters.AddWithValue("@DISTRUCTION_NO", Number); cmd.Parameters.AddWithValue("@DATAAREAID", Session["DATAAREAID"].ToString()); cmd.Parameters.AddWithValue("@RECEIPT_NO", drpRecieptNo.SelectedItem.Text); cmd.Parameters.AddWithValue("@RECEIPTDATE", txtReceiptDate.Text); cmd.Parameters.AddWithValue("@INVOICE_NO", drpInvoceNo.SelectedItem.Text); cmd.Parameters.AddWithValue("@INVOICEDATE", txtInvoiceDate.Text); cmd.Parameters.AddWithValue("@LINENO", i); cmd.Parameters.AddWithValue("@PRODUCTCODE", grv.Cells[1].Text); cmd.Parameters.AddWithValue("@BOX", grv.Cells[3].Text); cmd.Parameters.AddWithValue("@BATCHNO", grv.Cells[5].Text.Replace(" ", "")); cmd.Parameters.AddWithValue("@MFD", grv.Cells[6].Text); cmd.Parameters.AddWithValue("@REMARK", grv.Cells[7].Text.Replace(" ", "")); cmd.Parameters.AddWithValue("@PRICE", grv.Cells[8].Text); cmd.Parameters.AddWithValue("@VALUE", Convert.ToDecimal(grv.Cells[9].Text)); cmd.Parameters.AddWithValue("@DISTRUCTIONTYPE", 0); cmd.ExecuteNonQuery(); } #endregion #region insert into transaction table and claim table cmd2 = new SqlCommand("ACX_DISTRUCTION_STOCK_MOVEMENT"); cmd2.Connection = conn; cmd2.Transaction = transaction; cmd2.CommandTimeout = 3600; cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.Clear(); cmd2.Parameters.AddWithValue("@Siteid", Session["SITECODE"].ToString()); cmd2.Parameters.AddWithValue("@DISTRUCTIONTYPE", 0); cmd2.Parameters.AddWithValue("@DISTRUCTION_NO", Number); cmd2.ExecuteNonQuery(); #endregion transaction.Commit(); ClearAll(); string message = "alert('Distruction No : " + Number + " Generated Successfully.!');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", message, true); } } catch (Exception ex) { transaction.Rollback(); string message = "alert('Error:" + ex.Message + " !');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", message, true); ErrorSignal.FromCurrentContext().Raise(ex); } finally { if (conn != null) { if (conn.State.ToString() == "Open") { conn.Close(); conn.Dispose(); } } } }
protected void btnSave_Click(object sender, EventArgs e) { try { { if (Session["LineItem"] != null) { CreamBell_DMS_WebApps.App_Code.Global obj = new App_Code.Global(); conn = obj.GetConnection(); DataTable dtNumSeq = obj.GetNumSequenceNew(12, Session["SiteCode"].ToString(), Session["DATAAREAID"].ToString()); string NUMSEQ = string.Empty; string Code = string.Empty; if (dtNumSeq != null) { Code = dtNumSeq.Rows[0][0].ToString(); NUMSEQ = dtNumSeq.Rows[0][1].ToString(); } else { return; } cmd1 = new SqlCommand("[dbo].[ACX_InventoryReceipt_POPLine]"); transaction = conn.BeginTransaction(); cmd1.Connection = conn; cmd1.Transaction = transaction; cmd1.CommandTimeout = 3600; cmd1.CommandType = CommandType.StoredProcedure; //=============Save Line============= int i = 0; foreach (GridViewRow grv in gvDetails.Rows) { HiddenField lblProduct = (HiddenField)grv.FindControl("HiddenValueItemCode"); Label QTY = (Label)grv.Cells[5].FindControl("QTY"); Label Remark = (Label)grv.Cells[5].FindControl("Remark"); i = i + 1; string st = Session["SiteCode"].ToString(); string TransId = st.Substring(st.Length - 6) + System.DateTime.Now.ToString("yymmddhhmmss"); cmd1.Parameters.Clear(); cmd1.Parameters.AddWithValue("@TransId", TransId); cmd1.Parameters.AddWithValue("@Site_Code", lblsite.Text); cmd1.Parameters.AddWithValue("@Line_No", i); cmd1.Parameters.AddWithValue("@DOC_NO", Code); cmd1.Parameters.AddWithValue("@ITEM_CODE", lblProduct.Value); cmd1.Parameters.AddWithValue("@QTY_IN_PCS", QTY.Text); cmd1.Parameters.AddWithValue("@REMARK", Remark.Text); cmd1.Parameters.AddWithValue("@NumSeq", NUMSEQ); cmd1.Parameters.AddWithValue("@DATAAREAID", Session["DATAAREAID"].ToString()); cmd1.ExecuteNonQuery(); } // ==============Save Header========= List <string> ilist = new List <string>(); List <string> litem = new List <string>(); cmd = new SqlCommand("[dbo].[ACX_InventoryReceipt_POPHeader]"); cmd.Connection = conn; cmd.Transaction = transaction; cmd.CommandTimeout = 3600; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Site_Code", Session["SiteCode"].ToString()); cmd.Parameters.AddWithValue("@SUPPLIER_NAME", txtSupplierName.Text); cmd.Parameters.AddWithValue("@SUPPLIER_ADDRESS", txtSupplierAdd.Text); cmd.Parameters.AddWithValue("@DOC_NO", Code); cmd.Parameters.AddWithValue("@INVOICE_NO", txtDocumentNo.Text); cmd.Parameters.AddWithValue("@INVOICE_DATE", txtDocumentDate.Text); cmd.Parameters.AddWithValue("@NumSeq", NUMSEQ); cmd.Parameters.AddWithValue("@DATAAREAID", Session["DATAAREAID"].ToString()); cmd.ExecuteNonQuery(); transaction.Commit(); lblMessage.Text = "Data Saved Successfully. POP Inventory Reciept No is:" + Code + ""; clear(); } else { string message = "alert('Please Add Line Items First !');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", message, true); return; } } } catch (Exception ex) { transaction.Rollback(); string message = "alert('Error:" + ex.Message + " !');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", message, true); ErrorSignal.FromCurrentContext().Raise(ex); } finally { Session["LineItem"] = null; if (conn.State.ToString() == "Open") { conn.Close(); } } }