工作系统之脚本生成 求改进
刚开始写程序。。所以写出这种很和谐的代码来。。希望大家能帮忙改进一下 或者给个思路
/// <summary>
/// 日报处理
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public string DailyPaper2(string data)
{
//20120531
string a = "";
a = data.Substring(6, 2);
string s = "select ttt.业务类型,ttt.合同号,ttt.客户名称,ttt.代理,ttt.销售经理,ttt.电信帐号,";
string s2 = "";
string s3 = " from utdatabase.dbo.vwallcustomer as ttt ";
string s4 = "";
string s5 = "where ttt.电信帐号 is not null and ttt.客户状态='正常' and (";
string s6 = ""; string s7 = " )order by "; string s8 = "";
//垃圾代码不得不写。。
#region
for (int i = 0; i < Convert.ToInt32(a); i++)
{
if (i == Convert.ToInt32(a) - 1)
{
s2 += "isnull(t" + i + ".话费,0) as [201205" + (i + 1) + "]";
break;
}
if (i < 9)
{
string c = "0" + (i + 1);
s2 += "isnull(t" + i + ".话费,0) as [201205" + c + "],";
}
else
{
s2 += "isnull(t" + i + ".话费,0) as [201205" + (i + 1) + "],";
}
}
for (int i = 0; i < Convert.ToInt32(a); i++)
{
if (i < 9)
{
string c = "0" + (i + 1);
s4 += " left outer join utstatdata.dbo.dayamount201205" + c + " as t" + i + " on t" + i + ".电信帐号=ttt.电信帐号 ";
}
else
{
s4 += " left outer join utstatdata.dbo.dayamount201205" + (i + 1) + " as t" + i + " on t" + i + ".电信帐号=ttt.电信帐号 ";
}
}
for (int i = 0; i < Convert.ToInt32(a); i++)
{
if (i == 0)
{
s6 = "t0.话费<>0 or ";
}
else
{
if (i == Convert.ToInt32(a) - 1)
{
s6 += "t" + i + ".话费<>0 ";
break;
}
s6 += "t" + i + ".话费<>0 or ";
}
}
int q = Convert.ToInt32(a);
for (int i = 0; i < Convert.ToInt32(a); i++)
{
if (q == 1)
{
s8 += "t0.话费 desc";
}
else
{
q = q - 1;
s8 += "t" + q + ".话费 desc,";
}
}
return s + s2 + s3 + s4 + s5 + s6 + s7 + s8;
#endregion
}
调用
jiaoben j = new jiaoben();
string sql = "";
sql = j.jiequ(textBox1.Text);
DataTable table = db.Getdatable(sql);
dataGridView2.DataSource = table;
------解决方案--------------------
空行忒多;注释忒少;SQL语句ttt这种少用,怎么也得有点含义;为什么不用StringBuilder呢。水平太次,给不了你深入的建议,见谅。此外,楼主结贴率也忒低了。。。