Exemple #1
0
    protected void btnUpdateInspection_Click(object sender, EventArgs e)
    {
        try
        {
            string js;

            if (UDFLib.ConvertDateToNull(txtInsectionDate.Text) == null)
            {
                js = "handleStatus();alert('Select valid date.');";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "hideModalJS", js, true);
                return;
            }
            if (DDLInspectorA.SelectedIndex == 0)
            {
                js = "handleStatus();alert('Select valid inspector.');";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "hideModalJS", js, true);
                return;
            }
            int    onboard = 0;
            int    onshore = 0;
            string Status  = "Pending";


            if (rdbPlanned.Checked)
            {
                if (UDFLib.ConvertIntegerToNull(txtDurJobsU.Text) == null)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "", "handleStatus();alert('Duration is not valid.');", true);
                    return;
                }
                if (UDFLib.ConvertIntegerToNull(txtDurJobsU.Text) <= 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "", "handleStatus();alert('Duration cannot be smaller than or equal to zero.');", true);
                    return;
                }
            }
            if (rdbCompleted.Checked)
            {
                if (UDFLib.ConvertDateToNull(txtCompletionDate.Text) != null)
                {
                    if (UDFLib.ConvertDateToNull(txtCompletionDate.Text).Value.Date < UDFLib.ConvertDateToNull(txtInsectionDate.Text).Value.Date)
                    {
                        txtCompletionDate.Text = "";
                        txtOnboard.Text        = "";
                        txtOnShore.Text        = "";
                        txtDuration.Text       = "";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "", "handleStatus();alert('Completion date can not be lesser than the scheduled date.');", true);
                        return;
                    }
                    txtDuration.Text = (UDFLib.ConvertDateToNull(txtCompletionDate.Text).Value.Date.AddDays(1) - UDFLib.ConvertDateToNull(txtInsectionDate.Text).Value.Date).Days.ToString();
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('Completion date can not be empty.');handleStatus();", true);
                    return;
                }

                Status = "Completed";

                try
                {
                    onboard = Convert.ToInt32(txtOnboard.Text);
                }
                catch (Exception)
                {
                    js = "handleStatus();alert('Onboard duration is not valid.');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "hideModalJS", js, true);
                    return;
                }

                try
                {
                    onshore = Convert.ToInt32(txtOnShore.Text);
                }
                catch (Exception)
                {
                    js = "handleStatus();alert('Onshore duration is not valid.');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "hideModalJS", js, true);
                    return;
                }

                int duration = Convert.ToInt32(txtDuration.Text);

                if (duration != (onboard + onshore))
                {
                    js = "handleStatus();alert('Sum of onboard value and onshore should match duration value.');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "hideModalJS", js, true);
                    return;
                }
                if ((Convert.ToInt32(txtOnShore.Text) < 0) || (Convert.ToInt32(txtOnboard.Text) < 0))
                {
                    js = "handleStatus();alert('Onboard value or onshore value can not be negative.');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "hideModalJS", js, true);
                    return;
                }

                if (UDFLib.ConvertDateToNull(txtCompletionDate.Text).Value.Date > DateTime.Now.Date)
                {
                    js = "handleStatus();alert('Completion date cannot be a future date.');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", js, true);
                    return;
                }
            }

            if (DDLPort.SelectedIndex == 0)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "", "handleStatus();alert('No ports selected.');", true);
                return;
            }


            objInsp.Update_Inspection(UDFLib.ConvertToInteger(ViewState["SchDetailId"]), UDFLib.ConvertToInteger(DDLInspectorA.SelectedValue), UDFLib.ConvertDateToNull(txtInsectionDate.Text), Status, GetSessionUserID(), onboard, onshore, UDFLib.ConvertDateToNull(txtCompletionDate.Text), UDFLib.ConvertIntegerToNull(txtDurJobsU.Text));

            DataTable dtPortList = NewDaemonPortList();
            dtPortList.Rows.Add(DDLPort.SelectedValue.ToString());

            foreach (string newPortid in hdfNewinspectionPortid.Value.Split(','))
            {
                if (UDFLib.ConvertToInteger(newPortid) > 0 && dtPortList.Rows.Find(UDFLib.ConvertToInteger(newPortid)) == null)
                {
                    dtPortList.Rows.Add((dtPortList.NewRow()["PortID"] = newPortid));
                }
            }


            objInsp.INSP_InsertUpdate_InspectionPort(dtPortList, UDFLib.ConvertToInteger(ViewState["SchDetailId"]), GetSessionUserID());
            js = "handleStatus();alert('Inspection updated successfully.');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "hideModalJS", js, true);

            js = "handleStatus();hideModal('dvUpdateInspe');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "dvUpdateInspe", js, true);
            Load_Current_Schedules();
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
        }
    }