CeramicProject/newyt/Module_data/MaterialInventory_list.aspx.cs

542 lines
21 KiB
C#
Raw Normal View History

2024-05-18 15:28:29 +08:00
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.Collections;
public partial class MaterialInventory_list : System.Web.UI.Page
{
//创建一个共用的物料bll
Maticsoft.BLL.nr_z_wuliao wuliaobll = new Maticsoft.BLL.nr_z_wuliao();
//创建一个物料模板
Maticsoft.Model.nr_z_wuliao wuliaomd = new Maticsoft.Model.nr_z_wuliao();
//创建一个操作记录模板
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();
//创建一个共用的其他入库bll层
Maticsoft.BLL.nr_z_qtrk qtrkbll = new Maticsoft.BLL.nr_z_qtrk();
//创建一个共用的其他入库模板
Maticsoft.Model.nr_z_qtrk qtrk = new Maticsoft.Model.nr_z_qtrk();
//创建一个共用的物料bll层
Maticsoft.BLL.nr_z_qtck qtckbll = new Maticsoft.BLL.nr_z_qtck();
//创建一个共用的物料模板
Maticsoft.Model.nr_z_qtck qtck = new Maticsoft.Model.nr_z_qtck();
int jsid = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["user"] == null)
{
Response.Redirect("../index.aspx");
}
}
Utility.RegisterTypeForAjax(typeof(MaterialInventory_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)
{
bool isyincang = tiaojian.Contains("客户纸库");
Maticsoft.Model.nr_z_yhzh zhanghao = (Maticsoft.Model.nr_z_yhzh)Session["user"];
string htmlcode = "";
string paixuselct = "";
if (isyincang)
{
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_pk", 1);
}
else
{
paixuselct = string.Format("select * from nr_lt_paixu where userid='{0}' and tblname='{1}' and lieming!='kh_bh' and isxianshi={2} order by shuixu ", zhanghao.id, "view_nr_z_pk", 1);
}
DataTable dtselect = DBHlper.Execute(paixuselct).Tables[0];
if (dtselect.Rows.Count > 0)
{
string wherecode = string.Format("select top {0} ", pageitem);
foreach (DataRow dtr in dtselect.Rows)
{
wherecode += dtr["lieming"] + ",";
}
wherecode += "id";
wherecode += string.Format(" from view_nr_z_pk where " + tiaojian + " id not in(select top ({0}*{1}) id from view_nr_z_pk "+" where "+tiaojian+" 1=1 " + paixu + ")" + paixu, pg, pageitem);
DataTable dt_paixu = DBHlper.Execute(wherecode).Tables[0];
if (dt_paixu.Rows.Count == 0)
{
return "<tr><td>&nbsp&nbsp 没有数据</td></tr>";
}
for (int i = 0; i < dt_paixu.Rows.Count; i++)
{
htmlcode += "<tr tag='" + dt_paixu.Rows[i]["id"] + "' >";
htmlcode += " <td style='width:20px'><input type='checkbox' class='xz'/></td>";
htmlcode += "<td><a href='#button' class='button icon edit' onclick='tcpkk(" + dt_paixu.Rows[i]["id"] + ")' >盘库</a> </td>";
for (int j = 0; j < dt_paixu.Columns.Count - 1; j++)
{
htmlcode += "<td><span>" + dt_paixu.Rows[i][j] + "</span></td>";
}
htmlcode += "</tr>";
}
return htmlcode;
}
else
{
string lieselect = string.Format("select * from nr_sys_lieming where tblname='{0}' ORDER BY xh", "view_nr_z_pk");
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_pk", liedr["ywlieming"], liedr["zwlieming"], lieshuixu, 1);
DBHlper.excutecmd(cmdinsert);
}
return "";
}
}
#endregion
#region 便
[Ajax.AjaxMethod]
public int maxpage(int count, string tj)
{
int fanhuizhi = 0;
string cmd = string.Format("select count(*) from view_nr_z_pk " + tj);
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 zhanghao = (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}'", zhanghao.id, "view_nr_z_pk", 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 values('{0}','{1}','{2}','{3}',{4},{5})", zhanghao.id, "nr_z_wuliao", 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_pk", 1);
DataTable dtselect = DBHlper.Execute(paixuselct).Tables[0];
string htmlcode = "<td style='width:20px'><input onclick='selectall()' title='全选' type='checkbox' style='width:20px' id='cbo_selectall'/></td>";
htmlcode += "<td tag='id'>盘库</td>";
foreach (DataRow dr in dtselect.Rows)
{
if ((dr["lieming"]).ToString() == "kh_bh")
{
htmlcode += string.Format("<td class='kh' style='display:none' tag='{0}'>{1}</td>", dr["lieming"], dr["zhongwen"]);
}
else
{
htmlcode += string.Format("<td tag='{0}'>{1}</td>", dr["lieming"], dr["zhongwen"]);
}
}
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_pk' and userid='" + zhanghao.id + "'";
DataTable distable = DBHlper.Execute(displaycmd).Tables[0];
string htmlcode = "";
foreach (DataRow dr in distable.Rows)
{
endid++;
htmlcode += "<tr class='tr_item' id='tr_" + endid + "'><td style='width:30%'>" + endid + "</td><td style='width:30%' tag=" + dr["lieming"] + ">" + dr["zhongwen"] + "</td><td style='width:30%'><input type='checkbox'/></td> </tr>";
}
return htmlcode;
}
#endregion
#region
[Ajax.AjaxMethod]
public int sumitem(string wheretj)
{
string cmd = string.Format("select count(*) from view_nr_z_pk " + wheretj);
int sumcount = DBHlper.getcount(cmd);
return sumcount;
}
#endregion
#region
[Ajax.AjaxMethod]
public string nowdaycount(string option, 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 (option == "")
{
cmd = string.Format("select CONVERT(varchar(12),riqi,111) as 'riqi' from view_nr_z_pk where riqi>='{0}' and riqi<='{1}' ", yuechu, yuemo);
}
else
{
cmd = string.Format("select CONVERT(varchar(12),riqi,111) as 'riqi' from view_nr_z_pk where riqi>='{0}' and riqi<='{1}' and kufang='" + option + "'", yuechu, yuemo);
}
DataTable dt = DBHlper.Execute(cmd).Tables[0];
var biao = "<table class='lbrilitb' id='tbl_yueli'>"
+ "<tr class='lbrilitbtou'><td width='50px' ><span>日期</span><div><span class='cursor' onclick='yl_up()' title='上月'><</span>&nbsp<span id='yl_nowmonth' title='" + selmonth + "月'>" + selmonth + "</span>&nbsp<span class='cursor' onclick='yl_next()' title='下月'>></span></div></td>";
for (var x = 1; x <= days; x++)
{
biao += "<td width='50px'>" + x + "</td>";
}
biao += "</tr><tr style='width:100%;height:37px;cursor:pointer'><td width='50px' id='td_sum' onclick='selectallday()' title='全部'>数量</td>";
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 += "<td width='50px' onclick='selectnowday(this)' tag='" + everday + "'>" + dt.Select("riqi='" + everday + "'").Length + "</td>";
yc = yc.AddDays(1);
}
biao += "</tr></table>";
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");
}
2024-05-21 15:05:24 +08:00
if (!DBHlper.GetPermission(juese, "盘库管理", "nr_z_wuliao", "查看全部"))
2024-05-18 15:28:29 +08:00
{
Response.Redirect("../Common/nopower.htm");
}
2024-05-21 15:05:24 +08:00
if (DBHlper.GetPermission(juese, "盘库管理", "nr_z_wuliao", "导出"))
2024-05-18 15:28:29 +08:00
{
xiazai.Visible = true;
}
2024-05-21 15:05:24 +08:00
if (DBHlper.GetPermission(juese, "盘库管理", "nr_z_wuliao", "配置"))
2024-05-18 15:28:29 +08:00
{
leiset.Visible = true;
}
}
#endregion
#region
[Ajax.AjaxMethod]
public string isquanxian(int uid)
{
2024-05-21 15:05:24 +08:00
if (DBHlper.GetPermission(uid, "盘库管理", "nr_z_wuliao", "查看全部"))
2024-05-18 15:28:29 +08:00
{
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_pk' and isxianshi=1 and userid='" + ((Maticsoft.Model.nr_z_yhzh)Session["user"]).id + "' order by shuixu").Tables[0];
string tj = strwhere.Value;
string selzt = drp_zt.SelectedItem.Value;
foreach (DataRow r in dtcolmnname.Rows)
{
if (r["lieming"].ToString() == "kh_bh")
{
if (selzt == "客户纸库")
{
colmn += r["lieming"].ToString() + ',';
sList.Add(r["zhongwen"].ToString());
}
}
else
{
colmn += r["lieming"].ToString() + ',';
sList.Add(r["zhongwen"].ToString());
}
}
colmn = colmn.TrimEnd(',');
string selectcode = "";
if (selzt == "主料库")
{
selectcode = "select " + colmn + " from view_nr_z_pk where zt='1' and kufang='主料库' ";
}
else if (selzt == "辅料库")
{
selectcode = "select " + colmn + " from view_nr_z_pk where zt='1' and kufang='辅料库' ";
}
else if (selzt == "客户纸库")
{
selectcode = "select " + colmn + " from view_nr_z_pk where zt='1' and kufang='客户纸库' ";
}
else if (selzt == "")
{
selectcode = "select " + colmn + " from view_nr_z_pk where zt='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 = "<td></td>";
bool isyincang = tiaojian.Contains("客户纸库");
string paixuselct = "";
if (isyincang)
{
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_pk", 1);
}
else
{
paixuselct = string.Format("select * from nr_lt_paixu where userid='{0}' and tblname='{1}' and lieming!='kh_bh' and isxianshi={2} order by shuixu ", zhanghao.id, "view_nr_z_pk", 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 += "<td></td>";
}
else
{
datacolmn = dr["lieming"].ToString();
wherecode = "select sum(" + datacolmn + ") ";
wherecode += " from view_nr_z_pk where " + tiaojian;
wherecode += " 1=1 ";
code += "<td class='blue'>" + DBHlper.getfirstcolmn(wherecode) + "</td>";
}
}
code += "<td></td>";
return code;
}
#endregion
#region
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public string pkwlinfo(int id) {
string wlinfo = "";
DataSet ds = DBHlper.Execute("select wlbh,mingcheng,kucun,jine,dj from view_nr_z_pk where id=" + id + "");
if(ds!=null&&ds.Tables [0].Rows .Count >0){
wlinfo += "" + ds.Tables[0].Rows[0]["wlbh"] + "," + "" + ds.Tables[0].Rows[0]["mingcheng"] + "," + "" + ds.Tables[0].Rows[0]["kucun"] + "," + "" + ds.Tables[0].Rows[0]["jine"] + ",";
wlinfo += "" + ds.Tables[0].Rows[0]["dj"];
}
return wlinfo;
}
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public string pkcz(string rc, string wlbh, double sjkc,int id)
{
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
rizhi.riqi = DateTime.Now;
rizhi.yonghuming = user.zhanghao;
string sfcg = "";
if (rc == "r")
{
DataSet ds = DBHlper.Execute("select wlbh,mingcheng,kucun,jine,zhonglei,changdu ,kuandu ,pinpai,danwei ,kufang,kh_bh from view_nr_z_pk where id=" + id + "");
double rkkc = sjkc - Convert.ToDouble(ds.Tables[0].Rows[0]["kucun"].ToString());
double rkje = 0;
if(ds!=null&&ds.Tables [0].Rows.Count >0){
double dj =0;
qtrk.rkbh = DBHlper.getbh("QTRK-", "nr_z_qtrk", "rkbh", 4);
qtrk.rklx = "盘盈入库";
qtrk.riqi = Convert.ToDateTime(DateTime.Now);
qtrk.wlbh = wlbh;
qtrk.wlmc = ds.Tables[0].Rows[0]["mingcheng"].ToString();
qtrk.wlcd = Convert.ToDecimal(ds.Tables[0].Rows[0]["changdu"].ToString());
qtrk.wlkd = Convert.ToDecimal(ds.Tables[0].Rows[0]["kuandu"].ToString());
qtrk.wlpp = ds.Tables[0].Rows[0]["pinpai"].ToString();
qtrk.sl = Convert.ToDecimal(rkkc);
qtrk.dw = ds.Tables[0].Rows[0]["danwei"].ToString();
qtrk.zl = ds.Tables[0].Rows[0]["zhonglei"].ToString();
qtrk.dj =0;
qtrk.je = Convert.ToDecimal(rkje);
qtrk.jsr = user.zhanghao;
qtrk.wz = "";
qtrk.khbh = ds.Tables[0].Rows[0]["kh_bh"].ToString();
qtrk.bz = "";
qtrk.kf = ds.Tables[0].Rows[0]["kufang"].ToString();
qtrk.zt = "已确认";
}
rizhi.leixing = "材料库盘盈入库";
int count=qtrkbll.Add(qtrk);
if(count >0){
DBHlper.excutecmd("update nr_z_qtrk set zt='已确认' where id=" + count + " ");
if (ds.Tables[0].Rows[0]["kufang"].ToString() != "客户纸库")
{
string sql = "update nr_z_wuliao set kucun=kucun+" + rkkc + " where wlbh='" + wlbh + "'";
int counts=DBHlper.excutecmd(sql);
if(counts>0){
rizhi.jilu = user.zhanghao + ",盘盈入库,其它入库的编号为" + qtrk.rkbh+"入库的物料编号是"+wlbh+",库存是"+rkkc+"";
rizhibll.Add(rizhi);
sfcg = "成功!";
}
}
}
}
else {
DataSet ds = DBHlper.Execute("select wlbh,mingcheng,kucun,jine,zhonglei,changdu ,kuandu ,pinpai,danwei ,kufang,kh_bh from view_nr_z_pk where id=" + id + "");
double rkkc = Convert.ToDouble(ds.Tables[0].Rows[0]["kucun"].ToString()) - sjkc;
double rkje =0;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
double dj =0;
qtck.ckdh = DBHlper.getbh("qtck-", "nr_z_qtck", "ckdh", 4);
qtck.cklx = "盘亏出库";
qtck.ckrq = Convert.ToDateTime(DateTime.Now);
qtck.wlbh = wlbh;
qtck.wlmc = ds.Tables[0].Rows[0]["mingcheng"].ToString();
qtck.wlcd = Convert.ToDecimal(ds.Tables[0].Rows[0]["changdu"].ToString());
qtck.wlkd = Convert.ToDecimal(ds.Tables[0].Rows[0]["kuandu"].ToString());
qtck.wlpp = ds.Tables[0].Rows[0]["pinpai"].ToString();
qtck.sl = Convert.ToDecimal(rkkc);
qtck.wldw = ds.Tables[0].Rows[0]["danwei"].ToString();
qtck.jine = Convert.ToDecimal(rkje);
qtck.jsr = user.zhanghao;
qtck.khbh = ds.Tables[0].Rows[0]["kh_bh"].ToString();
qtck.bz = "";
qtck.kf = ds.Tables[0].Rows[0]["kufang"].ToString();
qtck.zt = "已确认";
}
rizhi.leixing = "材料库盘亏出库";
int count = qtckbll.Add(qtck);
if (count > 0)
{
DBHlper.excutecmd("update nr_z_qtck set zt='已确认' where id=" + count + " ");
if (ds.Tables[0].Rows[0]["kufang"].ToString() != "客户纸库")
{
string sql = "update nr_z_wuliao set kucun=kucun-" + rkkc + " where wlbh='" + wlbh + "'";
int counts = DBHlper.excutecmd(sql);
if (counts > 0)
{
rizhi.jilu = user.zhanghao + ",盘亏出库,其它出库的编号为" + qtck.ckdh + "出库的物料编号是" + wlbh + ",库存是" + rkkc + "";
rizhibll.Add(rizhi);
sfcg = "成功!";
}
}
}
}
return sfcg;
}
#endregion
}