protected void gdvItemSummery_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { GridViewRow rows = gdvItemSummery.Rows[e.RowIndex]; string refNo = gdvItemSummery.DataKeys[e.RowIndex][0].ToString(); string FrombrId = gdvItemSummery.DataKeys[e.RowIndex][1].ToString(); string ToBrId = gdvItemSummery.DataKeys[e.RowIndex][2].ToString(); Label FromBr = gdvItemSummery.Rows[e.RowIndex].FindControl("lblFromBr") as Label; string strFromBr = FromBr.Text.Trim() != null?FromBr.Text.Trim() : "0"; Label ToBrName = gdvItemSummery.Rows[e.RowIndex].FindControl("lblToBr") as Label; string strToBrName = ToBrName.Text.Trim() != null?ToBrName.Text.Trim() : "0"; Label Vtype = gdvItemSummery.Rows[e.RowIndex].FindControl("lblVtype") as Label; string strVtype = Vtype.Text.Trim() != null?Vtype.Text.Trim() : "0"; Label Vno = gdvItemSummery.Rows[e.RowIndex].FindControl("lblVno") as Label; string strVno = Vno.Text.Trim() != null?Vno.Text.Trim() : "0"; Label TotalValue = gdvItemSummery.Rows[e.RowIndex].FindControl("lblTotalValue") as Label; string strTotalValue = TotalValue.Text.Trim() != null?TotalValue.Text.Trim() : "0"; string relationId = refNo; string posted = "True"; string checkPostedStatus = objServiceHandler.ReturnString("SELECT ContraRef FROM TRANSACTIONLIST WHERE RefNo='" + refNo + "'"); if (!checkPostedStatus.Equals("")) { lblMesseage.Text = "This bill already import"; return; } if (!ToBrId.Equals(branchId)) { lblMesseage.Text = "You are not eligible import this bill ! "; return; } else { string strSql = ""; strSql = "SELECT MAX(VNO)+1 AS VNO FROM TransactionList WHERE VType='SI' AND BrId='" + branchId + "'"; string billNo = objServiceHandler.ReturnString(strSql); if (billNo.Equals(null)) { billNo = "1"; } string result = objTransaction.InsertNewTransferIN(ToBrId, "SI", billNo, strTotalValue, userId, posted); if (result.Equals("Successful")) { string referenceNo = objServiceHandler.ReturnString("SELECT IDENT_CURRENT ('TransactionList') REFERENCENO "); // Session["REFNO"] = referenceNo.ToString(); DataSet getTransferOutDetails = objServiceHandler.ExecuteQuery("SELECT ItemId,Qnty,rate,contraRate,Amount FROM TransactionDetails WHERE TRANSACTIONLIST_ID='" + relationId + "'"); if (getTransferOutDetails.Tables["Table1"].Rows.Count > 0) { foreach (DataRow prow in getTransferOutDetails.Tables["Table1"].Rows) { string itemId = prow["ItemId"].ToString(); string quantity = prow["Qnty"].ToString(); string rate = prow["rate"].ToString(); string contraRate = prow["contraRate"].ToString(); string amount = prow["Amount"].ToString(); string newTransferDetailsResult = objTransaction.InsertNewTransferDetails(itemId, quantity, rate, contraRate, amount, referenceNo); if (!newTransferDetailsResult.Equals("Successful")) { lblMesseage.Text = "Item Import Failled !"; return; } } } DataSet itemList = objServiceHandler.ExecuteQuery("SELECT ItemId,Qnty FROM TransactionDetails WHERE TRANSACTIONLIST_ID='" + referenceNo + "'"); if (itemList.Tables["Table1"].Rows.Count > 0) { foreach (DataRow prow in itemList.Tables["Table1"].Rows) { string itemId = prow["ItemId"].ToString(); string quantity = prow["Qnty"].ToString(); string balance = objServiceHandler.ReturnString("SELECT [" + ToBrId + "] AS Stock FROM ITEM WHERE ITEMID='" + itemId + "'"); double prevBalance = Convert.ToDouble(balance); double currentquantity = Convert.ToDouble(quantity); double currentBalance = prevBalance + currentquantity; quantity = currentBalance.ToString(); string BalanceUpdate = objTransaction.UpdateBalanace(itemId, quantity, ToBrId); if (!BalanceUpdate.Equals("Successfull")) { lblMesseage.Text = "Item Balance Updated Error !"; } } } string TransferOutresult = objTransaction.UpdateTransferOut(refNo, referenceNo, userId); if (TransferOutresult.Equals("Successfull")) { lblMesseage.Text = "Item Import Successfully"; LoadgdvItemSummery(); } else { lblMesseage.Text = "Sales Save Failed"; return; } } } } catch { lblMesseage.Text = "Something went wrong !"; return; } }
protected void btnSave_Click(object sender, EventArgs e) { try { string relationId = ""; string challanNo = txtChallanNo.Text; string voucherType = "PU"; string supplierChallanNo = txtSupplierChallanNo.Text; string supplierId = ddlSupplier.SelectedValue; string totalPrice = txtTotalPrice.Text; string vat = txtVat.Text; string comission = txtComission.Text; string netAmount = txtNetAmount.Text; string posted = "True"; if (ddlSupplier.SelectedIndex == 0) { lblMesseage.Text = "Please Select Supplier"; return; } DataSet checkPostedStatus = objServiceHandler.ExecuteQuery("SELECT REFNO,POSTED FROM TRANSACTIONLIST WHERE BRID='" + branchId + "' AND VTYPE='PU' AND VNO='" + challanNo + "' "); if (checkPostedStatus.Tables["Table1"].Rows.Count == 1) { foreach (DataRow prows in checkPostedStatus.Tables["Table1"].Rows) { relationId = prows["REFNO"].ToString(); string status = prows["POSTED"].ToString(); if (status.Equals("True")) { lblMesseage.Text = "This Bill Already Posted ! "; return; } else { string result = objTransaction.UpdatePurchase(branchId, voucherType, challanNo, relationId, supplierId, supplierChallanNo, totalPrice, vat, comission, netAmount, userId, posted); if (result.Equals("Successfull")) { lblMesseage.Text = "Purchase Save Successfully"; btnAddNew.Enabled = true; btnAdd.Enabled = false; DataSet itemList = objServiceHandler.ExecuteQuery("SELECT ItemId,Qnty FROM TransactionDetails WHERE TRANSACTIONLIST_ID='" + relationId + "'"); if (itemList.Tables["Table1"].Rows.Count > 0) { foreach (DataRow prow in itemList.Tables["Table1"].Rows) { string itemId = prow["ItemId"].ToString(); string quantity = prow["Qnty"].ToString(); string balance = objServiceHandler.ReturnString("SELECT [" + branchId + "] AS Stock FROM ITEM WHERE ITEMID='" + itemId + "'"); double prevBalance = Convert.ToDouble(balance); double currentquantity = Convert.ToDouble(quantity); double currentBalance = prevBalance + currentquantity; quantity = currentBalance.ToString(); string BalanceUpdate = objTransaction.UpdateBalanace(itemId, quantity, branchId); if (!BalanceUpdate.Equals("Successfull")) { lblMesseage.Text = "Item Balance Updated Error !"; } } } } else { lblMesseage.Text = "Purchase Save Failed"; return; } } } } } catch { lblMesseage.Text = "Something went wrong !"; } }