Пример #1
0
        private void Upload(DotModel model, string coverPdf)
        {
            var nameValues = new NameValueCollection
            {
                { "key", Guid.NewGuid() + Path.GetExtension(coverPdf) },
                { "token", model.Token }
            };

            try
            {
                var str = SD.Common.Http.Upload(SD.Common.Http.QINIU_UPLOAD, System.IO.File.ReadAllBytes(coverPdf), nameValues);
                if (str.StartsWith("error:"))
                {
                    model.IsSucced = false;
                    LogUtil.Write(str, "Waring");
                    return;
                }

                var result = JsonConvert.DeserializeObject <JObject>(str);
                model.Url      = string.Concat(model.BaseUrl, "/", result["key"]);
                model.IsSucced = true;
                LogUtil.Write(model.Url + "上传铺码文档成功!");
            }
            catch (Exception ex)
            {
                LogUtil.Error(ex);
                model.IsSucced = false;
            }
            finally
            {
                CallBack(model);
            }
        }
Пример #2
0
        private void CallBack(DotModel model)
        {
            try
            {
                var postData = JsonConvert.SerializeObject(new
                {
                    temp_id     = model.Id.ToString(),
                    dot_pdf_url = model.Url,
                    state       = model.IsSucced.ToString().ToLower(),
                });

                var str = SD.Common.Http.PostWebRequest(Domain, postData);
                LogUtil.Write(model.Id + "提交信息" + str);
            }
            catch (Exception ex)
            {
                LogUtil.Write(model.Id + "上传出错");
                LogUtil.Error(ex);
            }
            finally
            {
                var fileName = Path.Combine(runtimePath, SerializeFolder, string.Concat(model.Id, ".bin"));
                excutingFiles.Remove(fileName);
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                    LogUtil.Write(model.Id + "删除成功!");
                }
            }
        }
Пример #3
0
        private void Cover(DotModel model)
        {
            try
            {
                LogUtil.Write(model.Id + "开始铺码!");
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                Dot3Device dot3Device = new Dot3Device();
                var        coverPdf   = model.LocalUrl.Replace(".pdf", "_cover.pdf");
                dot3Device.CreateDotPdf(model.LocalUrl, coverPdf, model.Pages);
                stopwatch.Stop();
                LogUtil.Write(string.Concat(model.Id, "铺码完成!铺码用时:", stopwatch.ElapsedMilliseconds / 1000, "秒"));
                autoReset.Set();

                ThreadPool.QueueUserWorkItem((wr) =>
                {
                    Upload(model, coverPdf);
                });
            }
            catch (Exception ex)
            {
                LogUtil.Error(ex);
                model.IsSucced = false;
                CallBack(model);
            }
        }
Пример #4
0
        public async Task <IActionResult> SetDot(DotModel dm, IFormFile thumbFile)
        {
            if (ModelState.IsValid)
            {
                Dot dot = null;
                try
                {
                    if (thumbFile != null && thumbFile.ContentType.Contains("image"))
                    {
                        var uploadedFileExtension = Path.GetExtension(thumbFile.FileName);
                        var fileName   = Path.GetRandomFileName() + uploadedFileExtension;
                        var mappedPath = Path.Combine(_appEnvironment.WebRootPath, "Files", DateTime.Now.ToShortDateString());
                        Directory.CreateDirectory(mappedPath);
                        var filePath = Path.Combine(mappedPath, fileName);
                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            await thumbFile.CopyToAsync(fileStream);
                        }
                        Dot oldDot = _context.Dots.FirstOrDefault(d => d.id == dm.dot_id);
                        if (oldDot != null)
                        {
                            var oldThumb = Path.Combine(_appEnvironment.WebRootPath, oldDot.thumb_file);
                            System.IO.File.Delete(oldThumb);
                            _context.Entry(oldDot).State = EntityState.Detached;
                        }
                        dot             = dm.createDot(oldDot);
                        dot.category_id = dm.category_id;
                        dot.thumb_name  = Path.GetFileName(thumbFile.FileName);
                        //var baseUri = this.Request.Host.Host.ToString();
                        string webPath = Path.GetRelativePath(_appEnvironment.WebRootPath, filePath).Replace(@"\", "/");
                        dot.thumb_file     = Url.Content(webPath);;
                        ViewBag.FileStatus = "File uploaded successfully.";
                    }
                    else
                    {
                        ViewBag.FileStatus = "File is not image";
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.FileStatus = ex.StackTrace;
                    return(View(dot));
                }
                if (dot != null)
                {
                    var user = await _userManager.GetUserAsync(User);

                    dot.user_id = user.Id;
                    _context.Dots.Add(dot);
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(dm));
            }
        }
Пример #5
0
 private static void SaveModelData(DotModel model)
 {
     HuSe.WebClientUtil.DownloadFile(new MetaData
     {
         Url  = model.Url,
         Data = model
     }, DownloadHandler.Instance);
 }
Пример #6
0
        public dynamic GetByDotId(int Id)
        {
            var supplier   = new DotModel();
            var connection = new SqlConnection(sqlConnectionString);

            supplier = connection.Query <DotModel>("Select * from DotMaster where Id = @Id", new { Id = Id }).FirstOrDefault();
            return(supplier);
        }
Пример #7
0
        public void Succeed(MetaData wrapperData)
        {
            DotModel model = (DotModel)wrapperData.Data;

            try
            {
                model.LocalUrl = wrapperData.FullPath;
                LogUtil.Write(model.Id + "下载文件成功!");
            }
            catch (Exception ex)
            {
                LogUtil.Error(ex);
            }

            SerializeUtil.Serialize(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SerializeFolder, string.Concat(model.Id, string.Intern(".bin"))), model);
            autoReset.Set();
        }
Пример #8
0
        public async Task <IActionResult> SetDot(string data)
        {
            LatLng coords = JsonConvert.DeserializeObject <LatLng>(HttpUtility.UrlDecode(data).ToString());
            var    user   = await _userManager.GetUserAsync(User);

            DotModel dm = new DotModel();

            if (user != null)
            {
                dm.user  = user.UserName;
                dm.phone = user.PhoneNumber;
                dm.email = user.Email;
            }
            dm.latitude        = coords.latitude;
            dm.longitude       = coords.longitude;
            ViewBag.Categoryes = new SelectList(_context.Categories, "id", "name");
            return(View(dm));
        }
Пример #9
0
        public async Task <IHttpActionResult> AddDot([FromBody] DotModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            using (var connection = new SqlConnection(sqlConnectionString))
            {
                connection.Open();

                var CommandExist = connection.Query <DotModel>("Select * from DotMaster where DotName = @Name", new { Name = value.DotName }).FirstOrDefault();
                if (CommandExist == null)
                {
                    var p = new DotModel
                    {
                        DotName        = value.DotName,
                        AccountingUnit = value.AccountingUnit,
                        Dot            = value.Dot,
                        GSReserve      = value.GSReserve,
                        IsActive       = true
                    };


                    p.Id = connection.Query <int>(@"insert DotMaster(DotName,AccountingUnit,Dot,GSReserve,IsActive) values (@DotName,@AccountingUnit,@Dot,@GSReserve,@IsActive) select cast(scope_identity() as int)", p).First();
                    for (int i = 0; i < value.ProductListNew.Count; i++)
                    {
                        var product = new DotProductMaster
                        {
                            DotId     = p.Id,
                            ProductId = value.ProductListNew[i].ProductId
                        };
                        product.DotProductId = connection.Query <int>(@"insert DotProductMaster(DotId,ProductId) values (@DotId,@ProductId) select cast(scope_identity() as int)", product).First();
                    }


                    return(Json(new { Message = "Record Inserted Successfully" }));
                }
                else
                {
                    throw new ProcessException("Dot already exists");
                }
            }
        }
Пример #10
0
        public dynamic GetAllDot()
        {
            var             connection    = new SqlConnection(sqlConnectionString);
            var             dotList       = connection.Query <DotModel>("Select * from DotMaster where IsActive = 1").ToList();
            List <DotModel> responseModel = new List <DotModel>();

            for (int i = 0; i < dotList.Count; i++)
            {
                DotModel temp = new DotModel();
                temp.DotName        = dotList[i].DotName;
                temp.Dot            = dotList[i].Dot;
                temp.AccountingUnit = dotList[i].AccountingUnit;
                temp.GSReserve      = dotList[i].GSReserve;
                temp.Id             = dotList[i].Id;
                temp.ProductListNew = new List <DotProductMaster>();
                var dotProductList = connection.Query <DotProductMaster>("Select * from DotProductMaster where DotId = '" + dotList[i].Id + "'").ToList();
                for (int j = 0; j < dotProductList.Count; j++)
                {
                    DotProductMaster productList = new DotProductMaster();


                    var ProductList = connection.Query <ProductListNew>("Select * from ProductMaster_New where Id = '" + dotProductList[j].ProductId + "'").First();
                    productList.ProductId   = ProductList.Id;
                    productList.productName = ProductList.VarietyName;
                    temp.ProductListNew.Add(productList);
                }
                responseModel.Add(temp);
            }
            //SqlCommand command = new SqlCommand("spManageDot", connection);
            //command.CommandType = System.Data.CommandType.StoredProcedure;

            //connection.Open();

            //DataTable dt = new DataTable();

            //dt.Load(command.ExecuteReader());
            //var list = DataTableToJSONWithJSONNet(dt);
            //dynamic json = JsonConvert.DeserializeObject(list);


            return(responseModel);
        }
Пример #11
0
        public IActionResult EditDot(string id)
        {
            int      dotId = JsonConvert.DeserializeObject <int>(HttpUtility.UrlDecode(id));
            Dot      dot   = _context.Dots.FirstOrDefault(d => d.id == dotId);
            DotModel dm    = new DotModel();

            dm.category_id     = dot.category_id;
            dm.city            = dot.city;
            dm.description     = dot.description;
            dm.dot_id          = dot.id;
            dm.email           = dot.email;
            dm.latitude        = dot.latitude;
            dm.longitude       = dot.longitude;
            dm.phone           = dot.phone;
            dm.time_close      = dot.time_close;
            dm.time_open       = dot.time_open;
            dm.title           = dot.title;
            dm.website         = dot.website;
            ViewBag.Categoryes = new SelectList(_context.Categories, "id", "name", dm.category_id);
            return(View("SetDot", dm));
        }
Пример #12
0
        public async Task <IHttpActionResult> UpdateDot([FromBody] DotModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            using (TransactionScope scope = new TransactionScope())
                using (var connection = new SqlConnection(sqlConnectionString))
                {
                    connection.Open();

                    var p = new DotModel
                    {
                        DotName        = value.DotName,
                        AccountingUnit = value.AccountingUnit,
                        Dot            = value.Dot,
                        GSReserve      = value.GSReserve,
                    };

                    string updateQuery = @"UPDATE DotMaster SET Dot = @Dot,Name=@Name,AccountingUnit = @AccountingUnit,GSReserve=@GSReserve, Name= @Name WHERE Id = @Id";
                    for (int i = 0; i < value.ProductListNew.Count; i++)
                    {
                        var CommandExist = connection.Query <DotModel>("Select * from DotProductMaster where ProductId = @ProductId and DotId=@DotId", new { ProductId = value.ProductListNew[i].ProductId, DotId = value.Id }).FirstOrDefault();
                        if (CommandExist == null)
                        {
                            var product = new DotProductMaster
                            {
                                DotId     = p.Id,
                                ProductId = value.ProductListNew[i].ProductId
                            };
                            product.DotProductId = connection.Query <int>(@"insert DotProductMaster(DotId,ProductId) values (@DotId,@ProductId) select cast(scope_identity() as int)", product).First();
                        }
                    }
                    //For Deleting records

                    var result = connection.Execute(updateQuery, value);
                    scope.Complete();
                    return(Json(new { Message = "Record Updated Successfully" }));
                }
        }