CeramicProject/newyt/Module_data/OrderReceived_list.aspx.cs

557 lines
24 KiB
C#

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 OrderReceived_list : System.Web.UI.Page
{
//创建一个操作记录模板
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");
}
}
Utility.RegisterTypeForAjax(typeof(OrderReceived_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_z_dd_skjl");
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_z_dd_skjl", 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, "订单收款", "nr_z_dd_fysk", "查看全部"))
{
wherecode += string.Format(" from view_z_dd_skjl where " + tiaojian + " id not in(select top ({0}*{1}) id from view_z_dd_skjl "+" where "+tiaojian+" 1=1 " + paixu + ")" + paixu, pg, pageitem);
}
else if (DBHlper.GetPermission(zhanghao.juese, "订单收款", "nr_z_dd_fysk", "查看个人"))
{
wherecode += string.Format(" from view_z_dd_skjl where fkr='" + zhanghao.zhanghao + "' and" + tiaojian + " id not in(select top ({0}*{1}) id from view_z_dd_skjl "+" 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>";
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_z_dd_skjl");
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_z_dd_skjl", 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_z_dd_skjl " + tj);
Maticsoft.Model.nr_z_yhzh yhzh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
if (!DBHlper.GetPermission(yhzh.juese, "订单收款", "nr_z_dd_fysk", "查看全部"))
{
if (tj == "")
{
cmd += " where fkr='" + yhzh.zhanghao + "'";
}
else
{
cmd += " and fkr='" + yhzh.zhanghao + "'";
}
}
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_z_dd_skjl", 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_z_dd_skjl", 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_z_dd_skjl", 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>";
foreach (DataRow dr in dtselect.Rows)
{
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_z_dd_skjl' 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(Ajax.HttpSessionStateRequirement.ReadWrite)]
public int sumitem(string wheretj)
{
string selectcmd = "select count(*) from view_z_dd_skjl " + wheretj;
Maticsoft.Model.nr_z_yhzh yhzh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
if (!DBHlper.GetPermission(yhzh.juese, "订单收款", "nr_z_dd_fysk", "查看全部"))
{
if (wheretj == "")
{
selectcmd += " where fkr='" + yhzh.zhanghao + "'";
}
else
{
selectcmd += " and fkr='" + yhzh.zhanghao + "'";
}
}
int sumcount = DBHlper.getcount(selectcmd);
return sumcount;
}
#endregion
#region
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public string nowdaycount(string zt, string skzt, 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 = "";
string wherecode="";
string ztval = zt;
string skztval = skzt;
if (ztval == "" && skztval == "") {
wherecode = "";
} else if (ztval != "" && skztval == "") {
wherecode ="zt ='" + ztval + "' and ";
} else if (ztval == "" && skztval != "") {
if (skztval == "已收款未开票") {
wherecode = "fpje=0 and ";
} else if (skztval == "已收款已开票") {
wherecode = "fpje>0 and ";
}
} else if (ztval != "" && skztval != "") {
wherecode = "zt ='" + ztval + "' and ";
if (skztval == "已收款未开票") {
wherecode += "fpje=0 and ";
} else if (skztval == "已收款已开票") {
wherecode += "fpje>0 and ";
}
}
wherecode += " 1=1 ";
cmd = string.Format("select CONVERT(varchar(12),skrq,111) as 'riqi' from view_z_dd_skjl where skrq>='{0}' and skrq<='{1}' and {2} ", yuechu, yuemo,wherecode);
Maticsoft.Model.nr_z_yhzh yhzh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
if (!DBHlper.GetPermission(yhzh.juese, "订单收款", "nr_z_dd_fysk", "查看全部"))
{
cmd += " and fkr='" + yhzh.zhanghao + "'";
}
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");
}
if (!DBHlper.GetPermission(juese, "订单收款", "nr_z_dd_fysk", "查看全部") && !DBHlper.GetPermission(juese, "订单收款", "nr_z_dd_fysk", "查看个人"))
{
Response.Redirect("../Common/nopower.htm");
}
if (!DBHlper.GetPermission(juese, "订单收款", "nr_z_dd_fysk", "查看全部") && !DBHlper.GetPermission(juese, "订单收款", "nr_z_dd_fysk", "查看个人"))
{
Response.Redirect("../Common/nopower.htm");
}
if (DBHlper.GetPermission(juese, "订单收款", "nr_z_dd_fysk", "导出"))
{
xiazai.Visible = true;
}
if (DBHlper.GetPermission(juese, "订单收款", "nr_z_dd_fysk", "配置"))
{
leiset.Visible = true;
}
if (DBHlper.GetPermission(juese, "订单收款", "nr_z_dd_fysk", "增加全部订单收款") || DBHlper.GetPermission(juese, "订单收款", "nr_z_dd_fysk", "增加个人订单收款"))
{
li_add.Visible = true;
bt_tj.Visible = true;
}
if (DBHlper.GetPermission(juese, "订单收款", "nr_z_dd_fysk", "打印"))
{
dayin.Visible = true;
}
if (DBHlper.GetPermission(juese, "订单收款", "nr_z_dd_fysk", "收款确认"))
{
if (drp_zt.Value=="待确认") {
shenhe.Visible = true;
}
}
}
#endregion
#region
[Ajax.AjaxMethod]
public string isquanxian(int uid)
{
if (DBHlper.GetPermission(uid, "订单收款", "nr_z_dd_fysk", "查看全部"))
{
return "1";
}
else if (DBHlper.GetPermission(uid, "订单收款", "nr_z_dd_fysk", "查看个人"))
{
return "0";
}
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_z_dd_skjl' 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="";
selectcode = "select " + colmn + " from view_z_dd_skjl where 1=1 ";
if (tj != "")
{
tj=tj.Replace("where","");
selectcode +=" and "+ tj;
}
if (selectid != "")
{
selectcode += " and id in(" + selectid.TrimEnd(',') + ")";
}
if (DBHlper.GetPermission(zhanghao.juese, "订单收款", "nr_z_dd_fysk", "查看全部"))
{
}
else if (DBHlper.GetPermission(zhanghao.juese, "订单收款", "nr_z_dd_fysk", "查看个人"))
{
selectcode += " and fkr='" + zhanghao.zhanghao + "'";
}
DataTable dt = DBHlper.Execute(selectcode + " order by id desc").Tables[0];
DataRow hzdr = dt.NewRow();
string[] hzlie = hiddenhuizong.Value.Split(',');
int exits = 0;
int drindex = 0;
foreach (DataRow dr in dtcolmnname.Rows)
{
exits = 0;
drindex = dr.Table.Rows.IndexOf(dr);
foreach (string lie in hzlie)
{
if (dr["zhongwen"].ToString() == lie)
{
exits++;
}
}
if (exits == 0)
{
hzdr[drindex] = DBNull.Value;
}
else
{
hzdr[drindex] = dt.Compute("Sum(" + dr["lieming"].ToString() + ")", "true");
}
}
dt.Rows.Add(hzdr);
DBHlper.ExportByWeb(dt, "订单收款"+DateTime.Now, sList);
}
#endregion
protected void bt_tj_Click(object sender, EventArgs e)
{
Response.Redirect("OrderCollect_list.aspx");
}
#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>";
string paixuselct = string.Format("select * from nr_lt_paixu where userid='{0}' and tblname='{1}' and isxianshi={2} order by shuixu ", zhanghao.id, "view_z_dd_skjl", 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 + ") ";
if (DBHlper.GetPermission(zhanghao.juese, "订单收款", "nr_z_dd_fysk", "查看全部"))
{
wherecode += " from view_z_dd_skjl where " + tiaojian;
}
else if (DBHlper.GetPermission(zhanghao.juese, "订单收款", "nr_z_dd_fysk", "查看个人"))
{
wherecode += " from view_z_dd_skjl where yewuyuan='" + zhanghao.zhanghao + "' and " + tiaojian;
}
wherecode += " 1=1 ";
code += "<td class='blue'>" + DBHlper.getfirstcolmn(wherecode) + "</td>";
}
}
return code;
}
#endregion
#region
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public string plsh(string ids)
{
string shinfo = "<table style='border:1px solid gray' class='bule'><tr><td class='head2' style='width:100px;border:1px solid gray'>单号</td><td class='head2' style='width:200px;border:1px solid gray'>客户名称</td><td class='head2' style='width:200px;border:1px solid gray'>收款金额</td> <td class='head2' style='width:100px;border:1px solid gray'>操作结果</td></tr>";
string[] getid = ids.Split(',');
string yckinfo = "";
for (int i = 0; i < getid.Length; i++)
{
DataSet ds = DBHlper.Execute("select * from view_z_dd_skjl where id=" + getid[i] + "");
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
string ycks = DBHlper.getfirstcolmn("select isnull(khyck,0) from view_nr_z_kehu where bianhao='" + ds.Tables[0].Rows[0]["kh_bh"].ToString() + "'");
decimal yck = 0;
if (ycks == "")
{
yck = 0;
}
else {
yck =Convert.ToDecimal(ycks);
}
if (Convert.ToDecimal(ds.Tables[0].Rows[0]["syycje"].ToString()) > 0) {
if (Convert.ToDecimal(yck) - Convert.ToDecimal(ds.Tables[0].Rows[0]["syycje"].ToString()) < 0)
{
yckinfo += "客户预存款不足!收款失败!";
shinfo += "<tr><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["bh"].ToString() + "</td><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["khmc"].ToString() + "</td><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["skje"].ToString() + "<td style='border:1px solid gray'><span style='color:red'>" + yckinfo + "</span></td></tr>";
}
else {
int fh = DBHlper.excutecmd("update nr_z_dd_fysk set zt='已确认' where id=" + getid[i] + "");
if (fh > 0)
{
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + "确认了订单收款,收款对象为:" + ds.Tables[0].Rows[0]["khmc"].ToString() + ";收款金额为:¥" + ds.Tables[0].Rows[0]["skje"].ToString() + ";发票金额为:¥" + ds.Tables[0].Rows[0]["fpje"].ToString();
rizhi.yonghuming = zh.zhanghao;
rizhibll.Add(rizhi);
shinfo += "<tr><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["bh"].ToString() + "</td><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["khmc"].ToString() + "</td><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["skje"].ToString() + "<td style='border:1px solid gray'><span>收款确认成功!</span></td></tr>";
}
else
{
shinfo += "<tr><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["bh"].ToString() + "</td><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["khmc"].ToString() + "</td><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["skje"].ToString() + "<td style='border:1px solid gray'><span style='color:red'>收款确认失败!</span></td></tr>";
}
}
}
else
{
int fh = DBHlper.excutecmd("update nr_z_dd_fysk set zt='已确认' where id=" + getid[i] + "");
if (fh > 0)
{
//将session转换对象取值
Maticsoft.Model.nr_z_yhzh zh = (Maticsoft.Model.nr_z_yhzh)Session["user"];
//拼接字符串插入日志
rizhi.jilu = zh.zhanghao + "确认了订单收款,收款对象为:" + ds.Tables[0].Rows[0]["khmc"].ToString() + ";收款金额为:¥" + ds.Tables[0].Rows[0]["skje"].ToString() + ";发票金额为:¥" + ds.Tables[0].Rows[0]["fpje"].ToString();
rizhi.yonghuming = zh.zhanghao;
rizhibll.Add(rizhi);
shinfo += "<tr><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["bh"].ToString() + "</td><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["khmc"].ToString() + "</td><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["skje"].ToString() + "</td><td style='border:1px solid gray'><span>收款确认成功!</span></td></tr>";
}
else
{
shinfo += "<tr><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["bh"].ToString() + "</td><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["khmc"].ToString() + "</td><td style='border:1px solid gray'>" + ds.Tables[0].Rows[0]["skje"].ToString() + "</td><td style='border:1px solid gray'><span style='color:red'>收款确认失败!</span></td></tr>";
}
}
}
}
shinfo += "</table>";
return shinfo;
}
#endregion
}