protected void btnAddPPE_Click(object sender, EventArgs e)
 {
     if (isValidPPE(tbPPE.Text))
     {
         DepartmentOrderDetailTableAdapters.DepartmentOrderPPETableAdapter tableAdapter = new DepartmentOrderDetailTableAdapters.DepartmentOrderPPETableAdapter();
         tableAdapter.Insert(departmentId, loggedInUserCoId, int.Parse(Request[WebConstants.Request.DEPT_ORDER_ID]), tbPPE.Text, loggedInUserId);
         gvPPE.DataBind();
         tbPPE.Text = "";
         BindRepeater();
     }
 }
 protected void btnAddPPEs_Click(object sender, EventArgs e)
 {
     DepartmentOrderDetailTableAdapters.DepartmentOrderPPETableAdapter tableAdapter = new DepartmentOrderDetailTableAdapters.DepartmentOrderPPETableAdapter();
    foreach (RepeaterItem repeaterItem in rptPPE.Items)
     {
         CheckBoxList cbPPE = repeaterItem.FindControl("cbPPE") as CheckBoxList;
         foreach (ListItem listItem in cbPPE.Items)
         {
             if (listItem.Selected)
             {
                 tableAdapter.Insert(departmentId, loggedInUserCoId, int.Parse(Request[WebConstants.Request.DEPT_ORDER_ID]), listItem.Text, loggedInUserId);
             }
         }
     }
     gvPPE.DataBind();
     BindRepeater();
 }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(this.tbPPE.Text))
        {
            Company.un_co_detailsRow dr = GetCompany();
            if (dr != null && dr.Isflg_autosaveNull() == false && dr.flg_autosave)
            {
                if (isValidPPE(tbPPE.Text))
                {
                    DepartmentOrderDetailTableAdapters.DepartmentOrderPPETableAdapter tableAdapter = new DepartmentOrderDetailTableAdapters.DepartmentOrderPPETableAdapter();
                    tableAdapter.Insert(departmentId, loggedInUserCoId, int.Parse(Request[WebConstants.Request.DEPT_ORDER_ID]), tbPPE.Text, loggedInUserId);
                    Response.Redirect("~/Orders/AddOrderEmergencyExits.aspx?" + WebConstants.Request.DEPT_ORDER_ID + "=" + Request[WebConstants.Request.DEPT_ORDER_ID]);
                }
            }
            else
                SetErrorMessage(WebConstants.Messages.Error.NEXT_WARNING_COMPANYAUTOSAVE);

        }
        else if (this.gvPPE.Rows.Count > 0)
        {
            Response.Redirect("~/Orders/AddOrderEmergencyExits.aspx?" + WebConstants.Request.DEPT_ORDER_ID + "=" + Request[WebConstants.Request.DEPT_ORDER_ID]);
        }
        else
            SetErrorMessage(WebConstants.Messages.Error.NEXT_WARNING_ENTERRECORD);
    }
    protected void btnCopy_Click(object sender, EventArgs e)
    {
        DepartmentOrder.DepartmentOrderRowRow order = DatabaseUtility.GetDepartmentOrder(int.Parse(hfSourceOrderId.Value));
        if (order != null)
        {
            Nullable<bool> flgDocToClient = null;
            Nullable<int> estWork = null;
            Nullable<bool> multiEmerExits = null;
            Nullable<bool> multiAssemPts = null;
            Nullable<bool> flgCancelled = null;
            Nullable<DateTime> dateCancelled = null;
            Nullable<int> estNumOfOperatives = null;
            if (order.Isflg_order_doc_to_clientNull() == false) flgDocToClient = order.flg_order_doc_to_client;
            if (order.Isorder_est_of_worksNull() == false) estWork = order.order_est_of_works;
            if (order.Isflg_multi_emer_exitsNull() == false) multiEmerExits = order.flg_multi_emer_exits;
            if (order.Isflg_multi_assem_pointsNull() == false) multiAssemPts = order.flg_multi_assem_points;
            if (order.Isflg_cancelledNull() == false) flgCancelled = order.flg_cancelled;
            if (order.Isdate_cancelledNull() == false) dateCancelled = order.date_cancelled;
            if (order.Isest_num_of_operativesNull() == false) estNumOfOperatives = order.est_num_of_operatives;

            DepartmentOrderTableAdapters.DepartmentOrderRowTableAdapter da = new DepartmentOrderTableAdapters.DepartmentOrderRowTableAdapter();
            IEnumerator iEnum = da.InsertAndReturn(false, order.dept_id, order.co_id, order.order_ref, order.order_client_ref, order.order_sms,
                DateTime.Now, estWork, DateTime.Now.AddYears(1), flgDocToClient, tbAddressNo.Text,tbAddress1.Text,tbAddress2.Text,tbAddress3.Text,
                tbAddress4.Text,tbAddress5.Text,tbPostalCode.Text,getFullAddress(),(order.Isorder_descNull()) ? null : order.order_desc,
                multiEmerExits, multiAssemPts, flgCancelled, dateCancelled,(order.Isdesc_of_workNull()) ? null : order.desc_of_work,estNumOfOperatives,
                (order.Isrisk_takingNull())?null:order.risk_taking,loggedInUserId, DateTime.Now, loggedInUserId, DateTime.Now).GetEnumerator();
            if (iEnum.MoveNext())
            {
                DepartmentOrder.DepartmentOrderRowRow newOrder = (DepartmentOrder.DepartmentOrderRowRow)iEnum.Current;

                //copy persons
                DepartmentOrderPersonTableAdapters.DepartmentOrderPersonEntityTableAdapter personTA = new DepartmentOrderPersonTableAdapters.DepartmentOrderPersonEntityTableAdapter();
                IEnumerator iEPerson = personTA.GetAllOrderPersonsByOrderId(order.dept_id, order.co_id, order.sequence).GetEnumerator();

                while (iEPerson.MoveNext())
                {
                    DepartmentOrderPerson.DepartmentOrderPersonEntityRow personDR = (DepartmentOrderPerson.DepartmentOrderPersonEntityRow)iEPerson.Current;
                    Nullable<bool> flgSupervisor = null;
                    Nullable<bool> flgFirstAider = null;
                    Nullable<bool> flgFireWarden = null;
                    string personName = (personDR.Isname_descNull()) ? null : personDR.name_desc;
                    if (personDR.Issuperrvisor_checkNull() == false) flgSupervisor = Convert.ToBoolean(personDR.superrvisor_check);
                    if (personDR.Isfirstaiderr_checkNull() == false) flgFirstAider = Convert.ToBoolean(personDR.firstaiderr_check);
                    if (personDR.Isfirewardenn_checkNull() == false) flgFireWarden = Convert.ToBoolean(personDR.firewardenn_check);

                    personTA.Insert(personDR.dept_id, personDR.co_id, newOrder.sequence, personName, loggedInUserId, flgSupervisor, flgFirstAider, flgFireWarden,false);
                }

                //copy hazards
                DepartmentOrderDetailTableAdapters.DepartmentOrderHazardTableAdapter hazaradTA = new DepartmentOrderDetailTableAdapters.DepartmentOrderHazardTableAdapter();
                IEnumerator iEHazard = hazaradTA.GetAllHazards(order.dept_id, order.co_id, order.sequence).GetEnumerator();
                while (iEHazard.MoveNext())
                {
                    DepartmentOrderDetail.DepartmentOrderHazardRow hazardDR = (DepartmentOrderDetail.DepartmentOrderHazardRow)iEHazard.Current;
                    hazaradTA.Insert(order.dept_id, order.co_id, newOrder.sequence, hazardDR.hazard_desc, loggedInUserId);
                }

                //copy sequence of work
                DepartmentOrderDetailTableAdapters.DepartmentOrderWorkTableAdapter workTA = new DepartmentOrderDetailTableAdapters.DepartmentOrderWorkTableAdapter();
                IEnumerator iEWork = workTA.GetAllWorks(order.dept_id, order.co_id, order.sequence).GetEnumerator();
                while (iEWork.MoveNext())
                {
                    DepartmentOrderDetail.DepartmentOrderWorkRow workDR = (DepartmentOrderDetail.DepartmentOrderWorkRow)iEWork.Current;
                    workTA.Insert(order.dept_id, order.co_id, newOrder.sequence, workDR.work_desc, loggedInUserId);
                }

                //copy plats and tools
                DepartmentOrderDetailTableAdapters.DepartmentOrderToolTableAdapter toolTA = new DepartmentOrderDetailTableAdapters.DepartmentOrderToolTableAdapter();
                IEnumerator iETool = toolTA.GetAllDepartmentTool(order.dept_id, order.co_id, order.sequence).GetEnumerator();
                while (iETool.MoveNext())
                {
                    DepartmentOrderDetail.DepartmentOrderToolRow toolDR = (DepartmentOrderDetail.DepartmentOrderToolRow)iETool.Current;
                    toolTA.Insert(order.dept_id, order.co_id, newOrder.sequence, toolDR.tool_desc, loggedInUserId);
                }

                //copy PPE
                DepartmentOrderDetailTableAdapters.DepartmentOrderPPETableAdapter ppeTA = new DepartmentOrderDetailTableAdapters.DepartmentOrderPPETableAdapter();
                IEnumerator iEPPE = ppeTA.GetAllPPE(order.dept_id, order.co_id, order.sequence).GetEnumerator();
                while (iEPPE.MoveNext())
                {
                    DepartmentOrderDetail.DepartmentOrderPPERow ppeDR = (DepartmentOrderDetail.DepartmentOrderPPERow)iEPPE.Current;
                    ppeTA.Insert(order.dept_id, order.co_id, newOrder.sequence, ppeDR.ppe_desc, loggedInUserId);
                }

                //copy Emergency
                DepartmentOrderDetailTableAdapters.DepartmentOrderEmergencyExitTableAdapter emergencyTA = new DepartmentOrderDetailTableAdapters.DepartmentOrderEmergencyExitTableAdapter();
                IEnumerator iEEmergency = emergencyTA.GetAllEmergencyExits(order.dept_id, order.co_id, order.sequence).GetEnumerator();
                while (iEEmergency.MoveNext())
                {
                    DepartmentOrderDetail.DepartmentOrderEmergencyExitRow emergencyDR = (DepartmentOrderDetail.DepartmentOrderEmergencyExitRow)iEEmergency.Current;
                    emergencyTA.Insert(order.dept_id, order.co_id, newOrder.sequence, emergencyDR.emer_exit_title, null, loggedInUserId);
                }

                //copy Requirements
                DepartmentOrderDetailTableAdapters.DepartmentOrderRequirementTableAdapter requirementTA = new DepartmentOrderDetailTableAdapters.DepartmentOrderRequirementTableAdapter();
                IEnumerator iERequirements = requirementTA.GetAllRequirements(order.dept_id,order.co_id,order.sequence).GetEnumerator();
                while(iERequirements.MoveNext())
                {
                    DepartmentOrderDetail.DepartmentOrderRequirementRow requirementDR = (DepartmentOrderDetail.DepartmentOrderRequirementRow)iERequirements.Current;
                    requirementTA.Insert(order.dept_id,order.co_id,newOrder.sequence,requirementDR.requirement_header,null,loggedInUserId);
                }

                //copy Aspects
                DepartmentOrderDetailTableAdapters.DepartmentOrderKeyAspectsTableAdapter aspectsTA = new DepartmentOrderDetailTableAdapters.DepartmentOrderKeyAspectsTableAdapter();
                IEnumerator iEAspects = aspectsTA.GetAllKeyAspects(order.dept_id,order.co_id,order.sequence).GetEnumerator();
                while(iEAspects.MoveNext())
                {
                    DepartmentOrderDetail.DepartmentOrderKeyAspectsRow aspectsDR = (DepartmentOrderDetail.DepartmentOrderKeyAspectsRow)iEAspects.Current;
                    aspectsTA.Insert(order.dept_id,order.co_id,newOrder.sequence,aspectsDR.key_aspect_header,null,loggedInUserId);
                }

                //copy Docs

                DepartmentOrderDocTableAdapters.DepartmentOrderDocTableAdapter docTA = new DepartmentOrderDocTableAdapters.DepartmentOrderDocTableAdapter();
                IEnumerator iEDocs = docTA.GetAllDocs(order.co_id,order.dept_id,order.sequence).GetEnumerator();
                while(iEDocs.MoveNext())
                {
                    DepartmentOrderDoc.DepartmentOrderDocEntityRow docDR = (DepartmentOrderDoc.DepartmentOrderDocEntityRow)iEDocs.Current;
                    docTA.Insert(newOrder.sequence,docDR.doc_id,order.dept_id,order.co_id,false);
                }
            }
        }

        GridView1.DataBind();
    }