public void Attach() { string filename = Path.GetFileName(fuAttachment.FileName); string fullPath = path + filename; MaterialFacade facade = new MaterialFacade(); if (hfId.Value != null) { if (fuAttachment.PostedFile != null) { HttpPostedFile myFile = fuAttachment.PostedFile; int nFileLen = myFile.ContentLength; byte[] myData = new byte[nFileLen]; myFile.InputStream.Read(myData, 0, nFileLen); WriteToFile(fullPath, ref myData); facade.UpdateAttachment(Convert.ToInt32(hfId.Value), filename); gvMaterials.DataBind(); } } }
protected void btnSave_Click(object sender, EventArgs e) { MaterialFacade facade = new MaterialFacade(); int? id = null; decimal? nullValue = null; try { id = (!String.IsNullOrEmpty(hfId.Value)) ? Convert.ToInt32(hfId.Value) : id; facade.Save(id, txtMaterialCode.Text, txtMaterialName.Text, txtDescription.Text, (!String.IsNullOrEmpty(txtPricePerUnit.Text)) ? Convert.ToDecimal(txtPricePerUnit.Text) : nullValue , (!String.IsNullOrEmpty(hfAttachment.Value) ? hfAttachment.Value : null) , DateTime.Now, DateTime.Now, user, user); lblErrorMessage.Text = Helper.SaveRecordMessage(true); } catch (Exception ex) { lblErrorMessage.Text = Helper.SaveRecordMessage(false); } gvMaterials.DataBind(); Helper.EnableControls(false, action); fuAttachment.Visible = false; btnUpload.Visible = false; }