CeramicProject/newyt/Module_data/Purchase_Form.aspx.cs

333 lines
16 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Ajax;
public partial class Purchase_Form : CommonPage
{
public string fanhuicode="";
//创建一个共用的编码bll层
Maticsoft.BLL.nr_sys_bianma bm = new Maticsoft.BLL.nr_sys_bianma();
//创建一个共用的类型BLL层
Maticsoft.BLL.nr_sys_leixing bmlx = new Maticsoft.BLL.nr_sys_leixing();
//创建一个共用的客户bll层
Maticsoft.BLL.nr_z_caigoudan cgdbll = new Maticsoft.BLL.nr_z_caigoudan();
//创建一个操作记录bll
Maticsoft.BLL.nr_sys_rizhi rizhibll = new Maticsoft.BLL.nr_sys_rizhi();
//创建一个共用的客户模板
Maticsoft.Model.nr_z_caigoudan cgdmodel = new Maticsoft.Model.nr_z_caigoudan();
//创建一个操作记录模板
Maticsoft.Model.nr_sys_rizhi rizhi = new Maticsoft.Model.nr_sys_rizhi();
//创建采购单管理详细模版
Maticsoft.Model.nr_z_caigoudan_xm cgddetail = new Maticsoft.Model.nr_z_caigoudan_xm();
Maticsoft.BLL.nr_z_caigoudan_xm cgddetailbll = new Maticsoft.BLL.nr_z_caigoudan_xm();
public string detailcode = "";
protected void Page_Load(object sender, EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(Purchase_Form));
if (!IsPostBack)
{
if (Session["user"] == null)
{
Response.Redirect("../index.aspx");
}
//获取角色权限
Maticsoft.Model.nr_z_yhzh user = (Maticsoft.Model.nr_z_yhzh)(Session["user"]);
pdquanxian(user.juese);
txt_caigouyuan.Text = user.zhanghao;
txt_xdriqi.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
if (Request.QueryString["uid"] != null && Request.QueryString["uid"].ToString().Length > 0)
{
string uid = Request.QueryString["uid"].ToString();
id.Value = uid;
initdata(uid);
pdquanxianbj(user.juese);
binddatabycgd(uid);
}
else
{
if (Request.QueryString["fid"] != null && Request.QueryString["fid"].ToString().Length > 0)
{
string fid = Request.QueryString["fid"].ToString();
initdata(fid);
binddatabycgd(fid);
}
pdquanxian(user.juese);
if (Request["id"] != null)
{
binddatebysgd();
}
}
}
}
#region
private void binddatabycgd(string uid)
{
DataTable dtcgddetail = DBHlper.Execute("select * from view_nr_z_caigoudan_xm where cgdid=" + uid).Tables[0];
int hcount = 0;
for (int i = 0; i <= dtcgddetail.Rows.Count - 1; i++)
{
hcount++;
detailcode += ("<tr id='" + hcount + "' class='trdetail' name='" + dtcgddetail.Rows[i]["id"] + "'><td width='25px'> <img src='../Images_Folder/Button/tjljh.png' onclick='jianhang(this)' width='25px' height='25px' /></td>");
if (dtcgddetail.Rows[i]["sgdid"].ToString() != "0")
{
detailcode += (" <td><input type='text' id='sgdh" + hcount + "' Class='inpittxt' readonly tag=" + dtcgddetail.Rows[i]["sgdid"] + " value='" + dtcgddetail.Rows[i]["sgdbianhao"] + "' /></td> <td><input type='text' id='wldh" + hcount + "' Class='inpittxt' readonly tag=" + dtcgddetail.Rows[i]["wlid"] + " value='" + dtcgddetail.Rows[i]["wlbh"] + "'></td>"
+ " <td><input type='text' id='wlmc" + hcount + "' Class='inpittxt_hx' readonly value='" + dtcgddetail.Rows[i]["mingcheng"] + "' /></td>");
}
else
{
detailcode += ("<td style='width:100px'></td> <td><input type='text' id='wldh" + hcount + "' Class='inpittxt' tag=" + dtcgddetail.Rows[i]["wlid"] + " value='" + dtcgddetail.Rows[i]["wlbh"] + "' onclick='selectwl(" + hcount + ")' /></td>"
+ " <td><input type='text' id='wlmc" + hcount + "' Class='inpittxt' value='" + dtcgddetail.Rows[i]["mingcheng"] + "' onclick='selectwl(" + hcount + ")' /></td>");
}
detailcode += (
" <td><input type='text' id='changdu" + hcount + "' Class='inpittxt_hx' readonly value='" + dtcgddetail.Rows[i]["guige"] + "' /></td>"
+ " <td><input type='text' id='wlpp" + hcount + "' Class='inpittxt_hx' readonly value='" + dtcgddetail.Rows[i]["pinpai"] + "' /></td>"
+ " <td><input type='text' id='danwei" + hcount + "' Class='inpittxt_hx' readonly value='" + dtcgddetail.Rows[i]["danwei"] + "' /></td>"
+ "<td><input type='text' id='sl" + hcount + "' Class='inpittxt' value='" + dtcgddetail.Rows[i]["sl"] + "' onkeyup='doubleshuru(this," + hcount + ")' /></td>"
+ " <td><input type='text' id='dj" + hcount + "' Class='inpittxt' value='" + dtcgddetail.Rows[i]["dj"] + "' onkeyup='doubleshuru(this," + hcount + ")' /></td>"
+ " <td><input type='text' id='je" + hcount + "' Class='inpittxt' value='" + dtcgddetail.Rows[i]["je"] + "' readonly /></td>"
+ "<td><input type='text' id='cgjd" + hcount + "' Class='inpittxt_hx' readonly style='text-align:center' value='" + dtcgddetail.Rows[i]["cgjd"].ToString() + "' /></td>"
+ "<td><input type='text' id='bz" + hcount + "' Class='inpittxt' value='" + dtcgddetail.Rows[i]["beizhu"] + "' /></td></tr>");
}
}
#endregion
#region
private void binddatebysgd()
{
string scrq = DateTime.Now.ToString("yyyy-MM-dd");
string bzrq = DateTime.Now.AddYears(1).ToString("yyyy-MM-dd").ToString();
string[] idval = Request["id"].ToString().TrimEnd('/').Split('/');
string yhrq = DBHlper.getfirstcolmn("select yhriqi from view_nr_z_shengoudan where id="+idval[0]);
txt_jhriqi.Value = Convert.ToDateTime(yhrq).ToString("yyyy-MM-dd");
DataTable dtsgd = null;
int hcount = 0;
for (int i = 0; i <= idval.Length - 1; i++)
{
dtsgd = DBHlper.Execute("select * from view_nr_z_shengoudan where id=" + idval[i]).Tables[0];
hcount = i + 1;
detailcode += ("<tr id='" + hcount + "' name='0' class='trdetail'><td width='25px'> <img src='../Images_Folder/Button/tjljh.png' onclick='jianhang(this)' width='25px' height='25px' /></td>"
+ "<td><input type='text' id='sgdh" + hcount + "' Class='inpittxt_hx' readonly tag=" + dtsgd.Rows[0]["id"] + " value='" + dtsgd.Rows[0]["sgdbianhao"] + "' /></td>"
+ "<td><input type='text' id='wldh" + hcount + "' Class='inpittxt_hx' readonly value='" + dtsgd.Rows[0]["wlbh"] + "' tag=" + dtsgd.Rows[0]["wlid"] + " /></td>"
+ "<td><input type='text' id='wlmc" + hcount + "' Class='inpittxt_hx' readonly value='" + dtsgd.Rows[0]["mingcheng"] + "' /></td>"
+ "<td><input type='text' id='changdu" + hcount + "' Class='inpittxt_hx' readonly value='" + dtsgd.Rows[0]["guige"] + "' /></td>"
+ "<td><input type='text' id='wlpp" + hcount + "' Class='inpittxt_hx' readonly value='" + dtsgd.Rows[0]["pinpai"] + "' /></td>"
+ "<td><input type='text' id='danwei" + hcount + "' Class='inpittxt_hx' readonly value='" + dtsgd.Rows[0]["danwei"] + "' /></td>"
+ "<td><input type='text' id='sl" + hcount + "' Class='inpittxt' onkeyup='doubleshuru(this," + hcount + ")' value='" + dtsgd.Rows[0]["shengoushu"] + "' /></td>"
+ "<td><input type='text' id='dj" + hcount + "' Class='inpittxt' value='' onblur='hidedj()' onclick='showdj(this," + hcount + ")' onkeyup='doubleshuru(this," + hcount + ")' /></td>"
+ "<td><input type='text' id='je" + hcount + "' Class='inpittxt' readonly /></td>"
+ "<td><input type='text' id='cgjd" + hcount + "' Class='inpittxt_hx' readonly style='text-align:center' value='采购途中' /></td>"
+ "<td><input type='text' id='bz" + hcount + "' Class='inpittxt' /></td></tr>");
}
cgdtype.Value = "true";
}
#endregion
#region
private void initdata(string did)
{
DataTable dt= DBHlper.Execute("select * from view_nr_z_caigoudan where id="+did).Tables[0];
DataTable tbl_lianxiren = DBHlper.Execute("select id,lxr_name,dianhua from nr_z_lianxiren_gys where gys_bh='" + dt.Rows[0]["gysbianhao"].ToString() + "'").Tables[0];
foreach (DataRow dr in tbl_lianxiren.Rows)
{
if (dt.Rows[0]["lixiren"].ToString() == dr["lxr_name"].ToString())
{
fanhuicode += "<option selected value='" + dr["id"].ToString() + "' tag='" + dr["dianhua"] + "'>" + dr["lxr_name"].ToString() + "</option>";
}
else
{
fanhuicode += "<option value='" + dr["id"].ToString() + "' tag='" + dr["dianhua"] + "'>" + dr["lxr_name"].ToString() + "</option>";
}
}
txt_cgdhao.Text =dt.Rows[0]["cgdbianhao"].ToString() ;
drp_cgjindu.Text = dt.Rows[0]["cgjindu"].ToString();
txt_gyshao.Value = dt.Rows[0]["gysbianhao"].ToString();
txt_ghdanwei.Value = dt.Rows[0]["mingcheng"].ToString();
txt_lianxiren.Text = dt.Rows[0]["lixiren"].ToString();
lxrvalue.Value = dt.Rows[0]["lixiren"].ToString();
txt_lianxifangshi.Value = dt.Rows[0]["lianxifangshi"].ToString();
txt_fasongzhi.Text = dt.Rows[0]["songhuodidian"].ToString();
txt_yunshuleixing.Text = dt.Rows[0]["yunshuleixing"].ToString();
txt_caigouyuan.Text = dt.Rows[0]["caigouyuan"].ToString();
txt_xdriqi.Value = DateTime.Parse(dt.Rows[0]["riqi"].ToString()).ToString("yyyy-MM-dd HH:mm");
txt_jhriqi.Value = DateTime.Parse(dt.Rows[0]["jiaohuoriqi"].ToString()).ToString("yyyy-MM-dd");
txt_beizhu.Value = dt.Rows[0]["beizhu"].ToString();
gysid.Value = dt.Rows[0]["gyshangid"].ToString();
txt_shzt.Value = dt.Rows[0]["shzt"].ToString();
}
#endregion
#region model对象
private void getmd()
{
cgdmodel.cgjindu =drp_cgjindu.Text;
cgdmodel.gyshangid =Convert.ToInt32(gysid.Value);
cgdmodel.songhuodidian = txt_fasongzhi.Text.Trim();
cgdmodel.yunshuleixing = txt_yunshuleixing.Text.Trim();
cgdmodel.caigouyuan = txt_caigouyuan.Text.Trim();
cgdmodel.riqi = Convert.ToDateTime(txt_xdriqi.Value);
cgdmodel.jiaohuoriqi = Convert.ToDateTime(txt_jhriqi.Value.Trim());
cgdmodel.beizhu = txt_beizhu.Value.Trim();
cgdmodel.lixiren = lxrvalue.Value;
cgdmodel.lianxifangshi = txt_lianxifangshi.Value;
}
#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_caigoudan", "添加") == false)
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
#region
void pdquanxianbj(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_caigoudan", "编辑个人") == false && DBHlper.GetPermission(juese, "采购单管理", "nr_z_caigoudan", "编辑全部") == false)
{
Response.Redirect("../Common/nopower.htm");
}
}
#endregion
protected void bt_tj_Click(object sender, EventArgs e)
{
try
{
string str = detailcontent.Value;
List<Maticsoft.Model.nr_z_caigoudan_xm> cgddetail = new List<Maticsoft.Model.nr_z_caigoudan_xm>();
cgddetail = DBHlper.ConvertJsonToEntityListEntity<Maticsoft.Model.nr_z_caigoudan_xm>(detailcontent.Value);
string caozuo = "添加";
//接收成功参数值
int cgdid = 0;
int rtx = 0;
//判断uid是否存在值有值为修改无值为添加
if (id.Value != "")
{
cgdid = Convert.ToInt32(id.Value);
rtx = Convert.ToInt32(id.Value);
cgdmodel = cgdbll.GetModel(rtx);
getmd();
cgdbll.Update(cgdmodel);
caozuo = "修改";
string exsitid = "";
foreach (Maticsoft.Model.nr_z_caigoudan_xm detail in cgddetail)
{
if (detail.id == 0)
{
detail.cgdid =Convert.ToInt16(id.Value);
rtx=cgddetailbll.Add(detail);
exsitid += rtx + ",";
}
else {
detail.cgdid=Convert.ToInt32(id.Value);
cgddetailbll.Update(detail);
exsitid += detail.id + ",";
}
}
exsitid = exsitid.TrimEnd(',');
DBHlper.excutecmd("delete from nr_z_caigoudan_xm where id not in("+exsitid+") and cgdid="+id.Value);
}
else
{
getmd();
cgdmodel.cgdhao = DBHlper.getbh("CGD-", "nr_z_caigoudan", "cgdhao", 4);
txt_cgdhao.Text = cgdmodel.cgdhao;
cgdmodel.cgjindu = "已采购";
cgdmodel.shzt = "待审核";
cgdid=cgdbll.Add(cgdmodel);
foreach (Maticsoft.Model.nr_z_caigoudan_xm xm in cgddetail)
{
xm.cgdid = cgdid;
cgddetailbll.Add(xm);
}
}
if (cgdid > 0)
{
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
rizhi.yonghuming = zh.zhanghao;
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + caozuo + "了采购单管理,采购单管理号为:" + txt_cgdhao.Text.Trim();
rizhi.leixing = "采购单管理";
rizhi.riqi = DateTime.Now;
rizhibll.Add(rizhi);
Response.Redirect("Purchase_browse.aspx?uid="+cgdid, false);
}
else
{
Response.Redirect("../Common/error.aspx");
}
}
catch (Exception ex)
{
Response.Redirect("../Common/error.aspx");
}
}
//查询客户名称是否重复
[Ajax.AjaxMethod()]
public int serchmingcheng(string str)
{
string cmd = string.Format("select count(*) from nr_z_kehu where mingcheng='{0}' and zt='1'", str.Replace(" ", ""));
int count = DBHlper.getcount(cmd);
return count;
}
//给最近单价列表赋值
[Ajax.AjaxMethod()]
public string binddanjia(string tj)
{
DataTable dt = DBHlper.Execute("select top 5 * from view_nr_z_caigoudan_xm where 1=1 " + tj + " order by id desc").Tables[0];
string code = "";
foreach (DataRow dr in dt.Rows)
{
code += "<tr><td class='dj'>" + dr["riqi"] + "</td> <td class='dj'>" + dr["gysbh"] + "</td><td class='dj'>" + dr["gysmc"] + "</td><td class='dj'>" + dr["mingcheng"] + "</td><td class='dj'>" + dr["sl"] + "</td><td class='dj'>" + dr["dj"] + "</td></tr>";
}
return code;
}
}