using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ajax;
using System.Data;
using System.IO;
using System.Data.OleDb;
using System.Collections;
using System.Text;
public partial class Schedule_list : CommonPage
{
Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi();
//创建一个操作记录bll
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
int jsid = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["user"] == null)
{
Response.Redirect("../index.aspx");
}
if (Request.QueryString["sczt"] != null && Request.QueryString["sczt"] != "")
{
drp_zt.Text = Request.QueryString["sczt"].ToString();
}
}
Utility.RegisterTypeForAjax(typeof(Schedule_list));
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
hiddenid.Value = user.juese.ToString();
Hiddenname.Value = user.zhanghao;
jsid = user.juese;
pdquanxian(jsid);
}
#region 数据加载输出
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public string page_change(int pg, int pageitem, string paixu, string tiaojian)
{
Maticsoft.Model.nr_z_yhzh zhanghao = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string htmlcode = "";
string isexits = string.Format("select count(*) from nr_lt_paixu where userid='{0}' and tblname='{1}'", zhanghao.id, "view_nr_z_scjd");
int exitscount = DBHlper.getcount(isexits);
if (exitscount > 0)
{
string paixuselct = string.Format("select * from nr_lt_paixu where userid='{0}' and tblname='{1}' and isxianshi={2} order by shuixu ", zhanghao.id, "view_nr_z_scjd", 1);
DataTable dtselect = DBHlper.Execute(paixuselct).Tables[0];
string wherecode = string.Format("select top {0} ", pageitem);
foreach (DataRow dtr in dtselect.Rows)
{
wherecode += dtr["lieming"] + ",";
}
wherecode += "id";
if (DBHlper.GetPermission(zhanghao.juese, "生产进度", "view_nr_z_scjd", "查看全部"))
{
wherecode += string.Format(" from view_nr_z_scjd where " + tiaojian + " id not in(select top ({0}*{1}) id from view_nr_z_scjd " + " where " + tiaojian + " 1=1 " + paixu + ")" + paixu, pg, pageitem);
}
DataTable dt_paixu = DBHlper.Execute(wherecode).Tables[0];
if (dt_paixu.Rows.Count == 0)
{
return "
   没有数据 |
";
}
for (int i = 0; i < dt_paixu.Rows.Count; i++)
{
htmlcode += "";
htmlcode += " | ";
for (int j = 0; j < dt_paixu.Columns.Count - 1; j++)
{
htmlcode += "" + dt_paixu.Rows[i][j] + " | ";
}
DataSet gjds = DBHlper.Execute("select * from view_bianma where zhonglei='工序项目' and zt='1'");
if (gjds != null & gjds.Tables[0].Rows.Count > 0)
{
/*-----制模工序时候获取登记信息------*/
//需产总数量
string xcsl = DBHlper.getfirstcolmn("select isnull(sum(xcmj),0) from nr_z_mjzld where scdbh='" + dt_paixu.Rows[i]["scbh"] + "' and xmid='" + dt_paixu.Rows[i]["id"] + "' and pm='" + dt_paixu.Rows[i]["cpmc"] + "'");
//已登记总数量
string djzsl = DBHlper.getfirstcolmn("select isnull(SUM(djsl),0) from nr_z_scdj_djjl where scxmid='" + dt_paixu.Rows[i]["id"] + "'and djgx='制模'");
//已下发总数量
string yxfzsl = DBHlper.getfirstcolmn("select isnull(SUM(xfsl),0) from nr_z_scdj_xf where scxmid='" + dt_paixu.Rows[i]["id"] + "' and dqgx='制模' and xfgx=(select top 1 xfgx from nr_z_scdj_xf where dqgx='制模')");
//已报废总数量
string ybfzsl = DBHlper.getfirstcolmn("select isnull(SUM(bfsl),0) from nr_z_scdj_djjl where scxmid='" + dt_paixu.Rows[i]["id"] + "' and djgx='制模'");
//待登记数量
int ddjzsl = Convert.ToInt32(xcsl) - Convert.ToInt32(djzsl) - Convert.ToInt32(ybfzsl);
//待下发数量
int dxfzsl = Convert.ToInt32(djzsl) - Convert.ToInt32(yxfzsl);
//滞留总数量
int zlzsl = ddjzsl + dxfzsl;
if (Convert.ToInt32(ybfzsl) > 10)
{
htmlcode += "- 需产:" + xcsl + ";
- 滞留:" + zlzsl + ";
- 下发:" + yxfzsl + ";
- 报废:" + ybfzsl + ";
| ";
}
else if (zlzsl > 0)
{
htmlcode += "- 需产:" + xcsl + ";
- 滞留:" + zlzsl + ";
- 下发:" + yxfzsl + ";
- 报废:" + ybfzsl + ";
| ";
}
else if (Convert.ToInt32(xcsl) > 0 && zlzsl <= 0)
{
htmlcode += "- 需产:" + xcsl + ";
- 滞留:" + zlzsl + ";
- 下发:" + yxfzsl + ";
- 报废:" + ybfzsl + ";
| ";
}
else
{
htmlcode += "- 需产:" + xcsl + ";
- 滞留:" + zlzsl + ";
- 下发:" + yxfzsl + ";
- 报废:" + ybfzsl + ";
| ";
}
/*-----正常工序时候获取登记信息------*/
foreach (DataRow dr in gjds.Tables[0].Rows)
{
/*-----正常工序时候获取登记信息------*/
//需产总数量
xcsl = DBHlper.getfirstcolmn("select isnull(SUM(xfsl),0) from nr_z_scdj_xf where scxmid='" + dt_paixu.Rows[i]["id"] + "' and xfgx='" + dr["mingcheng"] + "'");
//已登记总数量
djzsl = DBHlper.getfirstcolmn("select isnull(SUM(djsl),0) from nr_z_scdj_djjl where scxmid='" + dt_paixu.Rows[i]["id"] + "'and djgx='" + dr["mingcheng"] + "'");
//已下发总数量
yxfzsl = DBHlper.getfirstcolmn("select isnull(SUM(xfsl),0) from nr_z_scdj_xf where scxmid='" + dt_paixu.Rows[i]["id"] + "' and dqgx='" + dr["mingcheng"] + "' and xfgx=(select top 1 xfgx from nr_z_scdj_xf where dqgx='" + dr["mingcheng"] + "')");
//已报废总数量
ybfzsl = DBHlper.getfirstcolmn("select isnull(SUM(bfsl),0) from nr_z_scdj_djjl where scxmid='" + dt_paixu.Rows[i]["id"] + "' and djgx='" + dr["mingcheng"] + "'");
//待登记数量
ddjzsl = Convert.ToInt32(xcsl) - Convert.ToInt32(djzsl) - Convert.ToInt32(ybfzsl);
//待下发数量
dxfzsl = Convert.ToInt32(djzsl) - Convert.ToInt32(yxfzsl);
//滞留总数量
zlzsl = ddjzsl + dxfzsl;
if (Convert.ToInt32(ybfzsl) > 10)
{
htmlcode += "- 需产:" + xcsl + ";
- 滞留:" + zlzsl + ";
- 下发:" + yxfzsl + ";
- 报废:" + ybfzsl + ";
| ";
}
else if (zlzsl > 0)
{
htmlcode += "- 需产:" + xcsl + ";
- 滞留:" + zlzsl + ";
- 下发:" + yxfzsl + ";
- 报废:" + ybfzsl + ";
| ";
}
else if (Convert.ToInt32(xcsl) > 0 && zlzsl <= 0)
{
htmlcode += "- 需产:" + xcsl + ";
- 滞留:" + zlzsl + ";
- 下发:" + yxfzsl + ";
- 报废:" + ybfzsl + ";
| ";
}
else
{
//htmlcode += "- 需产:" + xcsl + ";
- 滞留:" + zlzsl + ";
- 下发:" + yxfzsl + ";
- 报废:" + ybfzsl + ";
| ";
htmlcode += "等待交接... | ";
}
}
}
htmlcode += "
";
}
return htmlcode;
}
else
{
string lieselect = string.Format("select * from nr_sys_lieming where tblname='{0}' ORDER BY xh", "view_nr_z_scjd");
DataTable liedt = DBHlper.Execute(lieselect).Tables[0];
int lieshuixu = 0;
foreach (DataRow liedr in liedt.Rows)
{
lieshuixu++;
string cmdinsert = string.Format("insert into nr_lt_paixu values('{0}','{1}','{2}','{3}',{4},{5})", zhanghao.id, "view_nr_z_scjd", liedr["ywlieming"], liedr["zwlieming"], lieshuixu, 1);
DBHlper.excutecmd(cmdinsert);
}
return "";
}
}
#endregion
#region 传入条数返回页数以便前台调用
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public int maxpage(int count, string tj)
{
int fanhuizhi = 0;
string cmd = string.Format("select count(*) from view_nr_z_scjd " + tj);
Maticsoft.Model.nr_z_yhzh yhzh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
int sumcount = DBHlper.getcount(cmd);
if (sumcount > count)
{
fanhuizhi = sumcount / count;
}
return fanhuizhi;
}
#endregion
#region 数据排序
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public void itempaixu(string code)
{
Maticsoft.Model.nr_z_yhzh yhzh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string[] pxzu = code.Split(';');
string[] codezu = new string[4];
foreach (string px in pxzu)
{
codezu = px.Split('/');
string cmdexits = string.Format("select id from nr_lt_paixu where userid='{0}' and tblname='{1}' and lieming='{2}'", yhzh.id, "view_nr_z_scjd", codezu[2]);
DataTable paixutable = DBHlper.Execute(cmdexits).Tables[0];
if (paixutable.Rows.Count > 0)
{
int idfanhui = Convert.ToInt32(paixutable.Rows[0][0]);
string updatepaixu = string.Format("update nr_lt_paixu set shuixu={0},isxianshi={1} where id={2}", codezu[0], codezu[3], idfanhui);
DBHlper.excutecmd(updatepaixu);
}
else
{
string paixuinsert = string.Format("insert into nr_paixu (userid,tblname,lieming,zhongwen,shuixu,isxianshi) values('{0}','{1}','{2}','{3}',{4},{5})", yhzh.id, "view_nr_z_scjd", codezu[2], codezu[1], codezu[0], codezu[3]);
DBHlper.excutecmd(paixuinsert);
}
}
}
#endregion
#region 列头排序
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public string paixu()
{
Maticsoft.Model.nr_z_yhzh zhanghao = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string paixuselct = string.Format("select * from nr_lt_paixu where userid='{0}' and tblname='{1}' and isxianshi={2} order by shuixu ", zhanghao.id, "view_nr_z_scjd", 1);
DataTable dtselect = DBHlper.Execute(paixuselct).Tables[0];
string htmlcode = " | ";
foreach (DataRow dr in dtselect.Rows)
{
htmlcode += string.Format("{1} | ", dr["lieming"], dr["zhongwen"]);
}
DataSet gjds = DBHlper.Execute("select * from view_bianma where zhonglei='工序项目' and zt='1'");
if (gjds != null & gjds.Tables[0].Rows.Count > 0)
{
htmlcode += string.Format("{0} | ", "制模");
foreach (DataRow dr in gjds.Tables[0].Rows)
{
htmlcode += string.Format("{0} | ", dr["mingcheng"]);
}
}
return htmlcode;
}
#endregion
#region 获取隐藏的列
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public string yincanglie(int endid)
{
Maticsoft.Model.nr_z_yhzh zhanghao = (Maticsoft.Model.nr_z_yhzh)Session["user"];
endid = endid - 1;
string displaycmd = "select * from nr_lt_paixu where isxianshi=0 and tblname='view_nr_z_scjd' and userid='" + zhanghao.id + "'";
DataTable distable = DBHlper.Execute(displaycmd).Tables[0];
string htmlcode = "";
foreach (DataRow dr in distable.Rows)
{
endid++;
htmlcode += "" + endid + " | " + dr["zhongwen"] + " | |
";
}
return htmlcode;
}
#endregion
#region 查询数据总数
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public int sumitem(string wheretj)
{
string selectcmd = "select count(*) from view_nr_z_scjd " + wheretj;
Maticsoft.Model.nr_z_yhzh yhzh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
int sumcount = DBHlper.getcount(selectcmd);
return sumcount;
}
#endregion
#region 日期查询
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public string nowdaycount(string zt, int selmonth)
{
DateTime nowdt = DateTime.Now;
int days = DateTime.DaysInMonth(nowdt.Year, selmonth);
string yuechu = nowdt.Year + "-" + selmonth + "-" + "1";
string yuemo = Convert.ToDateTime(nowdt.Year + "-" + selmonth + "-" + days).AddDays(1).ToString("yyyy-MM-dd");
DateTime yc = Convert.ToDateTime(yuechu);
string cmd = "";
if (zt == "")
{
cmd = string.Format("select CONVERT(varchar(12),riqi,111) as 'riqi' from view_nr_z_scjd where riqi>='{0}' and riqi<='{1}' ", yuechu, yuemo);
}
else
{
cmd = string.Format("select CONVERT(varchar(12),riqi,111) as 'riqi' from view_nr_z_scjd where riqi>='{0}' and riqi<='{1}' and zt='{2}' ", yuechu, yuemo, zt);
}
Maticsoft.Model.nr_z_yhzh yhzh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
DataTable dt = DBHlper.Execute(cmd).Tables[0];
var biao = ""
+ "日期 < " + selmonth + " > | ";
for (var x = 1; x <= days; x++)
{
biao += "" + x + " | ";
}
biao += "
数量 | ";
for (var x = 1; x <= days; x++)
{
string str = yc.ToShortDateString();
int lenth = dt.Select("riqi='" + yc.ToShortDateString() + "'").Length;
string everday = yc.Year.ToString();
if (yc.Month < 10)
{
everday += "/0" + yc.Month;
}
else
{
everday += "/" + yc.Month;
}
if (yc.Day < 10)
{
everday += "/0" + yc.Day;
}
else
{
everday += "/" + yc.Day;
}
biao += "" + dt.Select("riqi='" + everday + "'").Length + " | ";
yc = yc.AddDays(1);
}
biao += "
";
return biao;
}
#endregion
#region 敏感权限查看
void pdquanxian(int juese)
{
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
if (DBHlper.getzt(user.id) != 1)
{
Response.Redirect("../index.aspx");
}
if (!DBHlper.GetPermission(juese, "生产进度", "view_nr_z_scjd", "查看全部") && !DBHlper.GetPermission(juese, "生产进度", "view_nr_z_scjd", "查看个人"))
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
#region 判断查看权限
[Ajax.AjaxMethod]
public string isquanxian(int uid)
{
if (DBHlper.GetPermission(uid, "生产进度", "view_nr_z_scjd", "查看全部"))
{
return "1";
}
else
{
return "";
}
}
#endregion
#region 下载方法
public void DownLoad(object o, EventArgs e)
{
Maticsoft.Model.nr_z_yhzh zhanghao = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string selectid = this.selectid.Value;
string colmn = "";
ArrayList sList = new ArrayList();
DataTable dtcolmnname = DBHlper.Execute("select lieming,zhongwen from nr_lt_paixu where tblname='view_nr_z_scjd' and userid='" + ((Maticsoft.Model.nr_z_yhzh)Session["user"]).id + "' order by shuixu").Tables[0];
string tj = strwhere.Value;
foreach (DataRow r in dtcolmnname.Rows)
{
colmn += r["lieming"].ToString() + ',';
sList.Add(r["zhongwen"].ToString());
}
colmn = colmn.TrimEnd(',');
string selectcode = "";
if (drp_zt.SelectedItem.Value != "")
{
selectcode = "select " + colmn + " from view_nr_z_scjd where zt='" + drp_zt.Text + "'";
}
else
{
selectcode = "select " + colmn + " from view_nr_z_scjd where 1=1 ";
}
if (tj != "")
{
selectcode += tj.Replace("where", "and");
}
if (selectid != "")
{
selectcode += " and id in(" + selectid.TrimEnd(',') + ")";
}
DataTable dt = DBHlper.Execute(selectcode + " order by id desc").Tables[0];
DBHlper.ExportByWeb(dt, "生产单" + DateTime.Now, sList);
}
#endregion
#region 汇总
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public string gethuizong(string tiaojian, string[] hzlie)
{
Maticsoft.Model.nr_z_yhzh zhanghao = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string code = " | ";
string paixuselct = string.Format("select * from nr_lt_paixu where userid='{0}' and tblname='{1}' and isxianshi={2} order by shuixu ", zhanghao.id, "view_nr_z_scjd", 1);
DataTable dtselect = DBHlper.Execute(paixuselct).Tables[0];
string datacolmn = "";
string wherecode = "";
int exits = 0;
foreach (DataRow dr in dtselect.Rows)
{
exits = 0;
foreach (string lie in hzlie)
{
if (dr["zhongwen"].ToString() == lie)
{
exits++;
}
}
if (exits == 0)
{
code += " | ";
}
else
{
datacolmn = dr["lieming"].ToString();
wherecode = "select sum(" + datacolmn + ") ";
if (DBHlper.GetPermission(zhanghao.juese, "生产进度", "view_nr_z_scjd", "查看全部"))
{
wherecode += " from view_nr_z_scjd where " + tiaojian;
}
else if (DBHlper.GetPermission(zhanghao.juese, "生产进度", "view_nr_z_scjd", "查看个人"))
{
wherecode += " from view_nr_z_scjd where yewuyuan='" + zhanghao.zhanghao + "' and " + tiaojian;
}
wherecode += " 1=1 ";
code += "" + DBHlper.getfirstcolmn(wherecode) + " | ";
}
}
return code;
}
#endregion
}