protected void btnEdit_Click(object sender, EventArgs e) { if (txtCarPlateNumber.Text.Trim() == "") { ClientScript.RegisterStartupScript(GetType(), ..... ...
<asp:FileUpload ID="FileUpload附件" runat="server" Width="200px" /> protected void btnEdit_Click(object sender, EventArgs e) { if (txtCarPlateNumber.Text.Trim() == "") { ClientScript.RegisterStartupScript(GetType(), "", "alert('請輸入車牌號!');", true); return; } int Id = 0; if (string.IsNullOrEmpty(Request.Params["Id"]) == false) { Id = int.Parse(Request.Params["Id"]); } ModelBlackWhiteList model = new ModelBlackWhiteList(); model.Id = Id; model.CarPlateType = ddlCarPlateType.SelectedItem.Text; model.CarPlateNumber = txtCarPlateNumber.Text.Trim(); model.Company = txtCompany.Text.Trim(); model.BWFlag = ddlBWFlag.SelectedItem.Value; model.OperatorName = this.UserLogin; model.CreateDateTime = DateTime.Now; string CommandName = Request.Params["CommandName"].ToString(); switch (CommandName) { case "Upd": { if (FileUpload附件.PostedFile.FileName.Trim().Length != 0) { string savePath; string fileName = DateTime.Now.ToString("yyyyMMddHHmmssms"); if (FileUpload附件.HasFile && FileUpload附件.PostedFile.FileName.Contains(".jpg")) { savePath = Server.MapPath("~/Upload/");//指定上傳文件在伺服器上的保存路徑 //檢查伺服器上是否存在這個物理路徑,如果不存在則創建 if (!System.IO.Directory.Exists(savePath)) { System.IO.Directory.CreateDirectory(savePath); } savePath = savePath + fileName + ".jpg"; FileUpload附件.SaveAs(savePath); model.CarPicPath = "/Upload /" + fileName + ".jpg"; } else { ClientScript.RegisterStartupScript(GetType(), "", "alert('請選擇JPG圖片文件!');", true); return; } } int result = SqlSugarClientHelper.SqlDBConnection.Updateable<ModelBlackWhiteList>(model).ExecuteCommand(); if (result > 0) { ClientScript.RegisterStartupScript(GetType(), "", "alert('保存成功!');window.location = 'BlackWhiteListManage.aspx';", true); } else { ClientScript.RegisterStartupScript(GetType(), "", "alert('保存失敗!');", true); } break; } case "New": { if (FileUpload附件.PostedFile.FileName.Trim().Length != 0) { string savePath; string fileName = DateTime.Now.ToString("yyyyMMddHHmmssms"); if (FileUpload附件.HasFile && FileUpload附件.PostedFile.FileName.Contains(".jpg")) { savePath = Server.MapPath("~/Upload/BWFLag/");//指定上傳文件在伺服器上的保存路徑 //檢查伺服器上是否存在這個物理路徑,如果不存在則創建 if (!System.IO.Directory.Exists(savePath)) { System.IO.Directory.CreateDirectory(savePath); } savePath = savePath + fileName + ".jpg"; FileUpload附件.SaveAs(savePath); model.CarPicPath = "/Upload/BWFLag/" + fileName + ".jpg"; } else { ClientScript.RegisterStartupScript(GetType(), "", "alert('請選擇JPG圖片文件!');", true); return; } } int result = SqlSugarClientHelper.SqlDBConnection.Insertable<ModelBlackWhiteList>(model).ExecuteCommand(); if (result > 0) { ClientScript.RegisterStartupScript(GetType(), "", "alert('保存成功!');window.location = 'BlackWhiteListManage.aspx';", true); } else { ClientScript.RegisterStartupScript(GetType(), "", "alert('保存失敗!');", true); } break; } } }