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);
            }
        }
        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);
            }
        }
        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);
            }
        }
Beispiel #4
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);
            }
        }