Exemplo n.º 1
0
 public Object Get(string s)
 {
     using (var svc = new SqlFace.Models.OrmService(Config.AppConfigs.sqlfaceconn))
     {
         List <object> ret = new List <object>();
         foreach (var i in svc.FilterWhere <Importing.Imp_Management>(t => t.mem.Contains(s) || t.file_name.Contains(s)))
         {
             ret.Add(new { mem = i.mem, length = i.length, last_modified_date = i.last_modified_date, file_name = i.file_name, import_id = i.id, total = i.total, addHeads = i.addHeads });
         }
         return(ret);
     }
 }
Exemplo n.º 2
0
 public Object GetImp(string impid)
 {
     using (var svc = new SqlFace.Models.OrmService(Config.AppConfigs.sqlfaceconn))
     {
         List <object> ret    = new List <object>();
         var           parent = svc.GetById <Importing.Imp_Management>(impid);
         foreach (var i in svc.FilterWhere <Importing.Imp_4g_Log>(t => t.import_id == impid))
         {
             ret.Add(new { phone_number = i.phone_number, old_pn_level_id = i.old_pn_level_id, pn_level_id = i.pn_level_id, commit_date = i.commit_date, import_id = i.import_id, mem = parent.mem, length = parent.length, file_name = parent.file_name, total = parent.total, addHeads = parent.addHeads });
         }
         return(ret);
     }
 }
Exemplo n.º 3
0
        public string Post(string put, [FromBody] Needs needs)
        {
            var      ret = "提交失败,请联系系统管理员:{0}";
            DataSet  ds;
            DateTime now = DateTime.Now;

            using (var svc = new SqlFace.Models.OrmService(Config.AppConfigs.sqlfaceconn))
            {
                var t = svc.GetById <Imp_Management>(needs.guid);
                if (svc.FilterWhere <Imp_4g_Log>(s => s.import_id == t.id).Count > 0)
                {
                    return(string.Format("不能重复导入多次"));
                }
                construction(t.phy_path, out ds);
                using (IDbTransaction trans = svc.theConnection.BeginTransaction(IsolationLevel.ReadCommitted))
                {
                    try
                    {
                        string    nbr, lvl;
                        DataTable dt = ds.Tables[0];
                        t.addHeads           = needs.addHeads;
                        t.mem                = needs.mem;
                        t.last_modified_date = now;
                        svc.Update <Imp_Management>(t, new List <string> {
                            "addHeads", "mem", "last_modified_date"
                        }, s => s.id == t.id);

                        if (needs.addHeads)
                        {
                            nbr = dt.Columns[needs.indexes[0]].ColumnName;
                            lvl = dt.Columns[needs.indexes[1]].ColumnName;
                            svc.Create <Imp_4g_Log>(new Imp_4g_Log {
                                log_id = Guid.NewGuid().ToString(), import_id = t.id, phone_number = nbr, pn_level_id = lvl, create_date = now, commit_date = null, old_pn_level_id = null, remarks = null, rsc_cd = null
                            });
                        }

                        foreach (DataRow dr in dt.Rows)
                        {
                            nbr = dr[needs.indexes[0]].ToString();
                            lvl = dr[needs.indexes[1]].ToString();
                            svc.Create <Imp_4g_Log>(new Imp_4g_Log {
                                log_id = Guid.NewGuid().ToString(), import_id = t.id, phone_number = nbr, pn_level_id = lvl, create_date = now, commit_date = null, old_pn_level_id = null, remarks = null, rsc_cd = null
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        trans.Rollback();
                        return(string.Format("导入文件中存在重复号码", e.Message));
                    }
                    trans.Commit();
                    try
                    {
                        Dictionary <string, OracleParameter> cmdp = new Dictionary <string, OracleParameter>();
                        cmdp.Add("import_id", new OracleParameter("sql_text", OracleDbType.Varchar2, 400, t.id, System.Data.ParameterDirection.Input));
                        cmdp.Add("returnstr", new OracleParameter("returnstr", OracleDbType.Varchar2, 400, null, System.Data.ParameterDirection.Output));
                        cmdp.Add("stats", new OracleParameter("stats", OracleDbType.Varchar2, 400, null, System.Data.ParameterDirection.Output));
                        Utils.DBTool.RunOracleProcedure("hbwh_oss_admin.Import_4gNbr_with_lvl", ref cmdp);
                        var returnstr = (null == cmdp["returnstr"].Value) ? null : cmdp["returnstr"].Value.ToString();
                        var stats     = (null == cmdp["stats"].Value) ? null : cmdp["stats"].Value.ToString();
                        if (returnstr == null || returnstr.ToLower() == "null")
                        {
                            return("提交成功," + stats);
                        }
                        else
                        {
                            return(string.Format(ret, returnstr));
                        }
                    }
                    catch
                    {
                        try //调用异常,回滚数据,让用户可以再次尝试
                        {
                            var rt = Utils.DBTool.runCommands(new List <string> {
                                string.Format("delete imp_log where import_id = '{0}'", t.id)
                            });
                            throw;
                        }
                        catch
                        {
                            throw;
                        };
                    }
                }
            }
        }
Exemplo n.º 4
0
        public Task <object> Post()
        {
            string password;

            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Invalid Request!"));
            }

            try
            {
                var httpRequest = HttpContext.Current.Request;
                var keys        = httpRequest.Form;
                password = keys["password"];
                if (!checkpassword(password))
                {
                    throw new ApplicationException("密码错误!");
                }
            }
            catch (Exception e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Forbidden, e.Message));
            }
            try
            {
                var streamProvider = new MyMultipartFormDataStreamProvider("importing/uploads", Request.RequestUri.Authority);
                //Request.Content.LoadIntoBufferAsync().Wait();
                return(Request.Content.ReadAsMultipartAsync(streamProvider).
                       ContinueWith <object>(res =>
                {
                    object json;
                    var context = res.Result.FileData.Select(i =>
                    {
                        DataSet ds; List <String> cols; List <Object[]> data; List <Type> colTypes;
                        var phy_path = i.LocalFileName.Replace("\"", "");
                        var rname = i.Headers.ContentDisposition.FileName;
                        var test = i.Headers.ContentDisposition.ModificationDate;
                        try
                        {
                            construction(phy_path, out ds);
                            using (ds)
                            {
                                SqlFace.Models.DynmicService.GetTableRowsDataCompact(ds.Tables[0], out cols, out data, out colTypes);
                            }
                            FileInfo df = res.Result.fnmap[rname];
                            var guid = Guid.NewGuid().ToString();
                            var svc = new SqlFace.Models.OrmService(Config.AppConfigs.sqlfaceconn);
                            svc.Create(new Imp_Management
                            {
                                id = guid,
                                create_date = df.CreationTime,
                                file_name = rname.Trim('"'),
                                length = df.Length,
                                uploader = "anonymous",
                                last_modified_date = df.LastWriteTime,
                                phy_path = phy_path,
                                addHeads = null,
                                total = data.Count
                            });
                            svc.Dispose();
                            json = new { credit = guid, cols = cols, data = data, colTypes = colTypes, total = data.Count };
                            return json;
                        }
                        catch (Exception e)
                        {
                            json = new { hasError = true, Message = e.Message };
                            return json;
                        }
                    });
                    return context;
                }));
            }
            catch (Exception e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }