Beispiel #1
0
        private void _Save()
        {
            try
            {
                IsssuedItemsLogic akivi  = new IsssuedItemsLogic();
                properties        issued = new properties();

                issued.ChallanID            = Convert.ToDecimal(_tbChalanNo.Text);
                issued.Date                 = _tbChallanDate.Text;
                issued.IndentValue          = _tbIndentValue.Text;
                issued.Date2                = _tbIntendDate.Text;
                issued.Division             = _ddIntendDivisions.Text;
                issued.ChargeableHeadName   = _ddCHead.SelectedItem.ToString();
                issued.IsDeliveredTemporary = istemporary.Checked ? "Yes" : "No";
                issued.ModifiedBy           = Convert.ToInt16(Session["USERID"]);

                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;

                    if (itemName.SelectedValue.ToString() != "")
                    {
                        sb.Append(insertStatement.Replace("@DeliveryItemsChallanID", _tbChalanNo.Text).Replace("@ItemName", Utilities.ValidSql(itemName.SelectedItem.ToString())).Replace("@IssueHeadName", itemIHead.SelectedItem.ToString()).Replace("@QUANTITY", itemQuantity.Text).Replace("@UNIT", itemUnit.Text).Replace("@RATE", ddlRates.Text));
                        totalAmount += Convert.ToDouble(itemQuantity.Text) * Convert.ToDouble(ddlRates.SelectedValue);
                    }
                }
                issued.TotalAmount = totalAmount;
                //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.SaveIssuedItems(issued, sb.ToString());
                    //Session["CHALLANNO"] = _tbChalanNo.Text;
                    _tbChalanNo.Text = (Convert.ToDouble(_tbChalanNo.Text) + 1).ToString();
                    //to continue with same
                    //   Response.Redirect("IssueEntriesList.aspx");
                }


                else
                {
                    panelError.Visible   = true;
                    lblError.Text        = "Error! Select atleast one item to add.";
                    panelSuccess.Visible = false;
                }
            }

            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;
                    // tbOtEONumber.BorderColor = System.Drawing.Color.Red;
                }
                else
                {
                    Session["ERRORMSG"] = ex.ToString();
                    Response.Redirect("Error.aspx");
                }
            }
            catch (Exception ex)
            {
                Session["ERRORMSG"] = ex.ToString();
                Response.Redirect("Error.aspx", true);
            }
        }
Beispiel #2
0
        //method for saving all the data

        private void _SaveDeliveryItemDetails()
        {
            try
            {
                IsssuedItemsLogic akivi  = new IsssuedItemsLogic();
                properties        issued = new properties();

                issued.ChallanID = Convert.ToDecimal(_tbChalanNo.Text);
                issued.Date2     = DateTime.ParseExact(_tbChallanDate.Text, "dd-MM-yyyy", null).ToString("yyyy-MM-dd");

                //issued.Date = _tbChallanDate.Text;


                issued.IndentValue = _tbIndentValue.Text;

                issued.Date = DateTime.ParseExact(_tbIntendDate.Text, "dd-MM-yyyy", null).ToString("yyyy-MM-dd");
                //issued.Date2 = _tbIntendDate.Text;

                issued.Division             = _ddIntendDivisions.Text;
                issued.ChargeableHeadName   = _ddCHead.SelectedItem.ToString();
                issued.IsDeliveredTemporary = istemporary.Checked ? "Yes" : "No";
                // Session["USERID"] = 1;//setting user id temp here
                issued.ModifiedBy = Convert.ToInt16(Session["USERID"]);
                //  TextBox tbtotalAmount = gvItems.FooterRow.FindControl("tbtotalAmount") as TextBox;
                // issued.TotalAmount = Convert.ToDouble(tbtotalAmount.Text);
                // issued.TotalAmount = Convert.ToDouble(_tbtotalAmount.Text);
                issued.ReceiverDesignation = tbReceiverDesignation.Text;
                issued.VehicleNumber       = tbVehicleNumberCaps.Text.ToUpper();
                issued.Remarks             = tbRemarks.Text;


                //if data is saved in challan table , save into item table
                StringBuilder sb = new StringBuilder();
                //  sb.Append("<root>");
                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));
                        //saving total amount
                        totalAmount += Convert.ToDouble(itemQuantity.Text) * Convert.ToDouble(hdnSelectedRate.Value);
                    }
                }
                issued.TotalAmount = totalAmount;
                //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.SaveIssuedItems(issued, sb.ToString());
                    // Session["CHALLANNO"] = _tbChalanNo.Text;
                    // Response.Redirect(Request.Url.ToString());
                    Response.Redirect("IssuedItemsDetails.aspx?id=" + _tbChalanNo.Text);

                    //Response.Redirect("IssuedEntryEdit.aspx?challanid=" + index);
                }


                else
                {
                    panelError.Visible   = true;
                    lblError.Text        = "Error! Select atleast one item to add.";
                    panelSuccess.Visible = false;
                }
            }

            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;
                    // tbOtEONumber.BorderColor = System.Drawing.Color.Red;
                }
                else
                {
                    Session["ERRORMSG"] = ex.ToString();
                    Response.Redirect("Error.aspx");
                }
            }
            catch (Exception ex)
            {
                Session["ERRORMSG"] = ex.ToString();
                Response.Redirect("Error.aspx", true);
            }
        }