using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Productin_browse : System.Web.UI.Page
{
Maticsoft.Model.nr_z_cprk cprkmodel = new Maticsoft.Model.nr_z_cprk();
Maticsoft.BLL.nr_z_cprk cprkbll = new Maticsoft.BLL.nr_z_cprk();
//创建一个操作记录模板
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();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["user"] == null)
{
Response.Redirect("../index.aspx");
}
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
if (Request.QueryString["uid"] != null && Request.QueryString["uid"] != "")
{
id.Value = Request.QueryString["uid"].ToString();
}
initdata(Convert.ToInt32(id.Value));
pdquanxian(user.juese);
}
}
#region 获取真正数据值
private void initdata(int did)
{
cprkmodel = cprkbll.GetModel(did);
ckdh.Text = cprkmodel.rkbh;
riqi.Text = cprkmodel.riqi.ToString("yyyy-MM-dd");
scdh.Text = cprkmodel.scdh;
//khming.Text = cpckmodel.;
//cpbh.Text = cpckmodel.cpmc;
cpmc.Text = cprkmodel.cpmc;
//danjia.Text = cpckmodel..ToString();
//guige.Text = cpckmodel.guige.ToString();
zzshuliang.Text = cprkmodel.zzsl.ToString();
lingtou.Text = cprkmodel.lt.ToString();
shuliang.Text = cprkmodel.sl.ToString();
//danwei.Text = cpckmodel.danwei;
//lxr.Text = cpckmodel.lxr;
//zongjine.Text = cpckmodel.zje.ToString();
//lxdh.Text = cpckmodel.lxdh;
jingshouren.Text = cprkmodel.jsr;
//shr.Text = cpckmodel.shr;
//dizhi.Text = cpckmodel.shdizhi;
//txt_beizhu.Text = cpckmodel.beizhu;
zhuangtai.Text = cprkmodel.zt;
}
#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, "成品入库", "nr_z_cprk", "查看全部") == false && DBHlper.GetPermission(juese, "成品入库", "nr_z_cprk", "查看个人") == false)
{
Response.Redirect("../Common/nopower.htm");
}
if (DBHlper.GetPermission(juese, "成品入库", "nr_z_cprk", "编辑个人") && jingshouren.Text == user.zhanghao)
{
bt_tj.Visible = true;
}
if (DBHlper.GetPermission(juese, "成品入库", "nr_z_cprk", "编辑全部"))
{
bt_tj.Visible = true;
}
if (DBHlper.GetPermission(juese, "成品入库", "nr_z_cprk", "删除个人") && jingshouren.Text == user.zhanghao)
{
shanchu.Visible = true;
}
if (DBHlper.GetPermission(juese, "成品入库", "nr_z_cprk", "删除全部"))
{
shanchu.Visible = true;
}
if (DBHlper.GetPermission(juese, "成品入库", "nr_z_cprk", "入库确认"))
{
rkqr.Visible = true;
}
if (DBHlper.GetPermission(juese, "成品入库", "nr_z_cprk", "入库冲红"))
{
ckch.Visible = true;
}
if (DBHlper.GetPermission(juese, "成品入库", "nr_z_cprk", "添加"))
{
bt_add.Visible = true;
}
if (zhuangtai.Text == "已入库")
{
rkqr.Enabled = false;
rkqr.BackColor = System.Drawing.Color.Gray;
shanchu.Enabled = false;
shanchu.BackColor = System.Drawing.Color.Gray;
bt_tj.Enabled = false;
bt_tj.BackColor = System.Drawing.Color.Gray;
}
if (zhuangtai.Text == "待确认")
{
ckch.Enabled = false;
ckch.BackColor = System.Drawing.Color.Gray;
}
if (DBHlper.GetPermission(juese, "成品入库", "nr_z_cprk", "打印"))
{
dayin.Visible = true;
}
}
#endregion
protected void bt_tj_Click(object sender, EventArgs e)
{
Response.Redirect("Productin_Form.aspx?uid=" + id.Value);
}
protected void Button1_Click(object sender, EventArgs e)
{
if (cprkbll.Delete(Convert.ToInt32(id.Value)))
{
//给日志模板赋值
rizhi.riqi = DateTime.Now;
rizhi.leixing = "成品入库";
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + "删除了成品入库,入库单号为:" + cpbh.Text.Trim();
rizhi.yonghuming = zh.zhanghao.ToString();
rizhibll.Add(rizhi);
Response.Redirect("Productin_list.aspx", false);
}
else
{
Response.Write("");
}
}
protected void btnchonghong_Click(object sender, EventArgs e)
{
DataTable dt = DBHlper.Execute(string.Format("select * from nr_z_cpkc where scdh='{0}' and xmmc='{1}' and khmc='{2}'", scdh.Text, cpbh.Text, khming.Text)).Tables[0];
double sl = Convert.ToDouble(dt.Rows[0]["sl"]);
double nowsl = Convert.ToDouble(shuliang.Text);
int gxcount = DBHlper.excutecmd("update nr_z_cpkc set sl=" + (sl + nowsl) + " where id=" + dt.Rows[0]["id"]);
if (gxcount > 0)
{
DBHlper.excutecmd("update nr_z_cprk set zt='待确认' where id=" + id.Value);
}
else
{
Response.Write("");
}
//给日志模板赋值
rizhi.riqi = DateTime.Now;
rizhi.leixing = "成品入库";
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + "执行了入库冲红,入库单号为:" + ckdh.Text.Trim();
rizhi.yonghuming = zh.zhanghao.ToString();
rizhibll.Add(rizhi);
Response.Redirect("Productin_browse.aspx?uid=" + id.Value);
}
protected void btn_chuku_Click(object sender, EventArgs e)
{
//var sql = string.Format("select * from view_nr_z_cpkc where scdh='{0}' and xmmc='{1}' and khmc='{2}'", scdh.Text, cpbh.Text, khming.Text);
var sql = string.Format("select * from view_nr_z_cpkc where cpbh='{0}'", cpbh.Text);
var result = DBHlper.Execute(sql);
DataTable dt = result.Tables[0];
if (dt.Rows.Count == 0)
{
Response.Write("");
return;
}
else
{
double sl = Convert.ToDouble(dt.Rows[0]["sl"]);
double nowsl = Convert.ToDouble(shuliang.Text);
if (sl < nowsl)
{
Response.Write("");
return;
}
else
{
DBHlper.excutecmd("update nr_z_cpkc set sl=" + (sl - nowsl) + " where id=" + dt.Rows[0]["id"]);
DBHlper.excutecmd("update nr_z_cprk set zt='已入库' where id=" + id.Value);
rizhi.riqi = DateTime.Now;
rizhi.leixing = "成品入库";
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + "执行了成品入库,成品入库号为:" + ckdh.Text.Trim();
rizhi.yonghuming = zh.zhanghao.ToString();
rizhibll.Add(rizhi);
Response.Redirect("Productin_browse.aspx?uid=" + id.Value);
}
}
}
}