public ActionResult CreateFolder(string foldername)
 {
     try
     {
         Merchant_Folder_Info item = new Merchant_Folder_Info();
         item.ma_gian_hang   = currentUser.ma_gian_hang;
         item.ten_thu_muc    = foldername.Trim();
         item.nguoi_tao      = currentUser.name;
         item.nguoi_cap_nhat = currentUser.name;
         string result = new Merchant_Folder_Info_DAO().Insert(item, AppConfigs.MCCConnectionString);
         if (result != "true")
         {
             return(Json(new { success = false, message = result }));
         }
         return(Json(new { success = true }));
     }
     catch (Exception e)
     {
         return(Json(new { success = false, message = e.Message }));
     }
 }
示例#2
0
        public ActionResult Save(List <HttpPostedFileBase> files)
        {
            try
            {
                int i = 0;
                Merchant_Folder_Info folder = new Merchant_Folder_Info();
                folder.ma_gian_hang   = currentUser.ma_gian_hang;
                folder.ten_thu_muc    = AllConstant.FoldderName_Merchant_Catalog;
                folder.ngay_tao       = DateTime.Now;
                folder.nguoi_tao      = currentUser.name;
                folder.ngay_cap_nhat  = DateTime.Now;
                folder.nguoi_cap_nhat = currentUser.name;
                string a = new Merchant_Folder_Info_DAO().Insert(folder, AppConfigs.MCCConnectionString);
                foreach (var item in files)
                {
                    string LocalPath       = "";
                    string LocalFolderPath = "";
                    string url_link        = new AzureHelper().UploadFileToAzure("Catalog", item, currentUser.name, ref LocalFolderPath, ref LocalPath);
                    //update catalog info
                    Merchant_Catalog catalog = new Merchant_Catalog();
                    catalog.dung_luong       = item.ContentLength;
                    catalog.duong_dan_day_du = url_link;
                    catalog.ma_gian_hang     = currentUser.ma_gian_hang;
                    catalog.ten_catalog      = Path.GetFileNameWithoutExtension(item.FileName);
                    catalog.thu_muc          = LocalFolderPath;
                    catalog.url = DateTime.Now.ToString("yyyyMMddHHmmssfff") + currentUser.name + "-" + item.FileName;
                    string b = new Merchant_Catalog_DAO().UpSert(catalog, currentUser.name, AppConfigs.MCCConnectionString);

                    if (!string.IsNullOrEmpty(url_link))
                    {
                        i++;
                    }
                }
                return(Json(new { success = true, message = "Upload thành công " + i.ToString() + " file!" }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, message = e.Message }));
            }
        }
示例#3
0
        public string UploadImageToAzure(string FolderName, HttpPostedFileBase file, string ma_gian_hang, string UserName)
        {
            if (String.IsNullOrEmpty(FolderName.Trim()))
            {
                FolderName = AllConstant.FoldderName_Merchant_Product;
            }

            Merchant_Folder_Info item = new Merchant_Folder_Info();

            item.ma_gian_hang   = ma_gian_hang;
            item.ten_thu_muc    = FolderName;
            item.nguoi_tao      = UserName;
            item.nguoi_cap_nhat = UserName;
            string a = new Merchant_Folder_Info_DAO().Insert(item, AppConfigs.MCCConnectionString);


            string idref    = UserName + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
            var    fileName = Path.GetFileNameWithoutExtension(file.FileName);

            var img           = Image.FromStream(file.InputStream, true, true);
            var listType      = new List <Code_Master>();
            var listExtension = listType;

            using (IDbConnection db = OrmliteConnection.openConn(AppConfigs.MCCConnectionString))
            {
                listType      = db.Select <Code_Master>(s => s.Type == "IMGResizeType");
                listExtension = db.Select <Code_Master>(s => s.Type == "IMGResizeFormat");
            }

            if (listType.Count == 0)
            {
                return("Không tìm thấy cấu hình");
            }
            foreach (Code_Master type in listType)
            {
                var refix = idref;
                img = AutoResize(img, type.Value);
                if (img == null)
                {
                    return("Không tìm thấy cấu hình");
                }
                var    i               = 0;
                string FolderPath      = System.Web.HttpContext.Current.Server.MapPath("~/Images/Merchant_Image_Info/" + ma_gian_hang + "/" + FolderName + "/");
                var    destinationPath = Path.Combine(FolderPath, refix);

                if (!Directory.Exists(FolderPath))
                {
                    Directory.CreateDirectory(FolderPath);
                }
                var    lastRefix = "_" + img.Width.ToString() + "x" + img.Height.ToString();
                string extension = ".jpg";
                foreach (var ex in listExtension)
                {
                    if (ex.Value == type.Value)
                    {
                        extension = ex.Name;
                        break;
                    }
                }
                while (System.IO.File.Exists(destinationPath + i.ToString() + lastRefix + extension))
                {
                    i++;
                }
                destinationPath += i.ToString() + lastRefix + extension;
                img.Save(destinationPath);
                return(new BIBIAM.Core.AzureHelper().UploadFile(ma_gian_hang, refix + i.ToString() + lastRefix + extension, destinationPath));
            }

            return(string.Empty);
        }
示例#4
0
        public string UploadImageToFolder(string FolderName, HttpPostedFileBase file, string ma_gian_hang, string UserName)
        {
            List <Merchant_Image_Info> list = new List <Merchant_Image_Info>();
            List <string> listPath          = new List <string>();
            string        duong_dan_day_du  = string.Empty;

            if (String.IsNullOrEmpty(FolderName.Trim()))
            {
                FolderName = AllConstant.FoldderName_Merchant_Product;
            }

            Merchant_Folder_Info item = new Merchant_Folder_Info();

            item.ma_gian_hang   = ma_gian_hang;
            item.ten_thu_muc    = FolderName;
            item.nguoi_tao      = UserName;
            item.nguoi_cap_nhat = UserName;
            string a = new Merchant_Folder_Info_DAO().Insert(item, AppConfigs.MCCConnectionString);


            string idref    = UserName + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
            var    fileName = Path.GetFileNameWithoutExtension(file.FileName);

            var img           = Image.FromStream(file.InputStream, true, true);
            var listType      = new List <Code_Master>();
            var listExtension = listType;

            using (IDbConnection db = OrmliteConnection.openConn(AppConfigs.MCCConnectionString))
            {
                listType      = db.Select <Code_Master>(s => s.Type == "IMGResizeType");
                listExtension = db.Select <Code_Master>(s => s.Type == "IMGResizeFormat");
            }

            if (listType.Count == 0)
            {
                return("Không tìm thấy cấu hình");
            }
            foreach (Code_Master type in listType)
            {
                Merchant_Image_Info _item = new Merchant_Image_Info();
                var refix = idref;
                img = AutoResize(img, type.Value);
                if (img == null)
                {
                    return("Không tìm thấy cấu hình");
                }
                var    i               = 0;
                string FolderPath      = System.Web.HttpContext.Current.Server.MapPath("~/Images/Merchant_Image_Info/" + ma_gian_hang + "/" + FolderName + "/");
                var    destinationPath = Path.Combine(FolderPath, refix);

                if (!Directory.Exists(FolderPath))
                {
                    Directory.CreateDirectory(FolderPath);
                }
                var    lastRefix = "_" + img.Width.ToString() + "x" + img.Height.ToString();
                string extension = ".jpg";
                foreach (var ex in listExtension)
                {
                    if (ex.Value == type.Value)
                    {
                        extension = ex.Name;
                        break;
                    }
                }
                while (System.IO.File.Exists(destinationPath + i.ToString() + lastRefix + extension))
                {
                    i++;
                }
                destinationPath += i.ToString() + lastRefix + extension;
                img.Save(destinationPath);

                listPath.Add(destinationPath);
                _item.url              = refix + i.ToString() + lastRefix + extension;
                _item.ma_anh_goc       = idref;
                _item.chieu_rong       = img.Width;
                _item.chieu_cao        = img.Height;
                _item.dung_luong       = new FileInfo(destinationPath).Length;
                _item.thu_muc          = ma_gian_hang + "/" + FolderName + "/";
                _item.duong_dan_day_du = new AzureHelper().UploadFile(ma_gian_hang, _item.url, destinationPath);
                _item.loai             = Int16.Parse(type.Value);
                _item.trang_thai       = "Active";
                _item.trang_thai_duyet = "New";
                _item.ten_anh          = fileName;
                _item.mo_ta            = _item.mo_ta_khong_dau = "";
                _item.ma_gian_hang     = ma_gian_hang;
                list.Add(_item);

                if (type.Name == "Small")
                {
                    duong_dan_day_du = _item.duong_dan_day_du;
                }
            }

            string result = new Merchant_Image_Info_DAO().UpSert(list, UserName, AppConfigs.MCCConnectionString);

            if (result != "true")
            {
                foreach (var path in listPath)
                {
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                }
            }
            return(duong_dan_day_du);
        }
        public ActionResult Save(List <HttpPostedFileBase> files, string FolderName)
        {
            try
            {
                List <Merchant_Image_Info> list = new List <Merchant_Image_Info>();
                List <string> listPath          = new List <string>();

                if (String.IsNullOrEmpty(FolderName.Trim()))
                {
                    FolderName = AllConstant.FoldderName_Merchant_Product;
                    Merchant_Folder_Info item = new Merchant_Folder_Info();
                    item.ma_gian_hang   = currentUser.ma_gian_hang;
                    item.ten_thu_muc    = FolderName;
                    item.nguoi_tao      = currentUser.name;
                    item.nguoi_cap_nhat = currentUser.name;
                    string a = new Merchant_Folder_Info_DAO().Insert(item, AppConfigs.MCCConnectionString);
                }

                foreach (var file in files)
                {
                    string idref    = currentUser.name + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    var    fileName = Path.GetFileNameWithoutExtension(file.FileName);

                    var img           = Image.FromStream(file.InputStream, true, true);
                    var listType      = new List <Code_Master>();
                    var listExtension = listType;
                    using (IDbConnection db = OrmliteConnection.openConn(AppConfigs.MCCConnectionString))
                    {
                        //db.ChangeDatabase(AllConstant.ERPDBName);
                        listType      = db.Select <Code_Master>(s => s.Type == "IMGResizeType");
                        listExtension = db.Select <Code_Master>(s => s.Type == "IMGResizeFormat");
                    }
                    if (listType.Count == 0)
                    {
                        return(Json(new { success = false, message = "Không tìm thấy cấu hình" }));
                    }
                    foreach (Code_Master type in listType)
                    {
                        var refix = idref;
                        Merchant_Image_Info item = new Merchant_Image_Info();
                        img = AutoResize(img, type.Value);
                        if (img == null)
                        {
                            return(Json(new { success = false, message = "Không tìm thấy cấu hình" }));
                        }
                        var    i               = 0;
                        string FolderPath      = Server.MapPath("~/Images/Merchant_Image_Info/" + currentUser.ma_gian_hang + "/" + FolderName + "/");
                        var    destinationPath = Path.Combine(FolderPath, refix);

                        if (!Directory.Exists(FolderPath))
                        {
                            Directory.CreateDirectory(FolderPath);
                        }
                        var    lastRefix = "_" + img.Width.ToString() + "x" + img.Height.ToString();
                        string extension = ".jpg";
                        foreach (var ex in listExtension)
                        {
                            if (ex.Value == type.Value)
                            {
                                extension = ex.Name;
                                break;
                            }
                        }
                        while (System.IO.File.Exists(destinationPath + i.ToString() + lastRefix + extension))
                        {
                            i++;
                        }
                        destinationPath += i.ToString() + lastRefix + extension;
                        img.Save(destinationPath);

                        listPath.Add(destinationPath);
                        item.url        = refix + i.ToString() + lastRefix + extension;
                        item.ma_anh_goc = idref;
                        item.chieu_rong = img.Width;
                        item.chieu_cao  = img.Height;
                        item.dung_luong = new FileInfo(destinationPath).Length;
                        item.thu_muc    = currentUser.ma_gian_hang + "/" + FolderName + "/";
                        //item.duong_dan_day_du = FolderPath + item.url;
                        item.duong_dan_day_du = new AzureHelper().UploadFile(currentUser.ma_gian_hang, item.url, destinationPath);
                        item.loai             = Int16.Parse(type.Value);
                        item.trang_thai       = AllConstant.trang_thai.DANG_SU_DUNG;
                        item.trang_thai_duyet = AllConstant.trang_thai_duyet.CHUA_DUYET;
                        item.ten_anh          = fileName;
                        item.mo_ta            = item.mo_ta_khong_dau = "";
                        item.ma_gian_hang     = currentUser.ma_gian_hang;
                        list.Add(item);
                    }
                }
                string result = new Merchant_Image_Info_DAO().UpSert(list, currentUser.name, AppConfigs.MCCConnectionString);

                if (result != "true")
                {
                    foreach (var path in listPath)
                    {
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                    }
                    return(Json(new { success = false, message = result }));
                }
                else
                {
                    return(Json(new { success = true, message = "Thành công" }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { success = false, message = e.Message }));
            }
        }