Làm quen mới NodeJS
Xem chi tiết link dưới:
https://www.TuanDev.com
Nếu bạn dùng chatwork và đôi khi muốn gửi 1 thông báo tới tất cả các room/group mà bạn không muốn copy paste thì làm thế nào?
Nếu bạn biết code c#, hãy tham khảo đoạn code sau
Thứ nhất, lấy toàn bộ danh sách room bạn có, trước hết bạn cần có token cá nhân
hãy đăng nhập vào tài khoản chatwork của bạn rồi truy cập link sau để lấy token
https://www.chatwork.com/service/packages/chatwork/subpackages/api/token.php
=====
//Hàm lấy danh sách room
public partial class ChatworkClient
{
public static List<RoomInfo> GetRooms(string token)
{
var client = new RestClient("https://api.chatwork.com/v2/rooms");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("X-ChatWorkToken", token);
IRestResponse response = client.Execute(request);
//Console.WriteLine(response.Content);
if(response.IsSuccessful && !string.IsNullOrEmpty(response.Content))
{
var rooms = JsonConvert.DeserializeObject<List<RoomInfo>>(response.Content);
return rooms;
}
return null;
}
}
=====
//model RoomInfo:
public class RoomInfo
{
public int room_id { get; set; }
public string name { get; set; }
}
======
//Tiếp theo, thực hiện gửi tin nhắn
tham khảo thêm chatwork API: trang 25,
[POST] /rooms/{room_id}/messages
https://download.chatwork.com/ChatWork_API_Documentation.pdf
Đôi khi bạn cần tạo form động, cho phép người dùng tùy ý thêm field dữ liệu vào form
Dưới đây là đoạn code thêm fields động vào form dùng trong dự án .net core, view razor
<!-- html code -->
<table class="table table-responsive" id="product-table">
<tr>
<th>TÊN SẢN PHẨM</th>
<th>SỐ LƯỢNG</th>
<th>
<a href="javascript:void(0);" class="btn btn-sm btn-success">
<i class="fas fa-plus" onclick="addNewRow()"> Thêm sản phẩm</i>
</a>
</th>
</tr>
<tr>
<td id="col0">
<input class="form-control" type="text" asp-for="Products" />
</td>
<td id="col1">
<input class="form-control" type="text" asp-for="ProductCount" />
</td>
<td id="col2">
</td>
</tr>
</table>
<!-- javascript code -->
<script>
/* This method will add a new row */
function addNewRow() {
let table = document.getElementById("product-table");
let rowCount = table.rows.length;
let cellCount = table.rows[0].cells.length;
let row = table.insertRow(rowCount);
for (let i = 0; i < cellCount; i++) {
let cell = 'cell' + i;
cell = row.insertCell(i);
if (i < cellCount - 1) {
let copycel = document.getElementById('col' + i).innerHTML;
cell.innerHTML = copycel;
} else {
cell.innerHTML = '<a href="javascript:void(0);" class="btn btn-danger btn-sm"><i class="fas fa-trash" onclick="deleteRow(this)"> Xóa sản phẩm</i></a>';
}
}
}
/* This method will delete a row */
function deleteRow(ele) {
let table = document.getElementById('product-table');
let rowCount = table.rows.length;
if (rowCount < 3) {
alert("There is no row available to delete!");
return;
} else {
if (ele) {
//delete specific row
ele.parentNode.parentNode.parentNode.remove();
} else {
//delete last row
table.deleteRow(rowCount - 1);
}
}
}
</script>
[Happy coding]
Đôi khi trong dự án bạn cần tạo mã tăng dần, theo cấu trúc nhất định
Có nhiều cách để thực hiện việc này, sql server sequence là 1 cách
bước 1:
tạo sequence bắt đầu giá trị 1, tăng dần 1 như sau
create sequence dbo.testing
start with 1
increment by 1;
go
bước 2:
tạo mã để sử dụng
select 'GID' + REPLACE(convert(nvarchar(10),getdate(),4),'.','')
+ right('0000'+cast(next value for dbo.testing as nvarchar(5)),5)
bước bổ sung:
kiểm tra sequence hiện tại
SELECT * FROM sys.sequences WHERE name = 'testing' ;
có thể bạn cần reset giá trị của sequence
alter sequence dbo.testing restart with 1;
Khi code chức năng gửi mail smtp bằng c#
đôi khi thiết lập mail server không chính xác hoặc SSL mail server không hợp lệ
bạn sẽ gặp exception như sau
===
> Source file path:SendMail
> Source line number:107
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Mail.SmtpConnection.Flush()
at System.Net.Mail.ReadLinesCommand.Send(SmtpConnection conn)
at System.Net.Mail.EHelloCommand.Send(SmtpConnection conn, String domain)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
===
(*) Cách sửa đơn giản: MailClient sét EnableSsl = false;
Thông tin vòng đời .net framework cho anh chị em lưu ý, nâng cấp, chỉnh sửa sản phẩm cũ hay phát triển sản phẩm mới liên quan .net
https://docs.microsoft.com/en-us/lifecycle/products/microsoft-net-framework
.NET Framework 4.5.2, 4.6, 4.6.1 will reach End of Support on April 26, 2022
https://devblogs.microsoft.com/dotnet/net-framework-4-5-2-4-6-4-6-1-will-reach-end-of-support-on-april-26-2022/
Chính thức trở thành đơn vị cung cấp dịch vụ đăng ký tên miền quốc tế, tên miền Việt Nam hosting, máy chủ, cloud hosting, cloud server, ema...