예제 #1
0
    public void BindIndex()
    {
        int?Vessel_ID = null;

        if (DDLVessel.SelectedIndex > 0)
        {
            Vessel_ID = UDFLib.ConvertIntegerToNull(DDLVessel.SelectedValue);
        }


        DataTable drilltable = BLL_LMS_Training.GET_DRILL_SCHEDULE(Vessel_ID);

        DataTable dt = UDFLib.PivotTable("PROGRAM_NAME", "SCHEDULED_DATE", "PROGRAM_ID", new string[] { "VESSEL_ID" }, new string[] { "VESSEL_ID", "ID", "PROGRAM_ID" }, drilltable);


        gvDrill.DataSource = dt;
        gvDrill.DataBind();

        int[] freq = new int[50];

        if (dt.Rows.Count > 0)
        {
            GridViewRow RowHeader = gvDrill.HeaderRow;
            int         j         = 2;
            foreach (TableCell cell in RowHeader.Cells)
            {
                //string[] hrow = (cell.Controls[0] as LinkButton).Text.Split('~');
                string[] hrow = cell.Text.Split('~');

                if (hrow.Length > 1)
                {
                    cell.Text = hrow[0] + "<br>" + hrow[1];
                    freq[j]   = int.Parse(hrow[1].Split(' ')[0]);
                    j++;
                }
            }

            foreach (GridViewRow gr in gvDrill.Rows)
            {
                j = 0;
                foreach (TableCell cell in gr.Cells)
                {
                    if (cell.Text == "Not Applicable")
                    {
                        cell.ForeColor = System.Drawing.Color.Blue;
                    }
                    if (j > 1 && cell.Text != "Not Applicable" && cell.Text.Trim() != "" && cell.Text.Trim() != "&nbsp;")
                    {
                        DateTime testDateTime = new DateTime();
                        if (DateTime.TryParse(cell.Text, out testDateTime))
                        {
                            if (Convert.ToDateTime(testDateTime).AddDays(freq[j]).CompareTo(DateTime.Now) < 1)
                            {
                                cell.BackColor = System.Drawing.Color.Tomato;
                                cell.ForeColor = System.Drawing.Color.White;
                            }
                        }
                    }
                    j++;
                }
            }
        }
    }