protected void btnDelete_Click(object sender, EventArgs e) { try { Factory fac = new Factory(); fac.FactoryId = int.Parse(hiddenFacID.Value); fac.isDeleted = true; fac.No = txtNo.Text; fac.Name = txtName.Text; fac.ImageFile = txtImgName.Text; fac.ModifiedAccount = this.User.Identity.Name; fac.Update(); Search(); panelEdit.Visible = false; panelMain.Visible = true; } catch (Exception ex) { RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), ex.Message) + "\");"); logger.Error("Erorr btnDelete_click", ex); } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (btnDelete.Enabled == false) { List<Factory> listFac = new List<Factory>(); listFac = Factory.GetAll().Where(l => l.Name.Trim().ToLower() == txtName.Text.Trim().ToLower()).ToList(); if (listFac.Count > 0) { RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), string.Format(GetResource("CheckName"), lblFactoryName.Text)) + "\");"); return; } Factory fac = new Factory(); fac.No = txtNo.Text; fac.CompanyId = int.Parse(GetCompany()); fac.Name = txtName.Text; fac.isDeleted = false; //fac.ImageFile = txtImgName.Text; fac.CreateAccount = fac.ModifiedAccount = this.User.Identity.Name; int id = Factory.InsertWithIndentity(fac); fac.ImageFile = id.ToString()+".png"; fac.Update(); string pathNew = Constant.PORTAL + GetCompanyPath() + string.Format(Constant.PATH_FACTORY, id, txtName.Text); if (!Directory.Exists(Server.MapPath(pathNew))) //(!Directory.Exists(Server.MapPath("~/Portal\\Images\\Factory\\"))) { Directory.CreateDirectory(Server.MapPath(pathNew)); //("~/Portal\\Images\\Factory\\)")); } string path = Server.MapPath(pathNew);//"~/Portal\\Images\\Factory\\"); //string filename = imgFactory.ImageUrl; string base64 = (string)ViewState["img"]; byte[] b = Convert.FromBase64String(base64); System.IO.File.WriteAllBytes(path + "/" + id +".png", b); } else { Factory fac = new Factory(); fac.FactoryId = int.Parse(hiddenFacID.Value); fac.CompanyId = int.Parse(GetCompany()); fac = fac.GetByPrimaryKey(); if (fac.Name.Trim() != txtName.Text.Trim()) { List<Factory> listFac = new List<Factory>(); listFac = Factory.GetAll().Where(l => l.Name.Trim().ToLower() == txtName.Text.Trim().ToLower()).ToList(); if (listFac.Count > 0) { RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), string.Format(GetResource("CheckName"), lblFactoryName.Text)) + "\");"); return; } } fac.ModifiedAccount = this.User.Identity.Name; fac.No = txtNo.Text; fac.Name = txtName.Text; fac.ImageFile = hiddenFacID.Value.ToString()+".png"; fac.Update(); string pathNew = Constant.PORTAL + GetCompanyPath() + string.Format(Constant.PATH_FACTORY, hiddenFacID.Value, txtName.Text); if (!Directory.Exists(Server.MapPath(pathNew))) //("~/Portal\\Images\\Factory\\"))) { Directory.CreateDirectory(Server.MapPath(pathNew)); //("~/Portal\\Images\\Factory\\)")); } string path = Server.MapPath(pathNew); //("~/Portal\\Images\\Factory\\"); if (ViewState["img"] != null) { string base64 = (string)ViewState["img"]; byte[] b = Convert.FromBase64String(base64); System.IO.File.WriteAllBytes(path + "/" + int.Parse(hiddenFacID.Value) + ".png", b); } } ViewState.Remove("img"); panelEdit.Visible = false; panelMain.Visible = true; Search(); } catch (Exception ex) { RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), ex.Message) + "\");"); logger.Error("Erorr btnSave_click", ex); } }