Exemple #1
0
        /// <summary>
        /// 获取所有未下载完的文件和文件夹列表
        /// </summary>
        /// <returns></returns>
        public static string GetAll(int uid, string mac)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("select ");
            sb.Append(" f_id");
            sb.Append(",f_mac");
            sb.Append(",f_pathLoc");
            sb.Append(",f_pathSvr");
            sb.Append(",f_lengthLoc");
            sb.Append(",f_percent");
            sb.Append(",fd_name");
            sb.Append(",fd_id");
            sb.Append(",fd_pathLoc");
            sb.Append(",fd_id_old");
            sb.Append(",fd_percent");
            sb.Append(" from down_files as f");
            sb.Append(" left join down_folders as fd");
            sb.Append(" on fd.fd_id = f.f_fdID");
            sb.Append(" where f_uid=@f_uid and f_mac=@f_mac and f_complete=0");
            //string sql = "select * from down_files where f_uid=@f_uid and f_mac=@f_mac and f_complete=0;";
            DbHelper  db  = new DbHelper();
            DbCommand cmd = db.GetCommand(sb.ToString());

            db.AddInt(ref cmd, "@f_uid", uid);
            db.AddString(ref cmd, "@f_mac", mac, 50);
            DbDataReader r     = db.ExecuteReader(ref cmd);
            JArray       files = new JArray();

            while (r.Read())
            {
                DnFileInf f = new DnFileInf();
                f.idSvr     = r.GetInt32(0);
                f.mac       = r.GetString(1);
                f.pathLoc   = r.IsDBNull(2) ? string.Empty : r.GetString(2);
                f.pathSvr   = r.IsDBNull(3) ? string.Empty : r.GetString(3);
                f.lengthLoc = r.IsDBNull(4) ? string.Empty : r.GetString(4);
                f.percent   = r.IsDBNull(5) ? "0%" : r.GetString(5);
                f.name      = Path.GetFileName(f.pathLoc);
                f.fdID      = r.IsDBNull(7)? 0 : r.GetInt32(7);
                //文件夹
                if (0 != f.fdID)
                {
                    f.name    = r.IsDBNull(6) ? string.Empty : r.GetString(6);
                    f.fdTask  = true;
                    f.percent = r.IsDBNull(10) ? string.Empty : r.GetString(10);
                    f.pathLoc = r.IsDBNull(8) ? string.Empty : r.GetString(8);
                }
                files.Add((JObject)JToken.FromObject(f));
            }
            r.Close();

            //JArray arrFiles = new JArray();
            //foreach (DnFileInf f in files)
            //{
            //    arrFiles.Add((JObject)JToken.FromObject(f));
            //}
            return(files.ToString());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string uid     = Request.QueryString["uid"];
            string mac     = Request.QueryString["mac"];
            string pathLoc = Request.QueryString["pathLoc"];     //客户端使用的是encodeURIComponent编码,
            string pathSvr = Request.QueryString["pathSvr"];     //客户端使用的是encodeURIComponent编码,

            pathLoc = HttpUtility.UrlDecode(pathLoc);            //utf-8解码
            pathSvr = HttpUtility.UrlDecode(pathSvr);            //utf-8编码
            string lengthLoc = Request.QueryString["lengthLoc"];
            string lengthSvr = Request.QueryString["lengthSvr"];
            string callback  = Request.QueryString["callback"];   //应用于jsonp数据

            System.Diagnostics.Debug.WriteLine("uid:" + uid);
            System.Diagnostics.Debug.WriteLine("mac:" + mac);
            System.Diagnostics.Debug.WriteLine("pathLoc:" + pathLoc);
            System.Diagnostics.Debug.WriteLine("pathSvr:" + pathSvr);
            System.Diagnostics.Debug.WriteLine("lengthLoc:" + lengthLoc);
            System.Diagnostics.Debug.WriteLine("lengthSvr:" + lengthSvr);
            System.Diagnostics.Debug.WriteLine("callback:" + callback);

            if (string.IsNullOrEmpty(uid) ||
                string.IsNullOrEmpty(mac) ||
                string.IsNullOrEmpty(pathLoc) ||
                string.IsNullOrEmpty(pathSvr) ||
                string.IsNullOrEmpty(lengthLoc) ||
                string.IsNullOrEmpty(lengthSvr))
            {
                Response.Write("参数为空");
                Response.End();
                return;
            }

            DnFileInf inf = new DnFileInf();

            inf.uid       = int.Parse(uid);
            inf.mac       = mac;
            inf.pathLoc   = pathLoc;
            inf.pathSvr   = pathSvr;
            inf.lengthLoc = lengthLoc;
            inf.lengthSvr = lengthSvr;
            DnFile db = new DnFile();

            db.Add(ref inf);

            string json = JsonConvert.SerializeObject(inf);

            //json = HttpUtility.UrlEncode(json);
            //json = json.Replace("+", "%20");
            json = callback + "(" + json + ")";//返回jsonp格式数据。
            Response.Write(json);
        }
Exemple #3
0
        public int Add(ref DnFileInf inf)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("insert into down_files(");
            sql.Append("f_uid");
            sql.Append(",f_mac");
            sql.Append(",f_pathLoc");
            sql.Append(",f_pathSvr");
            sql.Append(",f_lengthLoc");
            sql.Append(",f_lengthSvr");
            sql.Append(") values(");
            sql.Append("@f_uid");
            sql.Append(",@f_mac");
            sql.Append(",@f_pathLoc");
            sql.Append(",@f_pathSvr");
            sql.Append(",@f_lengthLoc");
            sql.Append(",@f_lengthSvr");
            sql.Append(");");
            sql.Append("select @@IDENTITY");

            DbHelper  db  = new DbHelper();
            DbCommand cmd = db.GetCommand(sql.ToString());

            db.AddInt(ref cmd, "@f_uid", inf.uid);
            db.AddString(ref cmd, "@f_mac", inf.mac, 50);
            db.AddString(ref cmd, "@f_pathLoc", inf.pathLoc, 255);
            db.AddString(ref cmd, "@f_pathSvr", inf.pathSvr, 255);
            db.AddString(ref cmd, "@f_lengthLoc", inf.lengthLoc, 19);
            db.AddString(ref cmd, "@f_lengthSvr", inf.lengthSvr, 19);
            object id = db.ExecuteScalar(ref cmd);

            inf.idSvr = Convert.ToInt32(id);
            //inf.idSvr = (int)db.ExecuteScalar(ref cmd);
            //cmd.Connection.Open();
            //cmd.ExecuteNonQuery();
            //cmd.Parameters.Clear();
            //cmd.CommandText = "select @@IDENTITY";
            //inf.idSvr = (int)cmd.ExecuteScalar();
            //cmd.Connection.Close();
            return(inf.idSvr);
        }