62,075
社区成员
发帖
与我相关
我的任务
分享
try
{
if (tbmonth.Text.ToString().Trim() == "本月")
{
tbmonth.Text = "请不要用‘本月’做为月报表名称";
}
else
{
string kaohefangshi = this.DropDownList1.Text.Trim();
string month = tbmonth.Text.ToString().Trim();
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conn2"]);
conn.Open();
//奖扣分记录修改为报表所在月。
string sql1 = "update rjb_detail set month='" + month + "' where month='本月'";
SqlCommand cmd1 = new SqlCommand(sql1, conn);
cmd1.ExecuteNonQuery();
//更新月报表
//--首先判断记录为‘本月’的报表的月报是月、季度、还是年。根据情况为每个科室增加相应的记录
string sqlby="select kaohefangshi from month where month='本月'";
SqlCommand cmdsqlby=new SqlCommand(sqlby,conn);
SqlDataReader reader=cmdsqlby.ExecuteScalar();
if(reader.Read())
{
string khfs=reader["kaohefangshi"].ToString().Trim();
}
reader.Close();
if(khfs=="12")//考核方式=12表示为这是一个季度报,需要更新所有考核方式=‘1’的报表
{
string sqlks="select distinct(month) as month from month where kaohefangshi='1'";//查询考核方式为月的所有月份列表,然后根据月份列表批量增加相应的记录
SqlCommand cmdsqlks=new SqlCommand(sqlks,conn);
SqlDataReader reader1=cmdsqlks.ExecuteReader();
while(reader.Read())//从读出的月份列表中依次选择相应的月,插入输入季度考核的月的数据。
{
string intsertxjl="insert into month(khdx,khdxfx,khdxfxxh,khnr,fz,jf,kf,khdw,jcfz,mkh,qkh,ykh,kaohefangshi,month) select khdx,khdxfx,khdxfxxh,khnr,fz,jf,kf,khdw,jcfz,mkh,qkh,ykh,kaohefangshi,'"+reader1["month"].ToString().Trim()+"' where mkh='0' and qkh='1' and month='本月'";
SqlCommand cmdintsertxjl=new SqlCommand(intsertxjl,conn);
cmdintsertxjl.ExecuteNonQuery();
}
//更新所有考核方式=1的月份。将考核方式修改为12,表示季度增加的分数已经分配给相应的月
string sql12="update month set kaohefangshi='12' where kaohefangshi='1'";
SqlCommand cmdsql12=new SqlCommand(sql12,conn);
cmdsql12.ExecuteNonQuery();
}
else if(khfs=="123")//考核方式表示这是一个年报。需要更新所有的khfs<>"123"的记录
{
string sqlks="select distinct(month) as month from month where kaohefangshi<>'123'";
SqlCommand cmdsqlks=new SqlCommand(sqlks,conn);
SqlDataReader reader1=cmdsqlks.ExecuteReader();
while(reader.Read())//从读出的月份列表中依次选择相应的月,插入输入季度考核的月的数据。
{
string intsertxjl="insert into month(khdx,khdxfx,khdxfxxh,khnr,fz,jf,kf,khdw,jcfz,mkh,qkh,ykh,kaohefangshi,month) select khdx,khdxfx,khdxfxxh,khnr,fz,jf,kf,khdw,jcfz,mkh,qkh,ykh,kaohefangshi,'"+reader1["month"].ToString().Trim()+"' where mkh='0' and ykh='1' and month='本月'";
SqlCommand cmdintsertxjl=new SqlCommand(intsertxjl,conn);
cmdintsertxjl.ExecuteNonQuery();
}
//更新所有考核方式=1的月份。将考核方式修改为12,表示季度增加的分数已经分配给相应的月
string sql12="update month set kaohefangshi='123' where kaohefangshi<>'123'";
SqlCommand cmdsql12=new SqlCommand(sql12,conn);
cmdsql12.ExecuteNonQuery();
}
//--其次将本月设置月报当月的month修改为录入的月份
string sql = "update month set month='" + month + "' where month='本月'";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
//插入新月报
string sqladd = "insert into month(khdx,khdxfx,khdxfxxh,khnr,fz,jf,kf,khdw,jcfz,mkh,qkh,ykh) select khdx,khdxfx,khdxfxxh,khnr,fz,jf,kf,khdw,fz,month,quarte,year from kaohedetail where " + kaohefangshi + "='1'";
SqlCommand cmdsqladd = new SqlCommand(sqladd, conn);
cmdsqladd.ExecuteNonQuery();
//--设置考核方式
if(kaohefangshi.ToString().Trim()=="1")
{
string sqlkhfs = "update month set kaohefangshi='1' where month='本月'";
}
else if (kaohefangshi.ToString().Trim() = "2")
{
string sqlkhfs = "update month set kaohefangshi='12' where month='本月'";
}
else if (kaohefangshi.ToString().Trim() = "3")
{
string sqlkhfs="update month set kaohefangshi='123' where month='本月'"
}
SqlCommand cmdsqlkhfs=new SqlCommand(cmdsqlkhfs,conn);
cmdsqlkhfs.ExecuteNonQuery();//到此新月报已经插入完毕。
conn.Close();
Response.Write("<script language=javascript>alert('操作成功');</script");
}
}
catch
{
Response.Write("<script language=javascript>alert('出现严重错误,请通知开发人员');</script");
}