//[System.Web.Services.WebMethod]
        //public static void GetComplaintItem(HttpContext context)
        //{
        //    //Get System properties from System table
        //    ISystemRepository systemRepository = ObjectFactory.GetInstance<ISystemRepository>();
        //    SystemEntity sysEntity = systemRepository.GetBySysName(cmplEntity.SystemName);

        //    //Get Item Path
        //    string serverName = sysEntity.IP + (sysEntity.Port.Length>0 ? ":" + sysEntity.Port : "");
        //    string connStr = String.Format("server={0};database={1};uid={2};pwd={3};max pool size =1024000",
        //                                    serverName, sysEntity.DBLocation, sysEntity.UserName, sysEntity.UserPwd);
        //    string type = ((ComplaintTypeEnum)cmplEntity.Type).ToString();

        //    string path = complaintApp.GetComItem(connStr, sysEntity.Procedure, type, cmplEntity.TargetID);

        //    HelpPath helpPath = new HelpPath();
        //    helpPath.Type = type;
        //    helpPath.Path = path;

        //    JavaScriptSerializer jss = new JavaScriptSerializer();
        //    context.Response.Write(jss.Serialize(helpPath));

        //    //if (type == "Photo")
        //    //{
        //    //    this.comImg.ImageUrl = path;
        //    //    this.comImg.Visible = true;
        //    //}
        //    //else if (type == "Video")
        //    //{
        //    //    //ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>setPlayerVideo();</script>");
        //    //    context.Response.Write(path);
        //    //}
        //}


        public void GetComplaintItem()
        {
            //Get System properties from System table
            ISystemRepository systemRepository = ObjectFactory.GetInstance <ISystemRepository>();
            SystemEntity      sysEntity        = systemRepository.GetBySysName(cmplEntity.SystemName);

            //Get Item Path
            string serverName = sysEntity.IP + (sysEntity.Port.Length > 0 ? ":" + sysEntity.Port : "");
            string connStr    = String.Format("server={0};database={1};uid={2};pwd={3};max pool size =1024000",
                                              serverName, sysEntity.DBLocation, sysEntity.UserName, sysEntity.UserPwd);
            string type = ((ComplaintTypeEnum)cmplEntity.Type).ToString();

            string result = complaintApp.GetComItem(connStr, sysEntity.Procedure, type, cmplEntity.TargetID);

            if (string.IsNullOrEmpty(result))
            {
                comItem = new ComplaintItem();
                return;
            }

            JavaScriptSerializer jss = new JavaScriptSerializer();

            comItem = (ComplaintItem)jss.Deserialize(result, typeof(ComplaintItem));

            if (type == "Photo")
            {
                this.comImg.Style["display"] = "inline";
            }
            else if (type == "Video")
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "setPlayerVideo('" + comItem.Path + "');", true);
            }
            else if (type == "User")
            {
                this.comUser.Style["display"] = "inline";
            }
            else if (type == "Group")
            {
                this.comGroup.Style["display"] = "inline";
            }
            else if (type == "Post")
            {
                this.comPost.Style["display"] = "inline";
            }
        }
        public string GetComItem(string connStr, string spName, string type, int id)
        {
            Regex  regex  = new Regex("(?<=database=).*(?=;uid)");
            string dbName = regex.Match(connStr).Value;

            //Add a connectionString if not existed
            Configuration            config    = WebConfigurationManager.OpenWebConfiguration("~");
            ConnectionStringsSection csSection = config.ConnectionStrings;

            if (csSection.ConnectionStrings[dbName] == null)
            {
                ConnectionStringSettings connection = new ConnectionStringSettings(dbName, connStr, "System.Data.SqlClient");
                csSection.ConnectionStrings.Add(connection);
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("connectionStrings");
            }

            ComplaintItem com = new ComplaintItem();
            Database      db  = new SqlDatabase(connStr);

            using (DbCommand dbCommand = db.GetStoredProcCommand(spName))
            {
                try
                {
                    db.AddInParameter(dbCommand, "Action", DbType.String, "View");
                    db.AddInParameter(dbCommand, "Type", DbType.String, type);
                    db.AddInParameter(dbCommand, "ID", DbType.Int32, id);
                    IDataReader reader = db.ExecuteReader(dbCommand);
                    if (reader.Read())
                    {
                        switch (type)
                        {
                        case "Photo":
                        case "Video":
                            com.Path = (string)reader["Path"];
                            break;

                        case "User":
                            com.UserName  = (string)reader["UserName"];
                            com.UserEmail = (string)reader["UserEmail"];
                            break;

                        case "Group":
                            com.UserName  = (string)reader["UserName"];
                            com.GroupName = (string)reader["GroupName"];
                            break;

                        case "Post":
                            com.UserName = (string)reader["UserName"];
                            com.Message  = (string)reader["Message"];
                            break;
                        }
                    }

                    JavaScriptSerializer jss = new JavaScriptSerializer();
                    return(jss.Serialize(com));
                }
                catch (Exception ex)
                {
                    WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]",
                                                    "GetTimesheetList", base.FormatParameters(dbCommand.Parameters), ex.Message));
                    return("");
                }
            }
        }