コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //get the id of the case
            if (!String.IsNullOrEmpty(Request.QueryString["id"]))
            {
                id = Convert.ToInt32(Request.QueryString["id"]);
                //Response.Write(id);
            }

            //check if user cookie exists, means if a user logged in
            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"));
                drafter_id = Convert.ToInt32(Encoding.UTF8.GetString(MachineKey.Unprotect(Convert.FromBase64String(Request.Cookies["user"]["person"]), "ProtectCookiePerson")));

                if (decoded_role == "admin" || decoded_role == "support")
                {

                }

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

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

            //string SolutionURI = "DetailAction2?case_id=" + id + "&new=1";
            //detailcase2_addsolution.Attributes.Add("onClick", string.Format("window.open('{0}'),'_self'", SolutionURI));

            string ChildURI = "DetailCase2?new=1&parent=" + id;
            detailcase2_children_add.Attributes.Add("onClick", string.Format("window.open('{0},'_self)", ChildURI));

            //set the multiview initially shows other panel
            Other_Tab.CssClass = "Clicked";
            Report_Tab.CssClass = "Initial";
            Files_Tab.CssClass = "Initial";
            Children_Tab.CssClass = "Initial";
            Customer_Tab.CssClass = "Initial";
            MainView.ActiveViewIndex = 0;

            //to avoid duplication in dropdown lists
            if (IsPostBack)
            {
                detailcase2_handler.DataSourceID = "";
                Items.Clear();
            }

            //add 'none' to some dropdown lists to enable none selection
            detailcase2_handler.AppendDataBoundItems = true;

            //check if it is a new case
            if (!String.IsNullOrEmpty(Request.QueryString["new"]))
            {
                isNew = Convert.ToInt32(Request.QueryString["new"]);
            }
            //check if this case is a child of another case
            if (Request.QueryString["parent"] != null && Convert.ToInt32(Request.QueryString["parent"]) != 0)
            {
                parent_id = Convert.ToInt32(Request.QueryString["parent"]);
            }

            //detailcase2_interface.Items.Insert(0, new ListItem("--Select Department--", "-1"));
            //Response.Write(parent_id);
            DateTime lastupdatedDate = new DateTime(1970, 1, 1);
            if (!IsPostBack)
            {
                //ListItem itemToRemove = detailcase2_interface.Items.FindByText("--Interface--");
                //if (itemToRemove != null)
                //{
                //    itemToRemove.Attributes.Add("style", "color:gray;");
                //    itemToRemove.Attributes.Add("disabled", "true");
                //    itemToRemove.Value = "-1";
                //}

                //ListItem itemToRemove2 = detailcase2_handler.Items.FindByText("");
                //if (itemToRemove != null)
                //{
                //    itemToRemove2.Enabled = false;
                //}

                detailcase2_interface.AppendDataBoundItems = true;

                if (isNew == 1)
                {
                    Support s = new Support();
                    Incident newCase = new Incident()
                    {
                        reportdate = DateTime.Now,
                        lastupdatedate = lastupdatedDate,
                        enddate = DateTime.Now,
                        sales = 0,
                        supportteam = 0,
                        technote = 0,
                        instruction = 0,
                        faq = 0,
                        allcompany = 0,
                        drafter = drafter_id,
                        description = "default",
                        model = 19
                    };

                    s.Incidents.Add(newCase);

                    //load parent
                    if (parent_id != 0)
                    {
                        newCase.parent = parent_id;
                        //before doing other operations, check if the parent still exists.
                        List<int> all_cases = (from x in s.Incidents select x.id).ToList();
                        if (newCase.parent != null)
                        {
                            if (!all_cases.Contains(Convert.ToInt32(newCase.parent.ToString())))
                            {
                                //  detailcase2_parent.Text = "No parent...";
                            }

                            else
                            {
                                var qparent = from p in s.Incidents
                                              where p.id == (int)newCase.parent
                                              select p;
                                if (qparent.FirstOrDefault().description.Length > 10)
                                {
                                    detailcase2_parent.Text = qparent.FirstOrDefault().description.Substring(0, 10);
                                }
                                else
                                {
                                    detailcase2_parent.Text = qparent.FirstOrDefault().description;
                                }

                                //inherited parent's model
                                newCase.model = qparent.FirstOrDefault().model;

                                var mo = (from m in s.models
                                          where m.id == newCase.model
                                          select m).FirstOrDefault();
                                detailcase2_interface.SelectedValue = mo._interface.ToString();
                                String strConnString = ConfigurationManager
                                    .ConnectionStrings["SupportConnectionString"].ConnectionString;
                                String strQuery = "SELECT [cord] FROM [model] WHERE ([interface] = @interface)";
                                SqlConnection con = new SqlConnection(strConnString);
                                SqlCommand cmd = new SqlCommand();
                                cmd.Parameters.AddWithValue("@interface",
                                    Convert.ToInt32(detailcase2_interface.SelectedItem.Value.ToString()));
                                cmd.CommandType = CommandType.Text;
                                cmd.CommandText = strQuery;
                                cmd.Connection = con;
                                try
                                {
                                    con.Open();
                                    detailcase2_cord.DataSource = cmd.ExecuteReader();
                                    detailcase2_cord.DataTextField = "cord";
                                    detailcase2_cord.DataValueField = "cord";
                                    detailcase2_cord.DataBind();
                                }
                                catch (Exception ex)
                                {
                                    Response.Write(ex);
                                }
                                finally
                                {
                                    con.Close();
                                    con.Dispose();
                                }
                                detailcase2_cord.SelectedValue = mo.cord.ToString();

                                detailcase2_interface.Enabled = false;
                                detailcase2_cord.Enabled = false;
                            }
                        }
                        else
                        {
                            detailcase2_parent.Text = "No parent...";
                        }
                    }
                    s.SaveChanges();
                    id = newCase.id;

                    detailcase2_reportdate.Text = newCase.reportdate.ToString("MM/dd/yyyy");
                    var p_query = from p in s.people where p.id == newCase.drafter select p;
                    detailcase2_drafter.Text = p_query.FirstOrDefault().lastname + " " + p_query.FirstOrDefault().firstname;
                    //Response.Write(id);
                }
                else
                {
                    try
                    {
                        Support support = new Support();
                        Support personnel = new Support();
                        var cases = (from c in support.Incidents
                                     where c.id == id
                                     select new
                                     {
                                         c.allcompany,
                                         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,
                                         c.cuscom,
                                         c.cusname,
                                         c.discom,
                                         c.dispname,
                                         c.model
                                     }).FirstOrDefault();

                        //parent
                        //before doing other operations, check if the parent still exists.
                        List<int> all_cases = (from x in support.Incidents select x.id).ToList();
                        if (cases.parent != null)
                        {
                            if (!all_cases.Contains(Convert.ToInt32(cases.parent.ToString())))
                            {
                                detailcase2_parent.Text = "N/A";
                            }

                            else
                            {
                                var qparent = from p in support.Incidents
                                              where p.id == (int)cases.parent
                                              select p;
                                if (qparent.FirstOrDefault().description.Length > 10)
                                {
                                    detailcase2_parent.Text = qparent.FirstOrDefault().description.Substring(0, 10);
                                }
                                else
                                {
                                    detailcase2_parent.Text = qparent.FirstOrDefault().description;
                                }
                            }
                        }
                        else
                        {
                            detailcase2_parent.Text = "N/A";
                        }

                        //customer name
                        if (!String.IsNullOrEmpty(cases.cusname))
                        {
                            detailcase2_cusname.Text = "" + cases.cusname.ToString();
                        }
                        else
                        {
                            detailcase2_cusname.Text = "";
                        }

                        //customer company
                        if (!String.IsNullOrEmpty(cases.cusname))
                        {
                            detailcase2_cuscom.Text = "" + cases.cuscom.ToString();
                        }
                        else
                        {
                            detailcase2_cuscom.Text = "";
                        }

                        //distrabution company
                        if (!String.IsNullOrEmpty(cases.discom))
                        {
                            detailcase2_discom.Text = "" + cases.discom.ToString();
                        }
                        else
                        {
                            detailcase2_discom.Text = "";
                        }

                        //distributor
                        if (!String.IsNullOrEmpty(cases.cusname))
                        {
                            detailcase2_disname.Text = "" + cases.dispname.ToString();
                        }
                        else
                        {
                            detailcase2_disname.Text = "";
                        }

                        //before doing other operations, check if the model still exists.
                        List<int> all_models = (from x in support.models select x.id).ToList();
                        if (cases.model != null)
                        {
                            var par = (from c in support.Incidents
                                       where c.id == cases.parent
                                       select c).FirstOrDefault();

                            int mod = Convert.ToInt32(cases.model.ToString());
                            if (all_models.Contains(mod))
                            {
                                using (Support s = new Support())
                                {
                                    var target = (from x in s.models
                                                  where x.id == mod
                                                  select x).FirstOrDefault();
                                    detailcase2_interface.SelectedValue = target._interface.ToString();
                                }
                                detailcase2_cord.Items.Clear();

                                detailcase2_cord.AppendDataBoundItems = true;
                                String strConnString = ConfigurationManager
                                    .ConnectionStrings["SupportConnectionString"].ConnectionString;
                                String strQuery = "SELECT [cord] FROM [model] WHERE model.interface = @interface";
                                SqlConnection con = new SqlConnection(strConnString);
                                SqlCommand cmd = new SqlCommand();
                                cmd.Parameters.AddWithValue("@interface",
                                    Convert.ToInt32(detailcase2_interface.SelectedItem.Value.ToString()));
                                cmd.CommandType = CommandType.Text;
                                cmd.CommandText = strQuery;
                                cmd.Connection = con;
                                try
                                {
                                    con.Open();
                                    detailcase2_cord.DataSource = cmd.ExecuteReader();
                                    detailcase2_cord.DataTextField = "cord";
                                    detailcase2_cord.DataValueField = "cord";
                                    detailcase2_cord.DataBind();
                                    if (detailcase2_cord.Items.Count >= 1)
                                    {
                                        //Response.Write("haha");
                                        detailcase2_cord.Enabled = true;

                                        if (par != null)
                                        {
                                            //Response.Write("hoho");
                                            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();
                                                detailcase2_interface.SelectedValue = target._interface.ToString();
                                                detailcase2_cord.Text = target.cord.ToString();

                                                detailcase2_interface.Enabled = false;
                                                detailcase2_cord.Enabled = false;

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

                                                if (ca.model != par_mod)
                                                {
                                                    //Response.Write("hehe");
                                                    ca.model = par_mod;
                                                    s.SaveChanges();
                                                }
                                            }
                                        }

                                        else
                                        {
                                            using (Support s = new Support())
                                            {
                                                //Response.Write("hiahia");
                                                var target = (from x in s.models
                                                              where x.id == mod
                                                              select x).FirstOrDefault();
                                                detailcase2_cord.SelectedValue = target.cord.ToString();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        detailcase2_cord.Enabled = false;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Response.Write(ex);
                                }
                                finally
                                {
                                    con.Close();
                                    con.Dispose();
                                }
                            }
                        }

                        //report date
                        if (cases.reportdate != null)
                        {
                            detailcase2_reportdate.Text = "" + cases.reportdate.ToString("MM/dd/yyyy");
                        }
                        else
                        {
                            detailcase2_reportdate.Text = "";
                        }

                        //decription
                        if (String.IsNullOrEmpty(cases.description) || cases.description == "default")
                        {
                            detailcase2_desc.Text = "";
                        }
                        else
                        {
                            detailcase2_desc.Text = cases.description.ToString();

                        }

                        //is closed
                        if (cases.enddate > cases.reportdate)
                        {
                            detailcase2_isclosed_cb.Checked = true;
                        }
                        else
                        {
                            detailcase2_isclosed_cb.Checked = false;
                        }

                        //sales
                        if (cases.sales.HasValue)
                        {
                            detailcase2_sales_rb.SelectedIndex = cases.sales.Value;
                        }
                        else
                        {
                            detailcase2_sales_rb.SelectedIndex = 0;
                        }

                        //support team
                        if (cases.supportteam.HasValue)
                        {
                            detailcase2_supportteam_rb.SelectedIndex = cases.supportteam.Value;
                        }
                        else
                        {
                            detailcase2_supportteam_rb.SelectedIndex = 0;
                        }

                        //tech note
                        if (cases.technote.HasValue)
                        {
                            detailcase2_technote_rb.SelectedIndex = cases.technote.Value;
                        }
                        else
                        {
                            detailcase2_technote_rb.SelectedIndex = 0;
                        }

                        //instruction
                        if (cases.instruction.HasValue)
                        {
                            detailcase2_inst_rb.SelectedIndex = cases.instruction.Value;
                        }
                        else
                        {
                            detailcase2_inst_rb.SelectedIndex = 0;
                        }

                        //faq
                        if (cases.faq.HasValue)
                        {
                            detailcase2_faq_rb.SelectedIndex = cases.faq.Value;
                        }
                        else
                        {
                            detailcase2_faq_rb.SelectedIndex = 0;
                        }

                        //all company
                        if (cases.allcompany.HasValue)
                        {
                            detailcase2_allcompany_rb.SelectedIndex = cases.allcompany.Value;
                        }
                        else
                        {
                            detailcase2_allcompany_rb.SelectedIndex = 0;
                        }

                        //detailcase2_sales_dp.SelectedValue = cases.sales.ToString();
                        //detailcase2_supportteam_dp.SelectedValue = cases.supportteam.ToString();
                        //detailcase2_technote_dp.SelectedValue = cases.technote.ToString();
                        //detailcase2_allcompany_dp.SelectedValue = cases.allcompany.ToString();
                        //detailcase2_faq_dp.SelectedValue = cases.faq.ToString();
                        //detailcase2_inst_dp.SelectedValue = cases.instruction.ToString();

                        //other
                        if (!String.IsNullOrEmpty(cases.other))
                        {
                            other = cases.other.ToString();
                            detailcase2_other.Text = other;
                        }
                        else
                        {
                            detailcase2_other.Text = "";
                        }

                        //drafter
                        List<int> all_person = (from x in personnel.people select x.id).ToList();
                        if (!all_person.Contains(Convert.ToInt32(cases.drafter.ToString())))
                        {
                            detailcase2_drafter.Text = "";
                        }
                        else
                        {
                            int d = cases.drafter;
                            var p_query = from p in personnel.people where p.id == d select p;
                            detailcase2_drafter.Text = "" + p_query.FirstOrDefault().lastname + " " + p_query.FirstOrDefault().firstname;
                        }

                        //handler
                        List<int> all_members = (from x in personnel.members select x.id).ToList();
                        if (cases.handler != null)
                        {
                            if (all_members.Contains(Convert.ToInt32(cases.handler.ToString())))
                            {
                                detailcase2_handler.SelectedValue = cases.handler.ToString();
                            }
                            else
                            {
                                detailcase2_handler.SelectedValue = "";
                            }
                        }
                        else
                        {
                            detailcase2_handler.SelectedValue = "";
                        }
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex);
                    }
                }
            }
        }
コード例 #2
0
        private void enableParents(Incident i)
        {
            if (i.parent == null)
            {
                return;
            }
            else
            {

                Support support = new Support();
                var par = (from c in support.Incidents
                           where c.id == i.parent
                           select c).FirstOrDefault();

                if (par != null)
                {
                    if (par.enddate > par.reportdate)
                    {
                        //Response.Write("haha| ");
                        par.enddate = par.reportdate;
                    }
                    support.SaveChanges();
                    Incident p = support.Incidents.Where(x => x.id == par.id).FirstOrDefault();
                    enableParents(p);
                }
            }
        }