请大家来看看这段垃圾代码怎么样能美化和优化一下
这段代码就是从数据库取数据,然后显示到页面上,我觉得写法太垃圾了,
大家有什么好的方法,请说下主要点,你们都是怎么处理数据和界面之间那些纠缠的比较紧的代码的。你说分层也行,不过要说具体点。
int wxy_id = (Request.QueryString["wxy_id"] == null) ? 0 : int.Parse(Request.QueryString["wxy_id"].ToString());
DataTable table = db.GetDataTable("select * from View_Safety where SaftyB1ID=" + wxy_id + "");
if (table.Rows.Count > 0)
{
Safety safety = new Safety();
safety.UpdateAQ_SaftyB1_Send_IsRead(wxy_id, Int32.Parse(Session["deptID"].ToString().Trim()), Int32.Parse(Session["accPsnID"].ToString().Trim()), true);
try
{
lbLiuShuiHao.Text = table.Rows[0]["LiuShuiNo"].ToString().Trim();//流水号
if (table.Rows[0]["CheckDepID"].ToString().Trim() == "" || table.Rows[0]["CheckDepID"].ToString().Trim() == "0")
{
lbCheckDept.Text = table.Rows[0]["CheckSort"].ToString().Trim();
}
else
{
lbCheckDept.Text = table.Rows[0]["CheckDeptName"].ToString().Trim();//检查单位
}
lbCheckMan.Text = table.Rows[0]["CheckName"].ToString().Trim();//检查人
lbKHLX.Text = table.Rows[0]["Khlx"].ToString().Trim();//考核类型
lbDownTime.Text = Convert.ToDateTime(table.Rows[0]["CheckDateA"].ToString().Trim()).ToString("yyyy-MM-dd");//检查日期
lbBan.Text = table.Rows[0]["ClassNumber"].ToString().Trim();//班次
lbAuditName.Text = table.Rows[0]["AuditMan"].ToString().Trim();//审核人
//string psnID = table.Rows[0]["AuditMan"].ToString().Trim();//审核人
try
{
lbAuditName.Text = db.GetDataTable("select psnName from Person where psnID='" + lbAuditName.Text + "'").Rows[0][0].ToString().Trim();
}
catch { }
if (table.Rows[0]["AuditDate"].ToString().Trim() != "")
{
lbAuditTime.Text = Convert.ToDateTime(table.Rows[0]["AuditDate"].ToString().Trim()).ToString("yyyy-MM-dd HH:mm:ss");//审核时间
}
lbTroubleDeptName.Text = table.Rows[0]["depName"].ToString().Trim();//隐患单位
lbDutyMan.Text = table.Rows[0]["DutyMan"].ToString().Trim();//隐患责任人
//lbDealDate.Text = table.Rows[0]["XGBan"].ToString().Trim();//限改时间
//if (lbDealDate.Text == "")
//{
// if (table.Rows[0]["DealDate"].ToString().Trim() != "")
// {
// lbDealDate.Text = Convert.ToDateTime(table.Rows[0]["DealDate"].ToString().Trim()).ToString("yyyy-MM-dd HH:mm:ss");//限改时间
// }
//}
if (table.Rows[0]["DealDate"].ToString().Trim() != "")
{
lbDealDate.Text = Convert.ToDateTime(table.Rows[0]["DealDate"].ToString().Trim()).ToString("yyyy-MM-dd HH:mm:ss");//限改时间
}
lbYHaddress.Text = table.Rows[0]["TroubleAddress"].ToString().Trim();//隐患地点
lbLevel.Text = table.Rows[0]["AQLevel"].ToString().Trim();//级别
lbYHSort.Text = table.Rows[0]["Sort"].ToString().Trim() + " - " + table.Rows[0]["SortSub"].ToString().Trim();//隐患类别
lbSendName.Text = table.Rows[0]["SendSHMan"].ToString().Trim();//发送人
if (table.Rows[0]["SendSHDate"].ToString().Trim() != "")
{
lbSendTime.Text = Convert.ToDateTime(table.Rows[0]["SendSHDate"].ToString().Trim()).ToString("yyyy-MM-dd HH:mm:ss");//发送时间
}
lbDealIde.Text = table.Rows[0]["DealIdea"].ToString().Trim();//提出整改意见
lbQuestion.Text = table.Rows[0]["Question"].ToString().Trim();//隐患描述
lbCallBackPerson.Text = table.Rows[0]["CallBackPerson"].ToString().Trim();//复查人
//lbCallBackTime.Text = table.Rows[0]["FCBan"].ToString().Trim();//复查时间
//if (lbCallBackTime.Text == "")
//{
// if (table.Rows[0]["CallBackTime"].ToString().Trim() != "")
// {
// lbCallBackTime.Text = Convert.ToDateTime(table.Rows[0]["CallBackTime"].ToString().Trim()).ToString("yyyy-MM-dd HH:mm:ss");//复查日期
// }
//}
if (table.Rows[0]["CallBackTime"].ToString().Trim() != "")
{
lbCallBackTime.Text = Convert.ToDateTime(table.Rows[0]["CallBackTime"].ToString().Trim()).ToString("yyyy-MM-dd HH:mm:ss");//复查日期
}
lbCallBackResult.Text = table.Rows[0]["CallBackResult"].ToString().Trim();//复查结果
lbRectifyMan.Text = table.Rows[0]["RectifyMan"].ToString().Trim();//整改责任人
//string psnID = table.Rows[0]["RectifyMan"].ToString().Trim();
try
{
lbRectifyMan.Text = db.GetDataTable("select psnName from Person where psnID='" + lbRectifyMan.Text + "'").Rows[0][0].ToString().Trim();
}
catch { }
//lbRectifyDate.Text = table.Rows[0]["ZGBan"].ToString().Trim();//整改时间
//if (lbRectifyDate.Text == "")
//{
// if (table.Rows[0]["RectifyDate"].ToString().Trim() != "")
// {
// lbRectifyDate.Text = Convert.ToDateTime(table.Rows[0]["RectifyDate"].ToString().Trim()).ToString("yyyy-MM-dd HH:mm:ss");//整改完成时间
// }
//}
if (table.Rows[0]["RectifyDate"].ToString().Trim() != "")
{
lbRectifyDate.Text = Convert.ToDateTime(table.Rows[0]["RectifyDate"].ToString().Trim()).ToString("yyyy-MM-dd HH:mm:ss");//整改完成时间
}
lbHazardName.Text = table.Rows[0]["HazardName"].ToString().Trim();
lbKhpfName.Text = table.Rows[0]["KhpfName"].ToString().Trim();
lbRectifyResult.Text = table.Rows[0]["RectifyResult"].ToString().Trim();//整改措施
lbRectifySpc.Text = table.Rows[0]["RectifySpc"].ToString().Trim();
string strState = "";
if (table.Rows[0]["IsZGTH"].ToString().Trim() == "True")
{
lbZGname.Text = "退回说明";
strState = "整改退回";
}
else if (table.Rows[0]["IsSHTH"].ToString().Trim() == "True")
{
lbZGname.Text = "退回说明";
strState = "审核退回";
lbRectifySpc.Text = table.Rows[0]["SHTHNote"].ToString().Trim();
}
else
{
lbZGname.Text = "整改措施";
if (table.Rows[0]["IsSendSH"].ToString().Trim() != "True")
{
strState = "待发送";
}
else if (table.Rows[0]["IsAllowSend"].ToString().Trim() != "True")
{
strState = "待审核";
}
else if (table.Rows[0]["RectifyYesNo"].ToString().Trim() != "True")
{
strState = "待整改";
}
else if (table.Rows[0]["CallBackYesNo"].ToString().Trim() != "True")
{
strState = "待复查";
}
else
{
strState = "隐患闭环";
}
}
lbLCstate.Text = strState;//流程状态
}
catch
{
}
}