我无法单击批准按钮将签名保存到数据库中。 。请帮忙!我已经参考了这个链接,但他们没有工作。 https://www.aspsnippets.com/Articles/Convert-Export-HTML-DIV-or-Table-to-Image-using-HTML-Canvas-in-ASPNet-using-C-and-VBNet.aspx
批准按钮下的代码
<asp:Button ID="ProcesssOwner1" Visible="true" data-action="save" Text="Approve" CssClass="btn btn-success btn-sm" UseSubmitBehavior="false" OnClientClick="return ConvertToImage(this)" runat="server" OnClick="ProcesssOwner1_Click" />
的Javascript
<script type="text/javascript">
function ConvertToImage(ProcesssOwner1) {
if (signaturePad.isEmpty()) {
alert("Please provide signature first.");
return false;
} else {
//document.getElementById("hfSign").value = signaturePad.toDataURL();
html2canvas($("#drawing")[0]).then(function (canvas) {
var base64 = canvas.toDataURL();
$("[id*=hfImageData]").val(base64);
__doPostBack(ProcesssOwner1.name, "");
});
return false;
}
}
</script>
点击按钮下的代码
这里我尝试将签名保存在路径和文件夹中。
protected void ProcesssOwner1_Click(object sender, EventArgs e)
{
if (Session["loggedUserID"] == null && Session["loggedRoleID"] == null)
{
Response.Redirect("Login.aspx");
}
else
{
int loggedUserID = Convert.ToInt32(Session["loggedUserID"]);
List<BOL.UserInfo> userslist = new UserInfos().List();
BOL.UserInfo loggeduser = userslist.Where(x => x.UserID == loggedUserID).FirstOrDefault();
string app_type = "";
string dcr = Request.QueryString["r_id"].Replace("/", "_") + DateTime.Now.ToString("yyyy-MM-dd HHmmtt");
string myID = loggeduser.EmployeeNo;
string path1 = "/Web/";
//System.Diagnostics.Debugger.Launch();
if (Request.QueryString["STAT"] == "S_7")
{
app_type = "A";
string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
byte[] bytes = Convert.FromBase64String(base64);
//write the bytes to file:
File.WriteAllBytes(path1 + dcr + "_" + myID + app_type + ".jpg", bytes); //write to a temp location.
File.Copy(path1 + dcr + "_" + myID + app_type + ".jpg", @"D:\IntranetPortal\IntranetPortal\Web\signature\" + dcr + "_" + myID + app_type + ".jpg");//here we grab the file and copy it. //EDIT: based on permissions you might be able to write directly to the share instead of a temp folder first.
}
else if (Request.QueryString["STAT"] == "S_9")
{
app_type = "C";
string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
byte[] bytes = Convert.FromBase64String(base64);
//write the bytes to file:
File.WriteAllBytes(path1 + dcr + "_" + myID + app_type + ".jpg", bytes); //write to a temp location.
File.Copy(path1 + dcr + "_" + myID + app_type + ".jpg", @"D:\IntranetPortal\IntranetPortal\Web\signature\" + dcr + "_" + myID + app_type + ".jpg");//here we grab the file and copy it.
}
DAL.DMSS insertdata = new DMSS();
insertdata.APP_PROCESS(Request.QueryString["r_id"], app_type, chatt.Text, path1 + "signature" + "/" + dcr + "_" + myID + app_type + ".jpg", dcr + "_" + myID + app_type + ".jpg", loggeduser.EmployeeNo, DATEE.Text);
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Approved.Thank you.');window.location ='Dms_app.aspx';", true);
}
}