protected void createRfq()
        {
            if (DropDownList_Level1.SelectedValue.Equals("_"))
            {
                Label_Status.Text      = "Please select one product category";
                Label_Status.ForeColor = System.Drawing.Color.Red;
                Label_Status.Visible   = true;

                Button_Submit_Req.Enabled           = true;
                Button_Submit_Next.Enabled          = true;
                Button_Submit_Extra_Prd_Srv.Enabled = true;
            }
            else
            {
                BackEndObjects.RFQDetails rfqObj = new BackEndObjects.RFQDetails();
                BackEndObjects.Id         idGen  = new BackEndObjects.Id();
                String rfqId = "";
                if (Session[SessionFactory.CREATE_RFQ_RFQ_ID] == null)
                {
                    rfqId = idGen.getNewId(BackEndObjects.Id.ID_TYPE_RFQ_STRING);
                    Session[SessionFactory.CREATE_RFQ_RFQ_ID] = rfqId; //store the newly created RFQ id in the session
                }
                if (!TextBox_Spec.Text.Equals(""))
                {
                    getAddintionalProdSrvList();
                    TextBox_Spec.Text = "";
                }

                ArrayList rfqSpecObjList = (ArrayList)Session[SessionFactory.CREATE_RFQ_SELECTED_RFQ_SPEC_MAP];

                //Set the RFQ id for all the  spec objects
                if (rfqSpecObjList != null)
                {
                    for (int i = 0; i < rfqSpecObjList.Count; i++)
                    {
                        ((BackEndObjects.RFQProductServiceDetails)rfqSpecObjList[i]).setRFQId(rfqId);
                    }
                }

                rfqObj.setRFQProdServList(rfqSpecObjList);
                rfqObj.setRFQId(rfqId);
                rfqObj.setCreatedUsr(User.Identity.Name);
                rfqObj.setActiveStat(BackEndObjects.RFQDetails.RFQ_ACTIVE_STAT_ACTIVE);
                rfqObj.setDueDate(TextBox_Within_Date.Text);
                rfqObj.setEntityId(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
                rfqObj.setCreatedEntity(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
                rfqObj.setCurrency(DropDownList_Curr.SelectedValue);
                //     FileUpload1=(FileUpload1 == null ? (FileUpload)Session[SessionFactory.CREATE_RFQ_NDA_FILE] : FileUpload1);
                if (FileUpload1 != null && FileUpload1.HasFile)
                {
                    rfqObj.setFileStream(FileUpload1);
                    rfqObj.setNDADocPathInFileStore(rfqObj.getEntityId());
                }
                else if ((FileUpload)Session[SessionFactory.CREATE_RFQ_NDA_FILE] != null && ((FileUpload)Session[SessionFactory.CREATE_RFQ_NDA_FILE]).HasFile)
                {
                    rfqObj.setFileStream((FileUpload)Session[SessionFactory.CREATE_RFQ_NDA_FILE]);
                    rfqObj.setNDADocPathInFileStore(rfqObj.getEntityId());
                }

                String localId = (!DropDownList_Locality.SelectedValue.Equals("_") && !DropDownList_Locality.SelectedValue.Equals("") ?
                                  DropDownList_Locality.SelectedValue : (!DropDownList_City.SelectedValue.Equals("_") && !DropDownList_City.SelectedValue.Equals("") ?
                                                                         DropDownList_City.SelectedValue : (!DropDownList_State.SelectedValue.Equals("_") && !DropDownList_State.SelectedValue.Equals("") ?
                                                                                                            DropDownList_State.SelectedValue : (!DropDownList_Country.SelectedValue.Equals("_") && !DropDownList_Country.SelectedValue.Equals("") ?
                                                                                                                                                DropDownList_Country.SelectedValue : ""))));

                rfqObj.setLocalityId(localId);
                rfqObj.setSubmitDate(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                rfqObj.setTermsandConds(TextBox_TnC.Text);
                rfqObj.setRFQName(TextBox_Reqr_Name.Text);
                rfqObj.setCreateMode(RFQDetails.CREATION_MODE_AUTO);

                //Set the approval Status
                int rfqLevel = BackEndObjects.MainBusinessEntity.getMainBusinessEntitybyIdwithLessDetailsDB(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString()).getRfqApprovalLevel();
                BackEndObjects.Workflow_Action actionObj = null;
                if (rfqLevel > 0)
                {
                    String reportingToUser = BackEndObjects.userDetails.
                                             getUserDetailsbyIdDB(User.Identity.Name, Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString()).getReportsTo();
                    rfqObj.setApprovalStat(reportingToUser);

                    actionObj = new Workflow_Action();
                    actionObj.setEntId(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
                    actionObj.setUserId(User.Identity.Name);
                    actionObj.setActionTaken(BackEndObjects.Workflow_Action.WORKFLOW_ACTION_ACTION_TAKEN_SUBMITTED);
                    actionObj.setActionDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    actionObj.setContextId(rfqObj.getRFQId());
                    actionObj.setContextName(BackEndObjects.Workflow_Action.WORKFLOW_ACTION_CONTEXT_NAME_RFQ);
                    actionObj.setComment("");
                }
                else
                {
                    rfqObj.setApprovalStat(RFQDetails.RFQ_APPROVAL_STAT_APPROVED);
                }
                rfqObj.setApprovalLevel("0".ToString());

                BackEndObjects.RFQProdServQnty rfqPrdQnty = new BackEndObjects.RFQProdServQnty();
                rfqPrdQnty.setRFQId(rfqObj.getRFQId());
                if (!TextBox_Price_Range_From.Text.Equals(""))
                {
                    rfqPrdQnty.setFromPrice(TextBox_Price_Range_From.Text);
                }
                if (!TextBox_Price_Range_To.Text.Equals(""))
                {
                    rfqPrdQnty.setToPrice(TextBox_Price_Range_To.Text);
                }
                if (!TextBox_Prod_Qnty_From.Text.Equals(""))
                {
                    rfqPrdQnty.setFromQnty(float.Parse(TextBox_Prod_Qnty_From.Text));
                }
                if (!TextBoxrod_Qnty_To.Text.Equals(""))
                {
                    rfqPrdQnty.setToQnty(float.Parse(TextBoxrod_Qnty_To.Text));
                }
                rfqPrdQnty.setMsrmntUnit(DropDownList_Unit_Of_Msrmnt.SelectedValue);
                rfqPrdQnty.setProdCatId(Session[SessionFactory.CREATE_RFQ_SELECTED_PRODUCT_CAT].ToString());
                //ArrayList rfqPrdQntyList = new ArrayList();
                //rfqPrdQntyList.Add(rfqPrdQnty);

                ArrayList prodSrvQntyList = (ArrayList)Session[SessionFactory.CREATE_RFQ_PROD_SRV_QNTY_LIST];

                if (prodSrvQntyList == null)
                {
                    prodSrvQntyList = new ArrayList();
                }

                prodSrvQntyList.Add(rfqPrdQnty);

                //Ensure that all objects in the arraylist has an associated rfqid
                for (int i = 0; i < prodSrvQntyList.Count; i++)
                {
                    BackEndObjects.RFQProdServQnty temp = (RFQProdServQnty)prodSrvQntyList[i];
                    if (temp.getRFQId() == null || temp.getRFQId().Equals(""))
                    {
                        temp.setRFQId(rfqObj.getRFQId());
                    }
                }

                rfqObj.setRFQProdServQntyList(prodSrvQntyList);

                Dictionary <String, String> reqSpecUniqnessValidation = new Dictionary <string, string>();

                if (rfqSpecObjList != null)
                {
                    for (int i = 0; i < rfqSpecObjList.Count; i++)
                    {
                        BackEndObjects.RFQProductServiceDetails rfqSpecObj = (BackEndObjects.RFQProductServiceDetails)rfqSpecObjList[i];
                        if (reqSpecUniqnessValidation.ContainsKey(rfqSpecObj.getPrdCatId() + ":" + rfqSpecObj.getFeatId()))
                        {
                            rfqSpecObjList.RemoveAt(i);//Remove the current RFQ spec object from the list - otherwise it will cause exception at DB layer while inserting
                        }
                        else
                        {
                            reqSpecUniqnessValidation.Add(rfqSpecObj.getPrdCatId() + ":" + rfqSpecObj.getFeatId(), "");
                            if (rfqSpecObj.getFileStream() != null)
                            {
                                rfqSpecObj.setImgPathInFileStore(rfqObj.getEntityId());
                            }
                        }
                    }
                }

                ActionLibrary.PurchaseActions._createRFQ cR = new ActionLibrary.PurchaseActions._createRFQ();
                try
                {
                    cR.createNewRFQ(rfqObj);
                    if (actionObj != null)
                    {
                        BackEndObjects.Workflow_Action.insertWorkflowActionObject(actionObj);
                    }

                    Label_Status.Text      = "RFQ created successfully....You MUST broadcast an RFQ for vendors to see!" + (rfqLevel == 0 ? " RFQ will be auto approved as there is no approval rule set in Administration->WorkflowMgmt->RFQ" : "");
                    Label_Status.ForeColor = System.Drawing.Color.Green;
                    Label_Status.Visible   = true;

                    //Refresh the parent grid
                    DataTable dt = (DataTable)Session[SessionFactory.ALL_PURCHASE_ALL_RFQ_GRID_DATA];
                    Dictionary <String, Currency> allCurrList = (Dictionary <String, Currency>)Session[SessionFactory.CURRENCY_LIST];

                    dt.Rows.Add();
                    int i = dt.Rows.Count - 1;

                    String docName = "";
                    if (rfqObj.getNDADocPath() != null)
                    {
                        String[] docPathList = rfqObj.getNDADocPath().
                                               Split(new String[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
                        if (docPathList.Length > 0)
                        {
                            docName = docPathList[docPathList.Length - 1];
                        }
                    }

                    DateUtility dU = new DateUtility();

                    dt.Rows[i]["RFQNo"]       = rfqObj.getRFQId();
                    dt.Rows[i]["RFQName"]     = rfqObj.getRFQName();
                    dt.Rows[i]["Submit Date"] = rfqObj.getSubmitDate();
                    dt.Rows[i]["curr"]        = allCurrList.ContainsKey(rfqObj.getCurrency()) ?
                                                allCurrList[rfqObj.getCurrency()].getCurrencyName() : "";
                    dt.Rows[i]["Submit Date Ticks"] = Convert.ToDateTime(rfqObj.getSubmitDate()).Ticks;
                    dt.Rows[i]["Due Date"]          = dU.getConvertedDateWoTime(rfqObj.getDueDate());
                    dt.Rows[i]["Due Date Ticks"]    = !dt.Rows[i]["Due Date"].Equals("")?Convert.ToDateTime(dt.Rows[i]["Due Date"]).Ticks:0;
                    dt.Rows[i]["ApprovalStat"]      = rfqObj.getApprovalStat();
                    dt.Rows[i]["Po_No"]             = "N/A";
                    dt.Rows[i]["Hidden_Doc_Name"]   = (docName == null || docName.Equals("") ? "" : docName);
                    dt.Rows[i]["ActiveStatus"]      = rfqObj.getActiveStat();
                    dt.Rows[i]["Inv_No"]            = "N/A";

                    dt.DefaultView.Sort = "Submit Date Ticks" + " " + "DESC";
                    Session[SessionFactory.ALL_PURCHASE_ALL_RFQ_GRID_DATA] = dt.DefaultView.ToTable();
                    ScriptManager.RegisterStartupScript(this, typeof(string), "RefreshRefqGrid", "RefreshParent();", true);
                }

                catch (Exception ex)
                {
                    Label_Status.Text      = "RFQ creation failed";
                    Label_Status.ForeColor = System.Drawing.Color.Red;
                    Label_Status.Visible   = true;
                }
                finally
                {
                    Session.Remove(SessionFactory.CREATE_RFQ_SELECTED_RFQ_SPEC_MAP);
                    Session.Remove(SessionFactory.CREATE_RFQ_RFQ_ID);
                    Session.Remove(SessionFactory.CREATE_RFQ_PROD_SRV_QNTY_LIST);
                    Session.Remove(SessionFactory.CREATE_RFQ_NDA_FILE);
                }
            }
        }