void editeCustomerinfo() { string nickname = string.Empty; string modelimgurl = string.Empty; try { nickname = HttpContext.Current.Request.Form.Get("nickname").ToString(); } catch (Exception) { nickname = ""; } MSCustomers customerModel = new MSCustomers(); MSCustomersDAL customerDal = new MSCustomersDAL(); customerModel.ID = strUid; if (nickname != null && nickname != "") { #region -----------------头像上传------------------- HttpFileCollection files = HttpContext.Current.Request.Files; if (files.Count > 0) { //检查文件扩展名字 HttpPostedFile postedFile = files[0]; string fileName, fileExtension, file_oldid, file_id; //取出精确到毫秒的时间做文件的名称 string my_file_id = DateTime.Now.ToString("yyyyMMddHHmmssfff"); fileName = System.IO.Path.GetFileName(postedFile.FileName); fileExtension = System.IO.Path.GetExtension(fileName); file_id = my_file_id + fileExtension; if (fileName != "" && fileName != null && fileName.Length > 0) { fileExtension = System.IO.Path.GetExtension(fileName); string saveurl; modelimgurl = "HeadImg/"; saveurl = "../PalmShop/ShopCode/" + modelimgurl; saveurl = Server.MapPath(saveurl); if (!Directory.Exists(saveurl)) { Directory.CreateDirectory(saveurl); } int length = postedFile.ContentLength; if (length > 512000) { file_oldid = "old" + file_id; postedFile.SaveAs(saveurl + file_oldid); JQDialog.ystp(saveurl + file_oldid, saveurl + file_id, 15); File.Delete(saveurl + file_oldid); } else { postedFile.SaveAs(saveurl + file_id); } modelimgurl = modelimgurl + file_id; } } #endregion customerModel.NickName = nickname; if (modelimgurl != null && modelimgurl != "") { customerModel.HeadImg = modelimgurl; } customerModel.IsDel = 0; if (customerDal.UpdateCustomers(customerModel)) { if (modelimgurl != null && modelimgurl != "") { if (oldimgname != null && oldimgname != "") { File.Delete(String.Format(@"{0}PalmShop/ShopCode/{1}", Server.MapPath("~"), oldimgname)); } } errorscript = JQDialog.alertOKMsgBox(3, "操作成功", "MyTopicList.aspx?fid=" + strfid, "succeed"); } else { errorscript = JQDialog.alertOKMsgBox(3, "操作失败,请核对后再操作", "Customerinfo.aspx?fid=" + strfid, "error"); } } else { errorscript = JQDialog.alertOKMsgBox(3, "操作失败,请核对后再操作", "Customerinfo.aspx?fid=" + strfid, "error"); } }
protected void btnSave_Click(object sender, EventArgs e) { if (Session["strLoginName"].ToString() != null && Session["strLoginName"].ToString() != "") { if (phone.Text.Trim() != null && phone.Text.Trim() != "" && password.Text.Trim() != null && password.Text.Trim() != "" && NickName.Text.Trim() != null && NickName.Text.Trim() != "") { //上传图像 string strIconFileName = string.Empty; //图像路径 string strIconSaveFileName = string.Empty; //网址路径 try { if (this.file0.PostedFile.FileName == "") { strIconSaveFileName = ""; } else { if (!System.IO.Directory.Exists(Server.MapPath("~") + @"/PalmShop")) { System.IO.Directory.CreateDirectory(Server.MapPath("~") + @"/PalmShop"); } if (!System.IO.Directory.Exists(String.Format(@"{0}/PalmShop/ShopCode/HeadImg/{1}", Server.MapPath("~"), phone.Text))) { System.IO.Directory.CreateDirectory(String.Format(@"{0}/PalmShop/ShopCode/HeadImg/{1}", Server.MapPath("~"), phone.Text)); } string orignalName = this.file0.PostedFile.FileName; //获取客户机上传文件的文件名 string extendName = orignalName.Substring(orignalName.LastIndexOf(".")); //获取扩展名 if (extendName != ".gif" && extendName != ".jpg" && extendName != ".jpeg" && extendName != ".png") { MessageBox.Show(this, "文件格式有误!"); return; }//检查文件格式 string newName = String.Format("{0}_{1}{2}", DateTime.Now.Millisecond, file0.PostedFile.ContentLength, extendName);//对文件进行重命名 strIconFileName = String.Format(@"{0}PalmShop/ShopCode/HeadImg/{1}/{2}", Server.MapPath("~"), phone.Text, newName); strIconSaveFileName = String.Format(@"HeadImg/{0}/{1}", phone.Text, newName); file0.PostedFile.SaveAs(strIconFileName); if (oldimg.Trim() != null && oldimg.Trim() != "" && oldimg.Trim().ToLower() != "shoplogo/default.png") { System.IO.File.Delete(String.Format(@"{0}PalmShop/ShopCode/{1}", Server.MapPath("~"), oldimg)); } } } catch (Exception ex) { MessageBox.Show(this, "上传发生错误!原因是:" + ex.ToString()); } MSCustomersDAL CustomerDal = new MSCustomersDAL(); MSCustomers CustomerModel = new MSCustomers(); CustomerModel.Phone = phone.Text; CustomerModel.NickName = NickName.Text; CustomerModel.Pnote = hd_content.Value; CustomerModel.Email = email.Text; CustomerModel.QQnum = QQnum.Text; CustomerModel.Sex = isstateyes.Checked ? 0 : 1; CustomerModel.UserPwd = Common.Common.MD5(password.Text); CustomerModel.IsDel = 0; CustomerModel.ID = strID; if (strIconSaveFileName.Trim() != null && strIconSaveFileName.Trim() != "") { CustomerModel.HeadImg = strIconSaveFileName; } if (CustomerDal.UpdateCustomers(CustomerModel)) { MessageBox.Show(this, "操作成功!"); } else { MessageBox.Show(this, "操作失败!"); } } else { MessageBox.Show(this, "请输入相应店铺名称或电话!"); } } else { return; } }