protected void Confirm_Button_Click(object sender, EventArgs e) { CommonClassLibrary.Account account = new CommonClassLibrary.Account() { Name = Name_account.Text, Idname = No_account.Text, Bank = Name_bank.Text, Sector = Sector_bank.Text }; model.Accounts.Add(account); if (model.SaveChanges() > 0) { this.SuccessPanel.Visible = true; this.SuccessLabel.Text = "บันทึกข้อมูลสำเร็จ"; this.ErrorPanel.Visible = false; showaccountdetail(); this.account.Visible = true; addaccount.Visible = false; } else { this.SuccessPanel.Visible = false; this.ErrorLabel.Text = "บันทึกข้อมูลไม่สำเร็จ"; this.ErrorPanel.Visible = true; } }
public void saveImage() { HttpPostedFile UpFileProduct = Picture_FileUpload.PostedFile; string UpFilePro = System.IO.Path.GetExtension(UpFileProduct.FileName); if (this.Picture_FileUpload.PostedFile.FileName.ToString() != "") { long IDProduct1 = (long)new CommonClassLibrary.CommonDataSetTableAdapters.TextContentTableAdapter().InsertQuery(Name_TextBox.Text, NameEN_TextBox.Text, " ", DateTime.Now, DateTime.Now, 1); if (UpFilePro == ".jpg" || UpFilePro == ".png" || UpFilePro == ".JPG" || UpFilePro == ".PNG" || UpFilePro == ".jpeg" || UpFilePro == ".JPEG") { string imageFileName = "IMF" + "_" + DateTime.Now.ToString("ddMMyyyy-HHmmss"); imageFileName += ".jpg"; string aaa = imageFileName; string path = System.IO.Path.Combine(Server.MapPath("~/Image/"), imageFileName); // string path = System.IO.Path.Combine(Server.MapPath("D:/OWP/DigitalServicesRestaurant/ManagementWebSite/Image/"), imageFileName); UpFileProduct.SaveAs(path); try { CommonClassLibrary.TypeCate tc = new CommonClassLibrary.TypeCate() { Name = IDProduct1.ToString(), UrlImage = aaa, CreateDate = DateTime.Now, LastUpdate = DateTime.Now, Status = 1 }; innofood.TypeCates.Add(tc); innofood.SaveChanges(); ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "บันทึกข้อมูลสำเร็จ" + "');", true); //this.SuccessPanel.Visible = true; //this.ErrorPanel.Visible = false; //this.SuccessLabel.Text = "บันทึกข้อมูลสำเร็จ"; Response.Redirect("~/ListCategory.aspx"); } catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "บันทึกข้อมูลไม่สำเร็จ" + "');", true); //this.SuccessPanel.Visible = false; //this.ErrorPanel.Visible = true; //this.ErrorLabel.Text = "บันทึกข้อมูลไม่สำเร็จ"; } //if (new CommonClassLibrary.CommonDataSetTableAdapters.CategoryTableAdapter().Insert(IDProduct1.ToString(), aaa, DateTime.Now, DateTime.Now, 1) == 1) //{ // this.SuccessLabel.Text = "บันทึกข้อมูลสำเร็จ"; // Response.Redirect("~/AddCategory.aspx"); //} //else //{ // FileInfo DeleteImage = new FileInfo(@"C:/FTP/Imilk/Image/" + aaa); // DeleteImage.Delete(); // this.SuccessPanel.Visible = false; // this.ErrorPanel.Visible = true; // this.ErrorLabel.Text = "บันทึกข้อมูลไม่สำเร็จ"; //} } } else { ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "บันทึกข้อมูลไม่สำเร็จ กรุณาเลือกรูปภาพ" + "');", true); //this.SuccessPanel.Visible = false; //this.ErrorPanel.Visible = true; //this.ErrorLabel.Text = "บันทึกข้อมูลไม่สำเร็จ กรุณาเลือกรูปภาพ"; } }