1. 單線圖修改多張上傳
2. 個人專屬logo
This commit is contained in:
parent
a1a406777b
commit
716c8d222b
@ -88,24 +88,38 @@ namespace SolarPower.Controllers
|
||||
myUser = userRepository.GetMyUserInfoByAccount(myAccount);
|
||||
myUser.Company = companyRepository.GetMyCompanyInfoById(myUser.CompanyId);
|
||||
|
||||
//判斷該檔案是否存在
|
||||
if (!string.IsNullOrEmpty(myUser.Company.Logo))
|
||||
//判斷該使用者是否有個人專屬Logo
|
||||
if (!string.IsNullOrEmpty(myUser.Logo))
|
||||
{
|
||||
var fullFilePath = Directory.GetCurrentDirectory() + "/wwwroot/" + Path.Combine("upload", "company_logo", myUser.Company.Logo);
|
||||
if (!System.IO.File.Exists(fullFilePath))
|
||||
var fullFilePath = Directory.GetCurrentDirectory() + "/wwwroot/" + Path.Combine("upload", "company_logo", myUser.Logo);
|
||||
if (System.IO.File.Exists(fullFilePath))
|
||||
{
|
||||
myUser.Company.Logo = "/img/logo.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
myUser.Company.Logo = "/" + Path.Combine("upload", "company_logo", myUser.Company.Logo);
|
||||
myUser.Logo = "/" + Path.Combine("upload", "company_logo", myUser.Logo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
myUser.Company.Logo = "/img/logo.png";
|
||||
//判斷該檔案是否存在
|
||||
if (!string.IsNullOrEmpty(myUser.Company.Logo))
|
||||
{
|
||||
var fullFilePath = Directory.GetCurrentDirectory() + "/wwwroot/" + Path.Combine("upload", "company_logo", myUser.Company.Logo);
|
||||
if (!System.IO.File.Exists(fullFilePath))
|
||||
{
|
||||
myUser.Company.Logo = "/img/logo.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
myUser.Company.Logo = "/" + Path.Combine("upload", "company_logo", myUser.Company.Logo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
myUser.Company.Logo = "/img/logo.png";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
myUser.Role = roleRepository.GetMyRoleInfoById(myUser.RoleId);
|
||||
|
||||
List<string> auth_arr = new List<string>();
|
||||
|
||||
@ -13,6 +13,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -26,6 +27,8 @@ namespace SolarPower.Controllers
|
||||
private readonly IPowerStationRepository powerStationRepository;
|
||||
private readonly IRoleRepository roleRepository;
|
||||
private string logoPath = "/upload/company_logo/";
|
||||
private string logoSaveAsPath = "";
|
||||
|
||||
public UserController(IUserRepository userRepository,
|
||||
ISendEmailService sendEmailService,
|
||||
IPowerStationRepository powerStationRepository,
|
||||
@ -35,6 +38,8 @@ namespace SolarPower.Controllers
|
||||
this.sendEmailService = sendEmailService;
|
||||
this.powerStationRepository = powerStationRepository;
|
||||
this.roleRepository = roleRepository;
|
||||
|
||||
logoSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "company_logo");
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
@ -320,6 +325,8 @@ namespace SolarPower.Controllers
|
||||
|
||||
var newPassword = edFunction.GetSHA256Encryption(random_password);
|
||||
|
||||
|
||||
|
||||
user = new User()
|
||||
{
|
||||
CompanyId = post.CompanyId,
|
||||
@ -344,7 +351,37 @@ namespace SolarPower.Controllers
|
||||
"CreatedBy",
|
||||
};
|
||||
|
||||
await userRepository.AddAsync(user, properties);
|
||||
var id = await userRepository.AddOneAsync(user, properties);
|
||||
|
||||
#region 處理公司Logo圖片
|
||||
if (post.LogoFile != null)
|
||||
{
|
||||
var split = post.LogoFile.FileName.Split(".");
|
||||
var fileName = "user_" + id + "." + split[split.Length - 1];
|
||||
|
||||
var fullPath = Path.Combine(logoSaveAsPath, fileName);
|
||||
|
||||
using (var stream = new FileStream(fullPath, FileMode.Create))
|
||||
{
|
||||
post.LogoFile.CopyTo(stream);
|
||||
}
|
||||
|
||||
UpdateUser updateUser = new UpdateUser()
|
||||
{
|
||||
Id = id,
|
||||
Logo = fileName
|
||||
};
|
||||
|
||||
properties = new List<string>()
|
||||
{
|
||||
"Id",
|
||||
"Logo"
|
||||
};
|
||||
|
||||
await userRepository.UpdatePersonInfo(updateUser, properties);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
var sendSubject = "新增帳號成功";
|
||||
var sendContent = $"您的新密碼為:{random_password}";
|
||||
@ -365,7 +402,7 @@ namespace SolarPower.Controllers
|
||||
#region 修改使用者
|
||||
UpdateUser update = new UpdateUser()
|
||||
{
|
||||
Id = post.Id,
|
||||
Id = user.Id,
|
||||
Name = post.Name,
|
||||
Email = post.Email,
|
||||
Phone = post.Phone,
|
||||
@ -386,6 +423,35 @@ namespace SolarPower.Controllers
|
||||
|
||||
await userRepository.UpdatePersonInfo(update, properties);
|
||||
|
||||
#region 處理公司Logo圖片
|
||||
if (post.LogoFile != null)
|
||||
{
|
||||
var split = post.LogoFile.FileName.Split(".");
|
||||
var fileName = "user_" + user.Id + "." + split[split.Length - 1];
|
||||
|
||||
var fullPath = Path.Combine(logoSaveAsPath, fileName);
|
||||
|
||||
using (var stream = new FileStream(fullPath, FileMode.Create))
|
||||
{
|
||||
post.LogoFile.CopyTo(stream);
|
||||
}
|
||||
|
||||
UpdateUser updateUser = new UpdateUser()
|
||||
{
|
||||
Id = user.Id,
|
||||
Logo = fileName
|
||||
};
|
||||
|
||||
properties = new List<string>()
|
||||
{
|
||||
"Id",
|
||||
"Logo"
|
||||
};
|
||||
|
||||
await userRepository.UpdatePersonInfo(updateUser, properties);
|
||||
}
|
||||
#endregion
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "儲存成功";
|
||||
#endregion
|
||||
|
||||
@ -2199,6 +2199,10 @@ ALTER TABLE `operation_firm`
|
||||
ADD COLUMN `TaxIDNumber` VARCHAR(8) NULL DEFAULT NULL COMMENT '統一編號' AFTER `Email`,
|
||||
ADD COLUMN `Remark` VARCHAR(255) NULL DEFAULT NULL COMMENT '備註' AFTER `TaxIDNumber`;
|
||||
|
||||
-- 使用者加入個人公司logo 20210911
|
||||
ALTER TABLE `user`
|
||||
ADD COLUMN `Logo` VARCHAR(100) NULL DEFAULT NULL COMMENT '公司logo' COLLATE 'utf8mb4_unicode_ci' AFTER `Email`;
|
||||
|
||||
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
|
||||
@ -49,6 +49,7 @@ namespace SolarPower.Models
|
||||
public int CompanyId { get; set; } //公司編號
|
||||
public int RoleId { get; set; } //角色編號
|
||||
public string Email { get; set; }
|
||||
public string Logo { get; set; }
|
||||
public MyCompany Company { get; set; } //公司資訊
|
||||
public MyRole Role { get; set; } //角色資訊
|
||||
public List<MyPowerStationGroupByCity> myPowerStationGroupByCities { get; set; }
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -38,6 +39,7 @@ namespace SolarPower.Models.User
|
||||
public string Phone { get; set; } //手機
|
||||
public int RoleId { get; set; } //角色編號
|
||||
public string Tel { get; set; } //市話
|
||||
public string Logo { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -87,6 +89,7 @@ namespace SolarPower.Models.User
|
||||
public string Email { get; set; } //信箱
|
||||
public string Phone { get; set; } //手機
|
||||
public int RoleId { get; set; } //角色編號
|
||||
public string Logo { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -129,6 +132,7 @@ namespace SolarPower.Models.User
|
||||
public string Account { get; set; } //帳號
|
||||
public int RoleId { get; set; } //角色編號
|
||||
public string Phone { get; set; } //手機
|
||||
public IFormFile LogoFile { get; set; } //個人logo
|
||||
}
|
||||
|
||||
public class UserSelectItemList
|
||||
|
||||
@ -2726,14 +2726,21 @@
|
||||
myDropzone.processQueue();
|
||||
});
|
||||
|
||||
myDropzone.on("sending", function (file, xhr, data) {
|
||||
if ((countPowerStationImage + myDropzone.files.length) > 5) {
|
||||
|
||||
myDropzone.on("sendingmultiple", function (file, xhr, data) {
|
||||
temp_count = countPowerStationImage + myDropzone.files.length;
|
||||
if (temp_count > 5) {
|
||||
toast_warning("圖片總數量不可超過 5 張");
|
||||
myDropzone.removeFile(file);
|
||||
file.forEach(function (item) {
|
||||
myDropzone.removeFile(item);
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
data.append("PowerStationId", stationId);
|
||||
data.append("StationImages", file);
|
||||
file.forEach(function (item) {
|
||||
data.append("StationImages", item);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -2865,8 +2872,8 @@
|
||||
url: "/PowerStation/SavePowerStationSingleLine",
|
||||
acceptedFiles: "image/*",
|
||||
autoProcessQueue: false,
|
||||
parallelUploads: 1,
|
||||
maxFiles: 1,
|
||||
parallelUploads: 5,
|
||||
maxFiles: 5,
|
||||
addRemoveLinks: true,
|
||||
uploadMultiple: true,
|
||||
dictRemoveFile: "移除",
|
||||
@ -2877,14 +2884,20 @@
|
||||
myDropzone.processQueue();
|
||||
});
|
||||
|
||||
myDropzone.on("sending", function (file, xhr, data) {
|
||||
if ((countPowerStationSingleLine + myDropzone.files.length) > 1) {
|
||||
toast_warning("請先刪除原本圖片");
|
||||
myDropzone.removeFile(file);
|
||||
myDropzone.on("sendingmultiple", function (file, xhr, data) {
|
||||
temp_count = countPowerStationSingleLine + myDropzone.files.length;
|
||||
if (temp_count > 5) {
|
||||
toast_warning("圖片總數量不可超過 5 張");
|
||||
file.forEach(function (item) {
|
||||
myDropzone.removeFile(item);
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
data.append("PowerStationId", stationId);
|
||||
data.append("SingleLineImages", file);
|
||||
file.forEach(function (item) {
|
||||
data.append("SingleLineImages", item);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -2934,7 +2947,6 @@
|
||||
Swal.fire({
|
||||
title: "刪除",
|
||||
text: "你確定是否刪除此筆資料?",
|
||||
type: "warning",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "是",
|
||||
@ -2945,7 +2957,8 @@
|
||||
var url = "/PowerStation/DeletePowerStationSingleLine";
|
||||
|
||||
var send_data = {
|
||||
Id: selectedImageId
|
||||
SelectedId: selectedImageId,
|
||||
PowerStationId: stationId
|
||||
}
|
||||
|
||||
$.post(url, send_data, function (rel) {
|
||||
|
||||
@ -109,7 +109,11 @@
|
||||
<aside class="page-sidebar">
|
||||
<div class="page-logo">
|
||||
<a href="#" class="page-logo-link press-scale-down">
|
||||
@if (!string.IsNullOrEmpty(ViewBag.myUser.Company.Logo))
|
||||
@if (!string.IsNullOrEmpty(ViewBag.myUser.Logo))
|
||||
{
|
||||
<img src="@ViewBag.myUser.Logo" alt="SmartAdmin WebApp" aria-roledescription="logo"> <span class="page-logo-text mr-1"></span> <span class="position-absolute text-white opacity-50 small pos-top pos-right mr-2 mt-n2"></span>
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ViewBag.myUser.Company.Logo))
|
||||
{
|
||||
<img src="@ViewBag.myUser.Company.Logo" alt="SmartAdmin WebApp" aria-roledescription="logo"> <span class="page-logo-text mr-1"></span> <span class="position-absolute text-white opacity-50 small pos-top pos-right mr-2 mt-n2"></span>
|
||||
}
|
||||
|
||||
@ -632,7 +632,7 @@
|
||||
if ($("#user-form").valid()) {
|
||||
var url = "/User/SaveUser";
|
||||
|
||||
var send_data = {
|
||||
@*var send_data = {
|
||||
Id: selected_id,
|
||||
CompanyId: $("#user_companyId_modal").val(),
|
||||
Name: $("#user_name_modal").val(),
|
||||
@ -640,9 +640,23 @@
|
||||
Account: $("#user_account_modal").val(),
|
||||
Phone: $("#user_phone_modal").val(),
|
||||
RoleId: $("#user_role_modal").val()
|
||||
}*@
|
||||
|
||||
var formData = new FormData();
|
||||
var logos = $('#user_logo_modal')[0].files;
|
||||
|
||||
formData.append("Id", selected_id);
|
||||
formData.append("CompanyId", $("#user_companyId_modal").val());
|
||||
formData.append("Name", $("#user_name_modal").val());
|
||||
formData.append("Email", $("#user_email_modal").val());
|
||||
formData.append("Account", $("#user_account_modal").val());
|
||||
formData.append("Phone", $("#user_phone_modal").val());
|
||||
formData.append("RoleId", $("#user_role_modal").val());
|
||||
if (logos.length > 0) {
|
||||
formData.append("LogoFile", logos[0])
|
||||
}
|
||||
|
||||
$.post(url, send_data, function (rel) {
|
||||
@*$.post(url, send_data, function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
@ -655,7 +669,30 @@
|
||||
UpdateRegisterNumber($("#user_companyId_modal").val());
|
||||
|
||||
userTable.ajax.reload();
|
||||
}, 'json');
|
||||
}, 'json');*@
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
data: formData,
|
||||
cache: false,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
toast_ok(rel.msg);
|
||||
$('#user-modal').modal('hide');
|
||||
|
||||
//更新當前剩餘可註冊使用者人數
|
||||
UpdateRegisterNumber($("#user_companyId_modal").val());
|
||||
|
||||
userTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
|
||||
@ -108,6 +108,11 @@
|
||||
<input type="text" id="user_phone_modal" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="form-group col-lg-6">
|
||||
<label class="form-label" for="user_logo_modal">專屬Logo(建議尺寸 200 * 40px)</label>
|
||||
<input type="file" id="user_logo_modal" name="user_logo_modal" class="form-control" accept="image/*">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user