Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["user"] != null)
            {
                string decoded_username = Encoding.UTF8.GetString(MachineKey.Unprotect(Convert.FromBase64String(Request.Cookies["user"]["username"]), "ProtectCookieUsername"));
                string decoded_role = Encoding.UTF8.GetString(MachineKey.Unprotect(Convert.FromBase64String(Request.Cookies["user"]["role"]), "ProtectCookieRole"));

                if (decoded_role == "admin")
                {

                }

                else
                {
                    Response.Redirect("~/");
                }
            }

            else
            {
                Response.Redirect("~/");
            }

            if (!String.IsNullOrEmpty(Request.QueryString["id"]))
            {
                id = Convert.ToInt32(Request.QueryString["id"]);
            }

            int isNew = Convert.ToInt32(Request.QueryString["new"]);

            if (!IsPostBack)
            {
                if (isNew == 1)
                {
                        model NewModel = new model()
                        {
                            _interface=1,
                            cord = "this is a new item"
                        };

                        Support s = new Support();
                        s.models.Add(NewModel);
                        s.SaveChanges();
                        id = NewModel.id;
                }
                else
                {
                    try
                    {
                        Support support = new Support();
                        var model = from m in support.models
                                    where m.id == id
                                    select new
                                    {
                                        m.name,
                                        m._interface,
                                        m.cord
                                    };

                        //name
                        if (!String.IsNullOrEmpty(model.FirstOrDefault().name))
                        {
                            name = model.FirstOrDefault().name.ToString();
                            detailmodel_name.Text = name;
                        }
                        else
                        {
                            name = "No name...";
                        }

                        //cord
                        desc = model.FirstOrDefault().cord.ToString();
                        detailmodel_cord.Text = desc;

                        utils u = new utils();

                        //interface
                        detailmodel_interface.Text = u.interfaceUntil(model.FirstOrDefault()._interface);

                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex);
                    }

                    using (Support s = new Support())
                    {
                        var target = (from x in s.models
                                      where x.id == id
                                      select x).FirstOrDefault();
                        detailmodel_interface.SelectedValue = target._interface.ToString();
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                /*
                //Get the LinkButton control in the first cell
                LinkButton _doubleClickButton = (LinkButton)e.Row.Cells[0].Controls[0].FindControl("CaseDoubleClick");
                //Get the javascript which is assigned to this LinkButton
                string _jsDouble =
                ClientScript.GetPostBackClientHyperlink(_doubleClickButton, "");
                //Add this JavaScript to the ondblclick Attribute of the row
                e.Row.Attributes["ondblclick"] = _jsDouble;
                */

                //if (!String.IsNullOrEmpty(e.Row.Cells[7].Text))
                //{
                //    int num = Convert.ToInt32(e.Row.Cells[7].Text);
                //    e.Row.Cells[7].Text = workstatus(num);
                //    e.Row.Cells[7].BackColor = statusColor(num);
                //}

                //if (!String.IsNullOrEmpty(e.Row.Cells[8].Text))
                //{
                //    int num = Convert.ToInt32(e.Row.Cells[8].Text);
                //    e.Row.Cells[8].Text = workstatus(num);
                //    e.Row.Cells[8].BackColor = statusColor(num);
                //}

                //if (!String.IsNullOrEmpty(e.Row.Cells[9].Text))
                //{
                //    int num = Convert.ToInt32(e.Row.Cells[9].Text);
                //    e.Row.Cells[9].Text = workstatus(num);
                //    e.Row.Cells[9].BackColor = statusColor(num);
                //}

                //if (!String.IsNullOrEmpty(e.Row.Cells[10].Text))
                //{
                //    int num = Convert.ToInt32(e.Row.Cells[10].Text);
                //    e.Row.Cells[10].Text = workstatus(num);
                //    e.Row.Cells[10].BackColor = statusColor(num);
                //}

                //if (!String.IsNullOrEmpty(e.Row.Cells[11].Text))
                //{
                //    int num = Convert.ToInt32(e.Row.Cells[11].Text);
                //    e.Row.Cells[11].Text = workstatus(num);
                //    e.Row.Cells[11].BackColor = statusColor(num);
                //}

                //if (!String.IsNullOrEmpty(e.Row.Cells[12].Text))
                //{
                //    int num = Convert.ToInt32(e.Row.Cells[12].Text);
                //    e.Row.Cells[12].Text = workstatus(num);
                //    e.Row.Cells[12].BackColor = statusColor(num);
                //}

                //Response.Write(e.Row.Cells[8].Text +"c8");
                //Response.Write(e.Row.Cells[9].Text +"c9");

                //the checked box item

                //if (showtechnote.Checked == false)
                //    GridView1.Columns[9].Visible = false;
                //else if (showtechnote.Checked == true)
                //    GridView1.Columns[9].Visible = true;

                //if (showsales.Checked == false)
                //    GridView1.Columns[7].Visible = false;
                //else if (showsales.Checked == true)
                //    GridView1.Columns[7].Visible = true;

                //if (showsupportteam.Checked == false)
                //    GridView1.Columns[8].Visible = false;
                //else if (showsupportteam.Checked == true)
                //    GridView1.Columns[8].Visible = true;

                //if (showinstruction.Checked == false)
                //    GridView1.Columns[10].Visible = false;
                //else if (showinstruction.Checked == true)
                //    GridView1.Columns[10].Visible = true;

                //if (showfaq.Checked == false)
                //    GridView1.Columns[11].Visible = false;
                //else if (showfaq.Checked == true)
                //    GridView1.Columns[11].Visible = true;

                //if (showallcompany.Checked == false)
                //    GridView1.Columns[12].Visible = false;
                //else if (showallcompany.Checked == true)
                //    GridView1.Columns[12].Visible = true;

                //if (showother.Checked == false)
                //    GridView1.Columns[13].Visible = false;
                //else if (showother.Checked == true)
                //    GridView1.Columns[13].Visible = true;

                //Response.Write(e.Row.Cells[1].Text);
                string QueryString = "~/Detail/DetailCase2.aspx?id=" + e.Row.Cells[1].Text;
                string NavigateURL = ResolveUrl(QueryString);
                e.Row.Attributes.Add("onClick", string.Format("window.open('{0}')", NavigateURL));
                e.Row.Style.Add("cursor", "pointer");

                try
                {
                    Support support = new Support();
                    Support personnel = new Support();
                    int rid = Convert.ToInt32(e.Row.Cells[1].Text);
                    var cases = from c in support.Incidents
                                where c.id == rid
                                select new
                                {
                                    c.allcompany,
                                    c.model,
                                    c.description,
                                    c.enddate,
                                    c.faq,
                                    c.instruction,
                                    c.lastupdatedate,
                                    c.other,
                                    c.reportdate,
                                    c.sales,
                                    c.supportteam,
                                    c.technote,
                                    c.handler,
                                    c.drafter,
                                    c.parent,
                                };
                    //description
                    if (cases.FirstOrDefault().description != null)
                    {
                        //if (Encoding.GetEncoding("utf-8").GetBytes(cases.FirstOrDefault().description).Length > 30)
                        //{
                        //    e.Row.Cells[3].Text = cases.FirstOrDefault().description.Substring(0, 30) + "...";
                        //}
                    }
                    if (cases.FirstOrDefault().model != null)
                    {
                        //interface and cord
                        using (Support mod = new Support())
                        {
                            var par = (from c in support.Incidents
                                       where c.id == cases.FirstOrDefault().parent
                                       select c).FirstOrDefault();

                            if (par != null)
                            {
                                using (Support s = new Support())
                                {
                                    int par_mod = par.model.Value;

                                    var target = (from x in s.models
                                                  where x.id == par_mod
                                                  select x).FirstOrDefault();

                                    var ca = (from c in s.Incidents
                                              where c.id == rid
                                              select c).FirstOrDefault();

                                    if (ca.model != par_mod)
                                    {
                                        ca.model = par_mod;
                                        s.SaveChanges();
                                    }
                                }
                            }

                            System.Web.UI.WebControls.Image img = e.Row.FindControl("ImageInterface") as System.Web.UI.WebControls.Image;
                            var option = (from o in support.models
                                          where o.id == cases.FirstOrDefault().model
                                          select o).FirstOrDefault();
                            utils u = new utils();

                            img.ImageUrl = u.interfaceUntil(option._interface);

                            Label lbCord = e.Row.FindControl("TextBoxCord") as Label;
                            lbCord.Text = option.cord;
                        }
                    }
                    //drafter
                    List<int> all_person = (from x in personnel.people select x.id).ToList();
                    if (!all_person.Contains(Convert.ToInt32(cases.FirstOrDefault().drafter.ToString())))
                    {
                        e.Row.Cells[5].Text = "No drafter...";
                    }
                    else
                    {
                        int d = cases.FirstOrDefault().drafter;
                        var p_query = from p in personnel.people where p.id == d select p;
                        e.Row.Cells[5].Text = p_query.FirstOrDefault().lastname + " " + p_query.FirstOrDefault().firstname;
                    }

                    //report
                    //all company
                    if (cases.FirstOrDefault().allcompany == 1)
                    {
                        (e.Row.Cells[6].FindControl("list_allcompany") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_allcompany") as Label).ForeColor = statusColor(1);
                    }
                    else if (cases.FirstOrDefault().allcompany == 2)
                    {
                        (e.Row.Cells[6].FindControl("list_allcompany") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_allcompany") as Label).ForeColor = statusColor(2);
                    }
                    //all company
                    if (cases.FirstOrDefault().sales == 1)
                    {
                        (e.Row.Cells[6].FindControl("list_sales") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_sales") as Label).ForeColor = statusColor(1);
                    }
                    else if (cases.FirstOrDefault().sales == 2)
                    {
                        (e.Row.Cells[6].FindControl("list_sales") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_sales") as Label).ForeColor = statusColor(2);
                    }
                    //instruction
                    if (cases.FirstOrDefault().instruction == 1)
                    {
                        (e.Row.Cells[6].FindControl("list_instruction") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_instruction") as Label).ForeColor = statusColor(1);
                    }
                    else if (cases.FirstOrDefault().instruction == 2)
                    {
                        (e.Row.Cells[6].FindControl("list_instruction") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_instruction") as Label).ForeColor = statusColor(2);
                    }

                    //tech note
                    if (cases.FirstOrDefault().technote == 1)
                    {
                        (e.Row.Cells[6].FindControl("list_technote") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_technote") as Label).ForeColor = statusColor(1);
                    }
                    else if (cases.FirstOrDefault().technote == 2)
                    {
                        (e.Row.Cells[6].FindControl("list_technote") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_technote") as Label).ForeColor = statusColor(2);
                    }

                    //support team
                    if (cases.FirstOrDefault().supportteam == 1)
                    {
                        (e.Row.Cells[6].FindControl("list_supportteam") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_supportteam") as Label).ForeColor = statusColor(1);
                    }
                    else if (cases.FirstOrDefault().supportteam == 2)
                    {
                        (e.Row.Cells[6].FindControl("list_supportteam") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_supportteam") as Label).ForeColor = statusColor(2);
                    }
                    //faq
                    if (cases.FirstOrDefault().faq == 1)
                    {
                        (e.Row.Cells[6].FindControl("list_faq") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_faq") as Label).ForeColor = statusColor(1);
                    }
                    else if (cases.FirstOrDefault().faq == 2)
                    {
                        (e.Row.Cells[6].FindControl("list_faq") as Label).Visible = true;
                        (e.Row.Cells[6].FindControl("list_faq") as Label).ForeColor = statusColor(2);
                    }

                    if(cases.FirstOrDefault().enddate > cases.FirstOrDefault().reportdate)
                    {
                        e.Row.BorderStyle = BorderStyle.Solid;
                        e.Row.BorderColor = Color.DarkGray;
                    }

                    //if (!String.IsNullOrEmpty(e.Row.Cells[8].Text))
                    //{
                    //    int num = Convert.ToInt32(e.Row.Cells[8].Text);
                    //    e.Row.Cells[8].Text = workstatus(num);
                    //    e.Row.Cells[8].BackColor = statusColor(num);
                    //}

                    //if (!String.IsNullOrEmpty(e.Row.Cells[9].Text))
                    //{
                    //    int num = Convert.ToInt32(e.Row.Cells[9].Text);
                    //    e.Row.Cells[9].Text = workstatus(num);
                    //    e.Row.Cells[9].BackColor = statusColor(num);
                    //}

                    //if (!String.IsNullOrEmpty(e.Row.Cells[10].Text))
                    //{
                    //    int num = Convert.ToInt32(e.Row.Cells[10].Text);
                    //    e.Row.Cells[10].Text = workstatus(num);
                    //    e.Row.Cells[10].BackColor = statusColor(num);
                    //}

                    //if (!String.IsNullOrEmpty(e.Row.Cells[11].Text))
                    //{
                    //    int num = Convert.ToInt32(e.Row.Cells[11].Text);
                    //    e.Row.Cells[11].Text = workstatus(num);
                    //    e.Row.Cells[11].BackColor = statusColor(num);
                    //}

                    //if (!String.IsNullOrEmpty(e.Row.Cells[12].Text))
                    //{
                    //    int num = Convert.ToInt32(e.Row.Cells[12].Text);
                    //    e.Row.Cells[12].Text = workstatus(num);
                    //    e.Row.Cells[12].BackColor = statusColor(num);

                    /*
                    //handler
                    List<int> all_members = (from x in personnel.members select x.id).ToList();
                    if (cases.FirstOrDefault().handler != null)
                    {
                        if (!all_members.Contains(Convert.ToInt32(cases.FirstOrDefault().handler.ToString())))
                        {
                            e.Row.Cells[7].Text = "No handler";
                        }
                        else
                        {
                            int mem = Convert.ToInt32(cases.FirstOrDefault().handler.ToString());
                            var m_query = from me in personnel.people
                                          join m in personnel.members
                                              on me.id equals m.person
                                          where m.id == mem
                                          select me;
                            e.Row.Cells[7].Text = m_query.FirstOrDefault().lastname + " " + m_query.FirstOrDefault().firstname; ;
                        }
                    }
                    else
                    {
                        e.Row.Cells[7].Text = "No handler...";
                    }
                    */

                    ////files
                    //List<int> all_files = (from x in support.Files select x.incident).ToList();
                    //if (!all_files.Contains(Convert.ToInt32(rid)))
                    //{
                    //    e.Row.Cells[14].Text = "No attachment";
                    //}
                    //else
                    //{
                    //    var f_query = from f in support.Files
                    //                  where f.incident == rid
                    //                  select f.name;
                    //    e.Row.Cells[14].Text = f_query.FirstOrDefault().ToString();
                    //}

                    //action
                    if (!actnum.ContainsKey(Convert.ToInt32(rid)))
                    {
                        e.Row.Cells[7].Text = "N/A";
                    }
                    else
                    {
                        e.Row.Cells[7].Text = actnum[rid].ToString();
                    }

                    e.Row.Cells[1].Visible = false;
                }

                catch (Exception ex)
                {
                    Response.Write(ex);
                }
            }

            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[1].Visible = false;
            }
        }