做项目的一些常用帮助
如何在html(前台中引用后台的命名空间)
<%@ Import Namespace="LCY.Business.Enums" %>
Namespace = 后台的 using LCY.Business.Enums//命名空间
获取指定值的枚举的 Description 属性方法
public static string GetEnumDescript(this object obj, Type _enumType)
{
if (obj == null)
{
return string.Empty;
}
try
{
DescriptionAttribute dna = null;
FieldInfo fi = _enumType.GetField(Enum.GetName(_enumType, obj));
dna = (DescriptionAttribute)Attribute.GetCustomAttribute(
fi, typeof(DescriptionAttribute));
if (dna != null && string.IsNullOrEmpty(dna.Description) == false)
return dna.Description;
}
catch
{
}
return obj.ToString();
}
调用情况
<%# Eval("state").GetEnumDescript(typeof(CedureEnum.CapitalDeclareState))%>
或者
ltlState.Text = oinfoCapitalDeclare.State.GetEnumDescript(typeof(CedureEnum.CapitalDeclareState));
后台返回给前台图片或者链接标签
List<Model.Work.wfFiles> files = IBLL.Factory.wfFilesCreate().GetModelList("BelongTable='infoCapitalDeclare' and BelongId=" + oinfoCapitalDeclare.Id);
if (files != null && files.Count > 0)
{
files.ForEach(x =>
{
//返回多张图片 点击跳转页面
FileList += "<a target=\"_blank\" href='" + Public.Path_Files + x.FilePath + "'>" + x.FileName + "</a><br/>";
});
}
web控件如何设置是否显示(通过 Visible)
<asp:LinkButton ID="lbtnEdit" runat="server" PostBackUrl='<%# Eval("Id", "/OA/Information/infoCapitalDeclareInfo.aspx?op=edit&Id={0}&action=update") %>' Text='[ 修改 ]' Visible='<%# GetVisible(Convert.ToInt32(Eval("State")))%>'></asp:LinkButton>
RadioButton 控件单选选:设置属性GroupName为相同的值
上传图片的简单方法
public string File(FileUpload filename)
{
// 检查图片后缀
string imageExtension = System.IO.Path.GetExtension(filename.FileName).ToLower();
string extension = ".mp4,.mp3,.av";
if (extension.Contains(imageExtension))
return "上传文件类型错误";
// 检查图片大小
if (filename.PostedFile.ContentLength > (10 * 1024 * 1024))
return "上传文件过大";
try
{
// 重命名图片并上传
string newImgName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + imageExtension;
filename.SaveAs(Server.MapPath(Public.Path_Files) + newImgName);
return "成功," + newImgName + "," + filename.FileName + "," + imageExtension;
}
catch (Exception ex)
{
return "上传失败";
}
}
获取当前前台页面 html标题type=file的图片上传操作
if (Request.Files.Count > 0) { HttpPostedFile file = Request.Files[i];//i 当上传多个文件的时候 这里相当于下标 int index = file.FileName.LastIndexOf("\\"); int length = file.FileName.Length - index - 1; string file_name = file.FileName.Substring(index + 1, length);//获取到当前上传图片的名称
file.SaveAs(this.Server.MapPath(Public.Path_Files + filename));//保存到指定文件夹里面
}
跳转页面
引用命名空间:using Expansion.UI;
this.JavaScript("alert('新增成功');location.href='/Admin/Work/wfPropertyDecoCostSetList.aspx';");