示例#1
0
    protected void gvInspecrionSchedule_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "onDelete")
            {
                objInsp.Del_ScheduledInspection(UDFLib.ConvertIntegerToNull(e.CommandArgument.ToString()), UDFLib.ConvertIntegerToNull(Session["USERID"]));
                Load_Current_Schedules();
            }
            if (e.CommandName == "ReOpen")
            {
                ViewState["SchDetailId"] = UDFLib.ConvertToInteger(e.CommandArgument.ToString().Split(';')[0]);;
            }
            if (e.CommandName.ToUpper() == "EDIT_SCHEDULE")
            {
            }
            if (e.CommandName.ToUpper() == "INSPUPD")
            {
                if (ViewState["edit"].ToString() == "0")
                {
                    btnUpdateInspection.Enabled = false;
                }

                ViewState["ShowImages"]  = 0;
                ViewState["SchDetailId"] = 1;
                string js;

                DataTable dtSup = objInsp.Get_Supritendent_Users(null, UDFLib.ConvertToInteger(e.CommandArgument.ToString().Split(';')[8]));

                if (dtSup != null)
                {
                    if (dtSup.Rows.Count > 0)
                    {
                        DDLInspectorA.DataSource     = dtSup;
                        DDLInspectorA.DataTextField  = "Name";
                        DDLInspectorA.DataValueField = "UserID";
                        DDLInspectorA.DataBind();
                        DDLInspectorA.Items.Insert(0, new ListItem("--SELECT--", null));
                        txtInsectionDate.Text = DateTime.Now.ToString("dd/MMM/yy");


                        ViewState["ScheduleID"]  = UDFLib.ConvertToInteger(e.CommandArgument.ToString().Split(';')[0]);
                        ViewState["SchDetailId"] = UDFLib.ConvertToInteger(e.CommandArgument.ToString().Split(';')[2]);
                        try
                        {
                            try
                            {
                                DDLInspectorA.SelectedValue = e.CommandArgument.ToString().Split(';')[1];
                            }
                            catch (Exception)
                            {
                                DDLInspectorA.SelectedValue = e.CommandArgument.ToString().Split(';')[4];
                            }
                        }
                        catch (Exception)
                        {
                            DDLInspectorA.SelectedIndex = 0;
                        }

                        try
                        {
                            txtInsectionDate.Text = Convert.ToDateTime(e.CommandArgument.ToString().Split(';')[5]).ToString("dd/MMM/yy");
                        }
                        catch (Exception)
                        {
                            txtInsectionDate.Text = Convert.ToDateTime(e.CommandArgument.ToString().Split(';')[6]).ToString("dd/MMM/yy");
                        }

                        try
                        {
                            hdfNewinspectionPortid.Value = "";
                            DataSet   dtAssignPortList = objInsp.INSP_Get_InspectionPort(UDFLib.ConvertToInteger(e.CommandArgument.ToString().Split(';')[2]));
                            DataTable dtPort           = objInfra.Get_PortList();

                            DDLPort.DataSource     = dtPort;
                            DDLPort.DataValueField = "PORT_ID";
                            DDLPort.DataTextField  = "PORT_NAME";
                            DDLPort.DataBind();
                            DDLPort.Items.Insert(0, new ListItem("-SELECT-", null));

                            if (dtAssignPortList.Tables[0].Rows.Count > 0)
                            {
                                try
                                {
                                    DDLPort.SelectedValue = dtAssignPortList.Tables[0].Rows[0]["PortID"].ToString();
                                }
                                catch { }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }


                        txtDurJobsU.Text = e.CommandArgument.ToString().Split(';')[7].ToString();
                        txtDuration.Text = e.CommandArgument.ToString().Split(';')[7].ToString();
                        DateTime dt = Convert.ToDateTime(txtInsectionDate.Text);
                        dt = dt.AddDays(UDFLib.ConvertToDouble(txtDuration.Text) - 1);
                        txtCompletionDate.Text = dt.ToString("dd/MMM/yy");
                        txtOnboard.Text        = "";
                        txtOnShore.Text        = "";
                        txtDuration.Text       = "";
                        rdbCompleted.Checked   = false;
                        rdbPlanned.Checked     = true;

                        js = " $('#divAddSystem').prop('title', 'Update Inspection');showModal('dvUpdateInspe',false);";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "showModalJS", js, true);

                        js = " $('#dvUpdateInspe').prop('title', 'Update Inspection');";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "", js, true);

                        js = "handleStatus();";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "handleModal", js, true);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
        }
    }
    protected void Load_Schedule(int ScheduleID, int SchDetailId)
    {
        try
        {
            ViewState["AddEditFlag"] = "Edit";

            DataTable dtVessel = objVsl.Get_VesselList(0, 0, Convert.ToInt32(0), "", Convert.ToInt32(Session["USERCOMPANYID"].ToString()));
            DDLVesselP.DataSource     = dtVessel;
            DDLVesselP.DataTextField  = "Vessel_name";
            DDLVesselP.DataValueField = "Vessel_id";
            DDLVesselP.DataBind();
            DDLVesselP.Items.Insert(0, new ListItem("-- Select --", null));
            ViewState["ScheduleID"]  = ScheduleID;
            DDLFleetP.SelectedIndex  = 0;
            DDLCompany.SelectedIndex = 0;
            int     Me = 0;
            DataSet ds = objInsp.Get_Schedule_Details(ScheduleID, GetSessionUserID(), SchDetailId, 0);
            if (ds != null)
            {
                DataTable dtSchedule          = ds.Tables[0];
                DataTable dtSettings          = ds.Tables[1];
                DataTable dtInpectionSchedule = ds.Tables[2];

                Session["dtInpectionSchedule"] = dtInpectionSchedule;

                if (dtSchedule.Rows.Count > 0)
                {
                    ViewState["ScheduleID"] = dtSchedule.Rows[0]["ScheduleID"].ToString();

                    txtStartDate.Text = UDFLib.ConvertDateToNull(dtSchedule.Rows[0]["Start_Date"]).Value.ToString("dd/MMM/yy");
                    if (UDFLib.ConvertDateToNull(dtSchedule.Rows[0]["End_Date"]) != null)
                    {
                        txtEndDate.Text = UDFLib.ConvertDateToNull(dtSchedule.Rows[0]["End_Date"]).Value.ToString("dd/MMM/yy");
                    }
                    rdoFrequency.SelectedValue = dtSchedule.Rows[0]["FrequencyType"].ToString();

                    txtWeek.Text = dtSchedule.Rows[0]["Frequency"].ToString();
                    rdoFrequency_SelectedIndexChanged(null, null);
                    txtInspRemark.Text       = dtSchedule.Rows[0]["Schedule_Desc"].ToString();
                    DDLVesselP.SelectedValue = dtSchedule.Rows[0]["Vessel_ID"].ToString();
                    DDLVessselP_SelectedIndexChanged(null, null);
                    try
                    {
                        DDLInspectorP.SelectedValue = dtSchedule.Rows[0]["InspectorID"].ToString();
                    }
                    catch (Exception)
                    {
                        DDLInspectorP.SelectedIndex = 0;
                    }

                    try
                    {
                        if (dtSchedule.Rows[0]["InspectionTypeId"].ToString().Trim().Length > 0)
                        {
                            ddlInspectionTypeP.SelectedValue = dtSchedule.Rows[0]["InspectionTypeId"].ToString();
                        }
                    }
                    catch (Exception)
                    {
                        ddlInspectionTypeP.SelectedIndex = 0;
                        ddlInspectionTypeP.Enabled       = true;
                    }
                    txtDurJobs.Text = dtSchedule.Rows[0]["DurJobs"].ToString();
                }

                if (dtSettings.Rows.Count > 0)
                {
                    if (rdoFrequency.SelectedValue == "Onetime")
                    {
                        txtOneTime.Text = GetSettingDateValue(dtSettings, "OneTime", "");
                    }

                    if (rdoFrequency.SelectedValue == "Weekly")
                    {
                        DataTable dtWeekdays = GetSettingTable(dtSettings, "WEEKDAYS");

                        chkWeekDays.ClearSelection();
                        foreach (DataRow dr in dtWeekdays.Rows)
                        {
                            chkWeekDays.Items[UDFLib.ConvertToInteger(dr["key_value_int"]) - 1].Selected = true;
                        }
                    }
                    if (rdoFrequency.SelectedValue == "Monthwise")
                    {
                        DataTable dtMonthWise = GetSettingTable(dtSettings, "MONTHWISE");

                        chkMonthWise.ClearSelection();
                        foreach (DataRow dr in dtMonthWise.Rows)
                        {
                            chkMonthWise.Items[UDFLib.ConvertToInteger(dr["key_value_int"]) - 1].Selected = true;
                        }
                    }
                    if (rdoFrequency.SelectedValue == "Duration")
                    {
                        ddlDuration.SelectedValue = GetSettingTable(dtSettings, "Duration").Rows[0]["key_value_int"].ToString();
                    }

                    DataTable dtEmailDays = GetSettingTable(dtSettings, "EmailDays");
                    if (dtEmailDays.Rows.Count > 0)
                    {
                        if (UDFLib.ConvertToInteger(dtEmailDays.Rows[0]["key_value_int"]) > 0)
                        {
                            chkSendEmail.Checked        = true;
                            ddlDaysBefore.SelectedValue = UDFLib.ConvertToInteger(dtEmailDays.Rows[0]["key_value_int"]).ToString();
                        }
                        else
                        {
                            chkSendEmail.Checked = false;
                        }
                    }

                    DataTable dtImages = GetSettingTable(dtSettings, "ShowImages");
                    if (dtImages.Rows.Count > 0)
                    {
                        if (UDFLib.ConvertToInteger(dtImages.Rows[0]["key_value_int"]) == 1)
                        {
                            chkImages.Checked = true;
                        }
                        else
                        {
                            chkImages.Checked = false;
                        }
                    }

                    DataSet dsPorts = objInsp.INSP_Get_InspectionPort(SchDetailId);

                    if (dsPorts.Tables[0].Rows.Count > 0)
                    {
                        try
                        {
                            drpPort.SelectedValue = dsPorts.Tables[0].Rows[0]["PortID"].ToString();
                        }
                        catch { }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
        }
    }