protected void _btnUpdate_Click(object sender, EventArgs e) { try { IsssuedItemsLogic akivi = new IsssuedItemsLogic(); properties issued = new properties(); decimal orginalChallanID = Convert.ToDecimal(hdnFieldChallanID.Value); issued.ChallanID = Convert.ToDecimal(_tbChalanNo.Text); // issued.Date = _tbChallanDate.Text; issued.Date = DateTime.ParseExact(_tbChallanDate.Text, "dd-MM-yyyy", null).ToString("yyyy-MM-dd"); stDate = DateTime.ParseExact(_tbChallanDate.Text, "dd-MM-yyyy", null).ToString("yyyy-MM-dd"); issued.IndentValue = _tbIndentValue.Text; // issued.Date2 = _tbIntendDate.Text; issued.Date2 = DateTime.ParseExact(_tbIntendDate.Text, "dd-MM-yyyy", null).ToString("yyyy-MM-dd"); edDate = DateTime.ParseExact(_tbIntendDate.Text, "dd-MM-yyyy", null).ToString("yyyy-MM-dd"); if (_ddIntendDivisions.SelectedIndex > 0) { issued.Division = _ddIntendDivisions.Text; } else { issued.Division = lblDivisionOld.Text; } if (_ddCHead.SelectedIndex > 0) { issued.ChargeableHeadName = _ddCHead.SelectedItem.ToString(); } else { issued.ChargeableHeadName = lblChHeadOld.Text; } issued.IsDeliveredTemporary = istemporary.Checked ? "Yes" : "No"; issued.ModifiedBy = Convert.ToInt16(Session["USERID"]); issued.ReceiverDesignation = tbReceiverDesignation.Text; issued.VehicleNumber = tbVehicleNumberCaps.Text.ToUpper(); issued.Remarks = tbremarks.Text; StringBuilder sb = new StringBuilder(); string insertStatement = "INSERT INTO DeliveryItemsDetails(DeliveryItemsChallanID,ItemName, IssueHeadName,QUANTITY,UNIT,RATE) values('@DeliveryItemsChallanID','@ItemName', '@IssueHeadName', '@QUANTITY', '@UNIT', '@RATE')"; for (int i = 0; i < gvItems.Rows.Count; i++) { DropDownList itemName = gvItems.Rows[i].FindControl("_ddItems") as DropDownList; TextBox itemUnit = gvItems.Rows[i].FindControl("_tbUnit") as TextBox; TextBox itemQuantity = gvItems.Rows[i].FindControl("_tbQuantity") as TextBox; //DropDownList itemIHead = gvItems.Rows[i].FindControl("_ddIhead") as DropDownList; //DropDownList ddlRates = gvItems.Rows[i].FindControl("ddlRates") as DropDownList; HiddenField hdnSelectedIssueHead = gvItems.Rows[i].FindControl("hdnSelectedIssueHead") as HiddenField; HiddenField hdnSelectedRate = gvItems.Rows[i].FindControl("hdnSelectedRate") as HiddenField; if (itemName.SelectedValue.ToString() != "") { sb.Append(insertStatement.Replace("@DeliveryItemsChallanID", _tbChalanNo.Text).Replace("@ItemName", Utilities.ValidSql(itemName.SelectedItem.ToString())).Replace("@IssueHeadName", hdnSelectedIssueHead.Value).Replace("@QUANTITY", itemQuantity.Text).Replace("@UNIT", itemUnit.Text).Replace("@RATE", hdnSelectedRate.Value)); } } if (sb.ToString() != "") { akivi.UpdateIssuedItems(issued, orginalChallanID, sb.ToString()); } else { akivi.UpdateIssuedItems(issued, orginalChallanID); } Response.Redirect("~/Admin/IssueEntriesList.aspx"); } catch (System.Threading.ThreadAbortException) { } catch (SqlException ex) { if (ex.Message.Contains("duplicate key")) { panelError.Visible = true; lblError.Text = "Error! The challan ID already exists. Please use another ID"; panelSuccess.Visible = false; } else { Session["ERRORMSG"] = ex.ToString(); Response.Redirect("Error.aspx"); } } catch (Exception ex) { Session["ERRORMSG"] = ex.ToString(); Response.Redirect("Error.aspx", true); } }
protected void _btnSave_Click(object sender, EventArgs e) { try { IsssuedItemsLogic akivi = new IsssuedItemsLogic(); properties issued = new properties(); decimal orginalChallanID = Convert.ToDecimal(hdnFieldChallanID.Value); issued.ChallanID = Convert.ToDecimal(_tbChalanNo.Text); // issued.Date = _tbChallanDate.Text; issued.Date = DateTime.ParseExact(_tbChallanDate.Text, "dd-MM-yyyy", null).ToString("yyyy-MM-dd"); stDate = DateTime.ParseExact(_tbChallanDate.Text, "dd-MM-yyyy", null).ToString("yyyy-MM-dd"); issued.IndentValue = _tbIndentValue.Text; // issued.Date2 = _tbIntendDate.Text; issued.Date2 = DateTime.ParseExact(_tbIntendDate.Text, "dd-MM-yyyy", null).ToString("yyyy-MM-dd"); edDate = DateTime.ParseExact(_tbIntendDate.Text, "dd-MM-yyyy", null).ToString("yyyy-MM-dd"); //using 2 controls for displaying old value and for givng option to check if (_ddIntendDivisions.SelectedIndex > 0) { issued.Division = _ddIntendDivisions.Text; } else { issued.Division = lblDivisionOld.Text; //same old value populated } //same wiht chargeable head value if (_ddCHead.SelectedIndex > 0) { issued.ChargeableHeadName = _ddCHead.SelectedItem.ToString(); } else { issued.ChargeableHeadName = lblChHeadOld.Text; } issued.IsDeliveredTemporary = istemporary.Checked ? "Yes" : "No"; issued.ModifiedBy = Convert.ToInt16(Session["USERID"]); //if data is saved in challan table , save into item table StringBuilder sb = new StringBuilder(); // sb.Append("<root>"); issued.VehicleNumber = tbVehicleNumberCaps.Text; issued.ReceiverDesignation = tbReceiverDesignation.Text; issued.Remarks = tbremarks.Text; string insertStatement = "INSERT INTO DeliveryItemsDetails(DeliveryItemsChallanID,ItemName, IssueHeadName,QUANTITY,UNIT,RATE) values('@DeliveryItemsChallanID','@ItemName', '@IssueHeadName', '@QUANTITY', '@UNIT', '@RATE')"; for (int i = 0; i < gvItems.Rows.Count; i++) { //TextBox itemID = gvItems.Rows[i].FindControl("_tbItemID") as TextBox; DropDownList itemName = gvItems.Rows[i].FindControl("_ddItems") as DropDownList; TextBox itemUnit = gvItems.Rows[i].FindControl("_tbUnit") as TextBox; TextBox itemQuantity = gvItems.Rows[i].FindControl("_tbQuantity") as TextBox; //DropDownList itemIHead = gvItems.Rows[i].FindControl("_ddIhead") as DropDownList; //DropDownList ddlRates = gvItems.Rows[i].FindControl("ddlRates") as DropDownList; HiddenField hdnSelectedIssueHead = gvItems.Rows[i].FindControl("hdnSelectedIssueHead") as HiddenField; HiddenField hdnSelectedRate = gvItems.Rows[i].FindControl("hdnSelectedRate") as HiddenField; //SAVE CODE if (itemName.SelectedValue.ToString() != "") { sb.Append(insertStatement.Replace("@DeliveryItemsChallanID", _tbChalanNo.Text).Replace("@ItemName", Utilities.ValidSql(itemName.SelectedItem.ToString())).Replace("@IssueHeadName", hdnSelectedIssueHead.Value).Replace("@QUANTITY", itemQuantity.Text).Replace("@UNIT", itemUnit.Text).Replace("@RATE", hdnSelectedRate.Value)); } } //now save it to db //making sure sb string is not empty if (sb.ToString() != "") { //call the method to save both in primary deliverychallan table and delivery details table akivi.UpdateIssuedItems(issued, orginalChallanID, sb.ToString()); } //what if user doesn't require to add items but to change primary table details only else //else new item(s) not inserted...save only primary table { akivi.UpdateIssuedItems(issued, orginalChallanID); // panelError.Visible = true; // lblError.Text = "Error! Select atleast one item to add."; // panelSuccess.Visible = false; } Session["CHALLANNO"] = _tbChalanNo.Text; // Response.Redirect(Request.Url.ToString()); Response.Redirect("~/Admin/IssuedEntryEdit.aspx?challanid=" + _tbChalanNo.Text); } catch (System.Threading.ThreadAbortException) { //do nothing } catch (SqlException ex) { if (ex.Message.Contains("duplicate key")) { panelError.Visible = true; lblError.Text = "Error! The challan ID already exists. Please use another ID"; panelSuccess.Visible = false; } else { Session["ERRORMSG"] = ex.ToString(); Response.Redirect("Error.aspx"); } } catch (Exception ex) { Session["ERRORMSG"] = ex.ToString(); Response.Redirect("Error.aspx", true); } }