对账日清后台

//
// DotNetNuke?- http://www.dotnetnuke.com
// Copyright (c) 2002-2018
// by DotNetNuke Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using System.Data;
using C1.Web.Wijmo.Controls.C1GridView;
using Insus.NET;

namespace Modules.duizhang_riqing
{

/// -----------------------------------------------------------------------------
/// <summary>
/// The Viewduizhang_riqing class displays the content
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
partial class Viewduizhang_riqing : PortalModuleBase, IActionable
{

#region "Event Handlers"

/// -----------------------------------------------------------------------------
/// <summary>
/// Page_Load runs when the control is loaded
/// </summary>
/// -----------------------------------------------------------------------------
protected void Page_Load(object sender, System.EventArgs e)
{
try
{
if (!IsPostBack)
{
string state = this.textbox_state.Text.Trim();
string sql = "";
string sql1 = "";
string sql2 = "";
this.textbox_date.Text = DateTime.Now.ToString("yyyy-MM-dd");
if (this.UserId.ToString() == "5")
{
sql = "select id,gjpOrderID,status,picPath from Orders where (daiquren='0' or qiankuanzhuangtai='1') and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) order by gjpOrderID desc";
sql1 = "select id,gjpOrderID,status,picPath from Orders where daiquren='1' and qiankuanzhuangtai='0' and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) order by gjpOrderID desc";

sql2 = "select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) and orderCreateTime='" + this.textbox_date.Text.Trim() + " 00:00:00.000' order by gjpOrderID desc";
}
else
{
if (!state.Equals(""))
{
string stuas = getfanstatus(state);
// and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=8)))
sql = "select id,gjpOrderID,status,picPath from Orders as o where o.status='" + stuas + "' and (daiquren='0' or qiankuanzhuangtai='1') and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) order by gjpOrderID desc";
sql1 = "select id,gjpOrderID,status,picPath from Orders as o where o.status='" + stuas + "' and daiquren='1' and qiankuanzhuangtai='0' and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) order by gjpOrderID desc";
//sql2 = "select id,gjpOrderID,status,picPath from Orders as o where o.status='" + stuas + "' and gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and orderCreateTime='" + this.textbox_date.Text.Trim() + " 00:00:00.000' order by gjpOrderID desc";

sql2 = "select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou and status='" + stuas + "' and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and orderCreateTime='" + this.textbox_date.Text.Trim() + " 00:00:00.000' order by gjpOrderID desc";
}
else
{
sql = "select id,gjpOrderID,status,picPath from Orders where (daiquren='0' or qiankuanzhuangtai='1') and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) order by gjpOrderID desc";
sql1 = "select id,gjpOrderID,status,picPath from Orders where daiquren='1' and qiankuanzhuangtai='0' and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) order by gjpOrderID desc";
//sql2 = "select id,gjpOrderID,status,picPath from Orders where gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and orderCreateTime='" + this.textbox_date.Text.Trim() + " 00:00:00.000' order by gjpOrderID desc";
sql2 = "select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and orderCreateTime='" + this.textbox_date.Text.Trim() + " 00:00:00.000' order by gjpOrderID desc";
}

}
//orderState.SelectedItem.Value = "99";
//string sql = " select id,gjpOrderID,status from Orders ";
DataSet ds = DbHelper.DAL.DateSet(sql);
DataSet ds1 = DbHelper.DAL.DateSet(sql1);
DataSet ds2 = DbHelper.DAL.DateSet(sql2);
if (ds.Tables[0].Rows.Count > 0)
{
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
else
{
//InsusJsUtility objJs = new InsusJsUtility();
//objJs.JsAlert("无数据!!");
}

if (ds1.Tables[0].Rows.Count > 0)
{
this.GridView2.DataSource = ds1;
this.GridView2.DataBind();
}
else
{

}

if (ds2.Tables[0].Rows.Count > 0)
{
this.GridView3.DataSource = ds2;
this.GridView3.DataBind();
}
else
{

}

string name = "select DisPlayName from Users where UserID =" + this.UserId.ToString() + "";
this.txtkefu.Text = kefuname(name).ToString();
this.textbox_date.Text = DateTime.Now.ToString("yyyy-MM-dd");
string emname = "select FullName from employee";
DataSet dsem = GJPDbHelper.DAL.DateSet(emname);
this.DropDownList1.DataSource = dsem;
this.DropDownList1.DataValueField = "FullName";
this.DropDownList1.DataTextField = "FullName";
this.DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("请选择", "-1"));
//string c1 = "select * from 表名";
}
}

catch (Exception exc)
{
//Module failed to load
Exceptions.ProcessModuleLoadException(this, exc);
}
}

public string getfanstatus(string status)
{
if (status == "出库中")
{
status = "0";
}
else if (status == "已出库")
{
status = "1";
}
else if (status == "有返品确认收货")
{
status = "2";
}
else if (status == "无返品确认收货")
{
status = "3";
}
else if (status == "已调度")
{
status = "5";
}
else if (status == "确认收款结束")
{
status = "4";
}
else
{
status = "错误订单";
}
return status;
}
protected void GridView1_RowCreated(object sender, C1GridViewRowEventArgs e)
{
if (e.Row.RowType != (C1GridViewRowType)DataControlRowType.DataRow) return;
string state = this.textbox_state.Text.Trim();

getList(state, e);

}
protected void GridView2_RowCreated(object sender, C1GridViewRowEventArgs e)
{
if (e.Row.RowType != (C1GridViewRowType)DataControlRowType.DataRow) return;
string state = this.textbox_state.Text.Trim();

getList2(state, e);

}
protected void GridView3_RowCreated(object sender, C1GridViewRowEventArgs e)
{
if (e.Row.RowType != (C1GridViewRowType)DataControlRowType.DataRow) return;
string state = this.textbox_state.Text.Trim();

getList3(state, e);

}
/// -----------------------------------------------------------------------------
/// <summary>
/// lstContent_ItemDataBound runs when items are bound. Here the
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// -----------------------------------------------------------------------------
protected void lstContent_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
string strContent = "";

// add content to template
if (!string.IsNullOrEmpty((string)Settings["template"]))
{
strContent = (string)Settings["template"];
ArrayList objProperties = CBO.GetPropertyInfo(typeof(duizhang_riqingInfo));
foreach (PropertyInfo objPropertyInfo in objProperties)
{
strContent = strContent.Replace("[" + objPropertyInfo.Name.ToUpper() + "]", Server.HtmlDecode(DataBinder.Eval(e.Item.DataItem, objPropertyInfo.Name).ToString()));
}
}
else
{
strContent = DataBinder.Eval(e.Item.DataItem, "Content").ToString();
}

// assign the content
Label lblContent = (Label)e.Item.FindControl("lblContent");
lblContent.Text = strContent;
}

#endregion

#region "Optional Interfaces"

/// -----------------------------------------------------------------------------
/// <summary>
/// Registers the module actions required for interfacing with the portal framework
/// </summary>
/// <value></value>
/// <returns></returns>
/// <remarks></remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public ModuleActionCollection ModuleActions
{
get
{
ModuleActionCollection Actions = new ModuleActionCollection();
Actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile),
ModuleActionType.AddContent, "", "add.gif", EditUrl(), false, DotNetNuke.Security.SecurityAccessLevel.Edit,
true, false);
return Actions;
}
}

#endregion
public DataTable ShujuBand(string sql)
{
return DbHelper.DAL.DateSet(sql).Tables[0];
}
public DataTable gjpShujuBand(string sql)
{
return GJPDbHelper.DAL.DateSet(sql).Tables[0];
}
public object kefuname(string sql)
{
return DbHelper.DAL.ExecuteScalar(sql);
}
public int Insersale(string sql)
{
return DbHelper.DAL.ExecuteNonQuery(sql);
}
#region 添加销售
protected void btn_addxiaoshou_Click(object sender, EventArgs e)
{
string sale=this.DropDownList1.SelectedValue;
string yiyou = "select * from kefupp where saleperson ='" + sale + "'";
DataTable dt = ShujuBand(yiyou);
if (dt.Rows.Count > 0)
{
Response.Write("<script>alert('已存在')</script>");
}
else
{
string str = "insert into kefupp values(" + this.UserId.ToString() + ",'" + sale + "')";
int count = Insersale(str);
if (count >= 1)
{
Response.Write("<script>alert('添加成功')</script>");
}
}
}
#endregion
public string getstatus(string status)
{
if (status == "0")
{
status = "出库中";
}
else if (status == "1")
{
status = "已出库";
}
else if (status == "2")
{
status = "有返品确认收货";
}
else if (status == "3")
{
status = "无返品确认收货";
}
else if (status == "5")
{
status = "已调度";
}
else if (status == "4")
{
status = "确认收款结束";
}
else
{
status = "错误订单";
}
return status;
}

#region 数据生成
static int rowindex = 0;
public void getList(string state, C1GridViewRowEventArgs e)
{
int count = GridView1.Rows.Count;
string sql = "";
string datewhere = "";
if (this.textbox_date1.Text == null || this.textbox_date1.Text.Trim() == "") { }
else
{
datewhere = " and o.orderCreateTime='" + this.textbox_date1.Text.Trim() + " 00:00:00.000'";
}
string wherestring = "";
if (this.orderState.SelectedItem.Value == "99")
{
wherestring = " (o.daiquren='0' or o.qiankuanzhuangtai='1') ";
}
else
{
if (this.orderState.SelectedItem.Value == "1")
{
wherestring = " o.daiquren='1' and o.qiankuanzhuangtai='1' ";
}
else
{
wherestring = " (o.daiquren='0' or o.qiankuanzhuangtai='1') and o.status='" + this.orderState.SelectedItem.Value + "' ";
}
}
if (this.UserId.ToString() == "5")
{
sql = "select distinct * from view_selectOrderBillnewnew as v,Orders as o where v.billNumberId = o.gjpOrderId and " + wherestring + " and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox1.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt1.Text.Trim() + "%' Order by v.billNumberId desc";

}
else
{
if (!state.Equals(""))
{
string stuas = getfanstatus(state);
sql = "select distinct * from view_selectOrderBillnewnew as v,Orders as o where v.billNumberId = o.gjpOrderId and o.status='" + stuas + "' and (o.daiquren='0' or o.qiankuanzhuangtai='1') and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox1.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt1.Text.Trim() + "%' Order by v.billNumberId desc";
}
else
{
sql = "select distinct * from view_selectOrderBillnewnew as v,Orders as o where v.billNumberId = o.gjpOrderId and " + wherestring + " and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox1.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt1.Text.Trim() + "%' Order by v.billNumberId desc";
}
}
DataSet ds = DbHelper.DAL.DateSet(sql);
DataTable dtt = DbHelper.DAL.ReplaceFullName(ds.Tables[0], "BName");
ds.Tables.Clear();
ds.Tables.Add(dtt);
//string sqlretu = " select * from OrderReturnGoods";
//DataSet dsre = db.Query(sqlretu);
if (ds.Tables[0].Rows.Count <= count)
{
}
else
{
Table table = new Table();
table.ID = "tabel";
table.Attributes.Add("cellspacing", "0");
table.CssClass = "table01";
//=================================================第一个TR
TableRow tr0 = new TableRow();

TableCell cell1 = new TableCell();
cell1.Text = "客户名称";
cell1.Attributes.Add("Style", "font-weight:bold;");
cell1.Attributes.Add("Width", "20%");
cell1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell1);

TableCell cell3 = new TableCell();
cell3.Attributes.Add("Width", "20%");
cell3.Text = "订单编号";
cell3.Attributes.Add("Style", "font-weight:bold;");
cell3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell3);

TableCell cell5 = new TableCell();
cell5.Attributes.Add("Width", "20%");
cell5.Text = "商城订单编号";
cell5.Attributes.Add("Style", "font-weight:bold;");
cell5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell5);

TableCell cell2 = new TableCell();
cell2.Attributes.Add("Width", "20%");
cell2.Text = "订单状态";
cell2.Attributes.Add("Style", "font-weight:bold;");
cell2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell2);

TableCell cell4 = new TableCell();
cell4.Attributes.Add("Width", "20%");
cell4.Text = "订单明细";
cell4.Attributes.Add("Style", "font-weight:bold;");
cell4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell4);

table.Rows.Add(tr0);

TableRow tr = new TableRow();
TableCell cell6 = new TableCell();
cell6.ID = "txtname";
cell6.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView1.Rows.Count]["BName"].ToString() == "")
{
cell6.Text = "";
}
else
{
cell6.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["BName"].ToString();
}
tr.Cells.Add(cell6);

TableCell cell8 = new TableCell();
cell8.ID = "txtcode";
cell8.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView1.Rows.Count]["Billcode"].ToString() == "")
{
cell8.Text = "";
}
else
{
cell8.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["Billcode"].ToString();
}
tr.Cells.Add(cell8);

TableCell cell10 = new TableCell();
cell10.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView1.Rows.Count]["explain"].ToString() == "")
{
cell10.Text = "";
}
else
{
cell10.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["explain"].ToString();
}
tr.Cells.Add(cell10);

TableCell cell7 = new TableCell();
cell7.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView1.Rows.Count]["status"].ToString().Equals("4"))
{
cell7.ForeColor = System.Drawing.Color.Green;
}
else
{
cell7.ForeColor = System.Drawing.Color.Red;
}
cell7.Text = getstatus(ds.Tables[0].Rows[GridView1.Rows.Count]["status"].ToString());
if (ds.Tables[0].Rows[GridView1.Rows.Count]["daiquren"].ToString() == "0")
{

}
else
{
cell7.Text = "预确认";
}
tr.Cells.Add(cell7);

TableCell cell9 = new TableCell();
Button btnmingxi = new Button();
btnmingxi.ID = "btn_mingxi";
btnmingxi.Text = "详情";
btnmingxi.PreRender += new EventHandler(btn_mingxi_Click);
btnmingxi.CommandArgument = ds.Tables[0].Rows[GridView1.Rows.Count]["Billcode"].ToString();
cell9.Controls.Add(btnmingxi);
cell9.Attributes.Add("Width", "20%");
tr.Cells.Add(cell9);

table.Rows.Add(tr);
//=================================================第二个TR
TableRow tr1 = new TableRow();
TableCell c0 = new TableCell();
c0.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["gjpOrderId"].ToString();
c0.Style.Add("display", "none");
tr1.Cells.Add(c0);

TableCell c1 = new TableCell();
c1.Text = "付款方式";
c1.Attributes.Add("Width", "20%");
c1.Attributes.Add("Style", "font-weight:bold;");
c1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c1);

TableCell c2 = new TableCell();
c2.Attributes.Add("Width", "20%");
c2.Text = "订单金额";
c2.Attributes.Add("Style", "font-weight:bold;");
c2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c2);

TableCell c3 = new TableCell();
c3.Attributes.Add("Width", "20%");
c3.Text = "应收金额";
c3.Attributes.Add("Style", "font-weight:bold;");
c3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c3);

TableCell c4 = new TableCell();
c4.Attributes.Add("Width", "20%");
c4.Text = "实收金额";
c4.Attributes.Add("Style", "font-weight:bold;");
c4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c4);

TableCell c5 = new TableCell();
c5.Attributes.Add("Width", "20%");
c5.Text = "欠款";
c5.Attributes.Add("Style", "font-weight:bold;");
c5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c5);
table.Rows.Add(tr1);
TableRow tr2 = new TableRow();

TableCell c6 = new TableCell();
c6.Attributes.Add("Width", "20%");
c6.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["payType"].ToString();//this.getpay(ds.Tables[0].Rows[GridView1.Rows.Count]["payType"].ToString());
c6.RowSpan = 2;
tr2.Cells.Add(c6);

TableCell c7 = new TableCell();
c7.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString() == "")
{
c7.Text = "";
}
else
{
c7.Text = "¥" + Convert.ToDouble(ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"]).ToString("N");
}
c7.RowSpan = 2;
tr2.Cells.Add(c7);

//TableCell c5 = new TableCell();
//c5.Text = "总金额";
//c5.Attributes.Add("Style", "font-weight:bold;");
//c5.BackColor = System.Drawing.Color.FromName("#5D7B9D");
//c5.Attributes.Add("Width", "20%");
//tr2.Cells.Add(c5);
string bill = ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString();
//string strtui = "select money from OrderReturnGoods where ";
TableCell c8 = new TableCell();
if (ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString() == "")
{
c8.Text = "";
}
else
{
if (ds.Tables[0].Rows[GridView1.Rows.Count]["yingshou"] != DBNull.Value && ds.Tables[0].Rows[GridView1.Rows.Count]["yingshou"] != null)
{
c8.Text = "¥" + Convert.ToDouble(ds.Tables[0].Rows[GridView1.Rows.Count]["yingshou"]).ToString("N");
}
else
{

c8.Text = "¥" + Convert.ToDouble(ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"]).ToString("N");

}

}
c8.Attributes.Add("Width", "20%");
c8.RowSpan = 2;
tr2.Cells.Add(c8);

//TableCell c55 = new TableCell();
//c55.Text = "下单日期";
//c55.Attributes.Add("Style", "font-weight:bold;");
//c55.BackColor = System.Drawing.Color.FromName("#5D7B9D");
//c55.Attributes.Add("Width", "20%");
//tr2.Cells.Add(c55);

TableCell c9 = new TableCell();
if (ds.Tables[0].Rows[GridView1.Rows.Count]["reallyPrice"].ToString() == "")
{
//c9.Text = "¥";


double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}


}

}


c9.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");


}
else
{

double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
double tempd = 0;
if(double.TryParse(dqk.Rows[i]["huankje"].ToString() ,out tempd)){
qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);
}


}

}


c9.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");

}

c9.Attributes.Add("Width", "20%");
c9.RowSpan = 2;
tr2.Cells.Add(c9);
TableCell c10 = new TableCell();
string qiankuan = "";
//if (ds.Tables[0].Rows[GridView1.Rows.Count]["reallyPrice"].ToString() == "")
//{
// qiankuan = (Convert.ToDouble(ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString()) - 0).ToString("N");
//}
//if (ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString() == "")
//{
// qiankuan = (0 - Convert.ToDouble(ds.Tables[0].Rows[GridView1.Rows.Count]["reallyPrice"].ToString())).ToString("N");
//}
//if (ds.Tables[0].Rows[GridView1.Rows.Count]["reallyPrice"].ToString() == "" && ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString() == "")
//{ qiankuan = "0"; }
//if (ds.Tables[0].Rows[GridView1.Rows.Count]["reallyPrice"].ToString() != "" && ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString() != "")
//{
//qiankuan = (Convert.ToDouble(ds.Tables[0].Rows[GridView1.Rows.Count]["yingshou"].ToString()) - 0).ToString("N");
if (ds.Tables[0].Rows[GridView1.Rows.Count]["yingshou"] != DBNull.Value && ds.Tables[0].Rows[GridView1.Rows.Count]["yingshou"] != null)
{
qiankuan = (Convert.ToDouble(ds.Tables[0].Rows[GridView1.Rows.Count]["yingshou"].ToString()) - 0).ToString("N");
}else{

qiankuan = "0";

}
// - Convert.ToDouble(ds.Tables[0].Rows[GridView1.Rows.Count]["reallyPrice"].ToString())
//}
string strqiankuansum = "select sum(cast(huankje as decimal(18,2))) from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + "'";

double huanke = 0;
try
{
DataTable dqksum = DbHelper.DAL.DateSet(strqiankuansum).Tables[0];
if (dqksum.Rows.Count > 0)
{
if (Convert.IsDBNull(dqksum.Rows[0][0]))
{

}
else
{
//huanke = Convert.ToDouble(dqksum.Rows[0][0]);
double tempd = 0;
if (double.TryParse(dqksum.Rows[0][0].ToString(), out tempd))
{
huanke = Convert.ToDouble(tempd);
}
}
}
}
catch (Exception ex)
{
huanke = 0;

}
if (Convert.ToDouble(qiankuan) - huanke > 0)
{
table.BackColor = System.Drawing.ColorTranslator.FromHtml("#fef1bd");
c10.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffff00");
}
string qiankuanstr = Math.Round((Convert.ToDouble(qiankuan) - huanke), 2).ToString();

c10.Text = "¥" + qiankuanstr;
c10.Attributes.Add("Width", "20%");
c10.RowSpan = 2;
tr2.Cells.Add(c10);

table.Rows.Add(tr2);

TableRow tr2_1 = new TableRow();
TableCell c9_1 = new TableCell();
if (ds.Tables[0].Rows[GridView1.Rows.Count]["reallyPrice"].ToString() == "")
{

double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + tempd;
}


}

}


c9_1.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");

}
else
{

double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + tempd;
}


}

}


c9_1.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");


}
c9_1.Attributes.Add("Width", "20%");

tr2_1.Cells.Add(c9_1);
table.Rows.Add(tr2_1);


//=================================================欠款显示
if (Convert.ToDouble(qiankuan) > 0)
{
double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);

double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + tempd;
}
if (dqk.Rows.Count == 1)
{
TableRow tr03 = new TableRow();
TableCell d1 = new TableCell();
d1.Text = "支付方式";
d1.Attributes.Add("Style", "font-weight:bold;");
d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d1.Attributes.Add("Width", "20%");
tr03.Cells.Add(d1);

TableCell d2 = new TableCell();
d2.Text = "支付时间";
d2.Attributes.Add("Style", "font-weight:bold;");
d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d2.Attributes.Add("Width", "20%");
tr03.Cells.Add(d2);

TableCell d3 = new TableCell();
d3.Text = "还款金额";
d3.Attributes.Add("Style", "font-weight:bold;");
d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d3.Attributes.Add("Width", "20%");
tr03.Cells.Add(d3);

TableCell d4 = new TableCell();
d4.Text = "还款率";
d4.Attributes.Add("Style", "font-weight:bold;");
d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d4.Attributes.Add("Width", "20%");
tr03.Cells.Add(d4);

TableCell d5 = new TableCell();
d5.Text = "操作";
d5.Attributes.Add("Style", "font-weight:bold;");
d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d5.Attributes.Add("Width", "20%");
tr03.Cells.Add(d5);
table.Rows.Add(tr03);

TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
//d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}
d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView1.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView1.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView1.Rows.Count]["Billcode"].ToString();
d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
if (Convert.ToDouble(qiankuan) <= qiankuanjine)
{
btn.Enabled = false;
btn1.Enabled = false;
}
}
else
{
if (i == dqk.Rows.Count - 1)
{
TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
//d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
//double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}
d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView1.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView1.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView1.Rows.Count]["Billcode"].ToString();
d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
if (Convert.ToDouble(qiankuan) <= qiankuanjine)
{
btn.Enabled = false;
btn1.Enabled = false;
}
}
else
{
if (i == 0)
{
TableRow tr03 = new TableRow();
TableCell d1 = new TableCell();
d1.Text = "支付方式";
d1.Attributes.Add("Style", "font-weight:bold;");
d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d1.Attributes.Add("Width", "20%");
tr03.Cells.Add(d1);

TableCell d2 = new TableCell();
d2.Text = "支付时间";
d2.Attributes.Add("Style", "font-weight:bold;");
d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d2.Attributes.Add("Width", "20%");
tr03.Cells.Add(d2);

TableCell d3 = new TableCell();
d3.Text = "还款金额";
d3.Attributes.Add("Style", "font-weight:bold;");
d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d3.Attributes.Add("Width", "20%");
tr03.Cells.Add(d3);

TableCell d4 = new TableCell();
d4.Text = "还款率";
d4.Attributes.Add("Style", "font-weight:bold;");
d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d4.Attributes.Add("Width", "20%");
tr03.Cells.Add(d4);

TableCell d5 = new TableCell();
d5.Text = "操作";
d5.Attributes.Add("Style", "font-weight:bold;");
d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d5.Attributes.Add("Width", "20%");
tr03.Cells.Add(d5);
table.Rows.Add(tr03);

TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
//btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
//d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
//btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView1.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView1.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView1.Rows.Count]["Billcode"].ToString();
//d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
}
else
{
TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";

//double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}

d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
//d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView1.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView1.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView1.Rows.Count]["Billcode"].ToString();
//d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
}

}
}
}
}
else
{
TableRow tr03 = new TableRow();
TableCell d1 = new TableCell();
d1.Text = "支付方式";
d1.Attributes.Add("Style", "font-weight:bold;");
d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d1.Attributes.Add("Width", "20%");
tr03.Cells.Add(d1);

TableCell d2 = new TableCell();
d2.Text = "支付时间";
d2.Attributes.Add("Style", "font-weight:bold;");
d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d2.Attributes.Add("Width", "20%");
tr03.Cells.Add(d2);

TableCell d3 = new TableCell();
d3.Text = "还款金额";
d3.Attributes.Add("Style", "font-weight:bold;");
d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d3.Attributes.Add("Width", "20%");
tr03.Cells.Add(d3);

TableCell d4 = new TableCell();
d4.Text = "还款率";
d4.Attributes.Add("Style", "font-weight:bold;");
d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d4.Attributes.Add("Width", "20%");
tr03.Cells.Add(d4);

TableCell d5 = new TableCell();
d5.Text = "操作";
d5.Attributes.Add("Style", "font-weight:bold;");
d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d5.Attributes.Add("Width", "20%");
tr03.Cells.Add(d5);
table.Rows.Add(tr03);

TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = "<select id='xingjia'><option>现金</option><option>微信</option><option>支付宝</option><option>余额</option></select>";

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = "";
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
d8.Text = "";
d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = "";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView1.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView1.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView1.Rows.Count]["Billcode"].ToString();
d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
}


}

//if (Convert.ToDouble(qiankuan) > 0)
//{

// TableRow tr03 = new TableRow();
// TableCell d1 = new TableCell();
// d1.Text = "支付方式";
// d1.Attributes.Add("Style", "font-weight:bold;");
// d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d1.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d1);

// TableCell d2 = new TableCell();
// d2.Text = "支付时间";
// d2.Attributes.Add("Style", "font-weight:bold;");
// d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d2.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d2);

// TableCell d3 = new TableCell();
// d3.Text = "还款金额";
// d3.Attributes.Add("Style", "font-weight:bold;");
// d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d3.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d3);

// TableCell d4 = new TableCell();
// d4.Text = "还款率";
// d4.Attributes.Add("Style", "font-weight:bold;");
// d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d4.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d4);

// TableCell d5 = new TableCell();
// d5.Text = "操作";
// d5.Attributes.Add("Style", "font-weight:bold;");
// d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d5.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d5);
// table.Rows.Add(tr03);

// string str = "select * from [qiankuanbiao] where [billcode]='" + ds.Tables[0].Rows[GridView1.Rows.Count]["Billcode"].ToString()+"'";
// ShujuBand(str);

// TableRow tr04 = new TableRow();
// TableCell d6 = new TableCell();
// d6.ID = "zffs";
// d6.Text = "<select id='xingjia'><option>现金全收</option><option>现金半收</option><option>现金不收</option><option>微信支付</option><option>其他</option></select>";

// d6.Attributes.Add("contentEditable", "true");
// d6.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d6);

// TableCell d7 = new TableCell();
// d7.ID = "zfsj";
// d7.Text = "";
// d7.Attributes.Add("contentEditable", "true");
// d7.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d7);

// TableCell d8 = new TableCell();
// d8.ID = "hkje";
// d8.Text = "";
// d8.Attributes.Add("contentEditable", "true");
// d8.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d8);

// TableCell d9 = new TableCell();
// d9.ID = "hkl";
// d9.Text = "";
// d9.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d9);

// TableCell d10 = new TableCell();
// Button btn = new Button();
// btn.ID = "btn_addqiankuan";
// btn.Text = "添加";
// btn.OnClientClick = "addqiankuan(this);return false;";
// d10.Controls.Add(btn);
// Button btn1 = new Button();
// btn1.ID = "btn_addbaocun";
// btn1.Text = "保存";
// btn1.OnClientClick = "huanqian(this);return false;";
// //btn1.Click += new EventHandler(btn_addqiankuan_Click);
// btn.CommandArgument = ds.Tables[0].Rows[GridView1.Rows.Count]["Billcode"].ToString();
// d10.Controls.Add(btn1);
// d10.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d10);
// table.Rows.Add(tr04);

//}
//=================================================退单显示
//TableRow tr05 = new TableRow();
//TableCell e1 = new TableCell();
//e1.Text = "退货单编号";
//e1.Attributes.Add("Style", "font-weight:bold;");
//e1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e1.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e1);

//TableCell e2 = new TableCell();
//e2.Text = "";
//e2.Attributes.Add("Style", "font-weight:bold;");
//e2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e2.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e2);

//TableCell e3 = new TableCell();
//e3.Text = "检查";
//e3.Attributes.Add("Style", "font-weight:bold;");
//e3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e3.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e3);

//TableCell e4 = new TableCell();
//e4.Text = "";
//e4.Attributes.Add("Style", "font-weight:bold;");
//e4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e4.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e4);

//TableCell e5 = new TableCell();
//e5.Text = "明细";
//e5.Attributes.Add("Style", "font-weight:bold;");
//e5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e5.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e5);
//table.Rows.Add(tr05);

//TableRow tr06 = new TableRow();
//TableCell e6 = new TableCell();
//e6.Text = "¥" + ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString();
//e6.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e6);

//TableCell e7 = new TableCell();
//e7.Text = "";
//e7.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e7);

//TableCell e8 = new TableCell();
//e8.Text = "¥" + ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString();
//e8.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e8);

//TableCell e9 = new TableCell();
//e9.Text = "";
//e9.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e9);

//TableCell e10 = new TableCell();
//e10.Text = "¥" + ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString();
//e10.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e10);
//table.Rows.Add(tr06);

//=================================================第四个TR
string sql01 = " select COUNT(*) as num from Orders as o,OrderReturnGoods as oo where o.gjpOrderId = oo.billNumberId ";
DataSet ds01 = DbHelper.DAL.DateSet(sql01);
if (Convert.ToInt32(ds01.Tables[0].Rows[0]["num"].ToString()) > 0)
{
DataSet ds1 = this.getReturnGoods(ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString());
//if (ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString().Equals(ds.Tables[0].Rows[0]["gjpOrderId"].ToString())) {
TableRow tr33 = new TableRow();
TableCell get1 = new TableCell();
get1.Text = "实际返品信息";
get1.Attributes.Add("Style", "10%;");
get1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
get1.Attributes.Add("Style", "font-weight:bold;");
tr33.Cells.Add(get1);

TableCell getF = new TableCell();
//getF.Attributes.Add("Style", "90%;");
getF.ColumnSpan = 4;
Table tab1 = new Table();
tab1.CssClass = "tab1";
if (Convert.ToInt32(ds1.Tables[0].Rows.Count) > 0)
{
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
if (i == 0)
{
TableRow tr01 = new TableRow();
TableCell c301 = new TableCell();
c301.Text = "商品号";
c301.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c301.Attributes.Add("Style", "font-weight:bold;");
c301.Attributes.Add("Width", "25%");
c301.ColumnSpan = 0;
tr01.Cells.Add(c301);
//


TableCell c30 = new TableCell();
c30.Text = "商品名";
c30.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c30.Attributes.Add("Style", "font-weight:bold;");
c30.Attributes.Add("Width", "25%");
c30.ColumnSpan = 0;
tr01.Cells.Add(c30);

TableCell c32 = new TableCell();
c32.Text = "返品数量";
c32.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c32.Attributes.Add("Style", "font-weight:bold;");
c32.Attributes.Add("Width", "25%");
c32.ColumnSpan = 0;
tr01.Cells.Add(c32);

TableCell c34 = new TableCell();
c34.Text = "返品单价";
c34.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c34.Attributes.Add("Style", "font-weight:bold;");
c34.Attributes.Add("Width", "25%");
c34.ColumnSpan = 0;
tr01.Cells.Add(c34);


//TableCell c40 = new TableCell();
//c40.Attributes.Add("Width", "20%");
//c40.Text = "";
//c40.Attributes.Add("Style", "font-weight:bold;");
//c40.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//tr01.Cells.Add(c40);

TableRow tr02 = new TableRow();

TableCell c311 = new TableCell();
c311.Text = ds1.Tables[0].Rows[i]["ptypeid"].ToString();
c311.Attributes.Add("Width", "25%");
tr02.Cells.Add(c311);

TableCell c31 = new TableCell();
c31.Text = ds1.Tables[0].Rows[i]["goodsName"].ToString();
c31.Attributes.Add("Width", "25%");
tr02.Cells.Add(c31);

TableCell c33 = new TableCell();
c33.Attributes.Add("Width", "25%");
c33.Text = ds1.Tables[0].Rows[i]["qty"].ToString() + ds1.Tables[0].Rows[i]["unitName"].ToString();
tr02.Cells.Add(c33);

TableCell c35 = new TableCell();
c35.Text = "¥" + Convert.ToDouble(ds1.Tables[0].Rows[i]["Price"]).ToString("N");
c35.Attributes.Add("Width", "25%");
tr02.Cells.Add(c35);

//TableCell c42 = new TableCell();
//c42.Attributes.Add("Width", "20%");
//c42.Text = "";
//tr02.Cells.Add(c42);

tab1.Rows.Add(tr01);
tab1.Rows.Add(tr02);
}
else
{
TableRow tr02 = new TableRow();

TableCell c311 = new TableCell();
c311.Text = ds1.Tables[0].Rows[i]["ptypeid"].ToString();
c311.Attributes.Add("Width", "25%");
tr02.Cells.Add(c311);

TableCell c31 = new TableCell();
c31.Text = ds1.Tables[0].Rows[i]["goodsName"].ToString();
c31.Attributes.Add("Width", "25%");
tr02.Cells.Add(c31);

TableCell c33 = new TableCell();
c33.Attributes.Add("Width", "25%");
c33.Text = ds1.Tables[0].Rows[i]["qty"].ToString() + ds1.Tables[0].Rows[i]["unitName"].ToString();
tr02.Cells.Add(c33);

TableCell c35 = new TableCell();
c35.Text = "¥" + Convert.ToDouble(ds1.Tables[0].Rows[i]["Price"]).ToString("N");
c35.Attributes.Add("Width", "25%");
tr02.Cells.Add(c35);

//TableCell c42 = new TableCell();
//c42.Attributes.Add("Width", "20%");
//c42.Text = "";
//tr02.Cells.Add(c42);

tab1.Rows.Add(tr02);
}
}
getF.Controls.Add(tab1);
tr33.Cells.Add(getF);
table.Rows.Add(tr33);
}
else
{
TableRow tr01 = new TableRow();
TableCell c301 = new TableCell();
c301.Text = "无返品";
c301.Attributes.Add("Style", "font-weight:bold;text-align:center;font-size:15px;");
c301.Attributes.Add("Width", "100%");
c301.ColumnSpan = 8;
tr01.Cells.Add(c301);

tab1.Rows.Add(tr01);
getF.Controls.Add(tab1);
tr33.Cells.Add(getF);
table.Rows.Add(tr33);
}
}


string ordersql = " select COUNT(*) as num from Orders as o,OrderReturnGoods as oo where o.gjpOrderId = oo.billNumberId ";
DataSet dst = DbHelper.DAL.DateSet(ordersql);
if (!ds.Tables[0].Rows[GridView1.Rows.Count]["status"].ToString().Equals("3"))
{
if (Convert.ToInt32(dst.Tables[0].Rows[0]["num"].ToString()) > 0)
{
string getOrd = " select * from view_selectOrderfanpin where BillNumberId =" + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString();
DataSet dt = DbHelper.DAL.DateSet(getOrd);
if (dt.Tables[0].Rows.Count > 0)
{
TableRow tr11 = new TableRow();
TableCell ce0 = new TableCell();
ce0.Text = dt.Tables[0].Rows[0]["BillNumberId"].ToString();
ce0.Style.Add("display", "none");
tr11.Cells.Add(ce0);

TableCell ce1 = new TableCell();
ce1.Text = "返品订单号";
ce1.Attributes.Add("Style", "font-weight:bold;text-align:center;");
ce1.Attributes.Add("Width", "10%");
//ce1.BackColor = System.Drawing.Color.FromName("#5D7B9D");
tr11.Cells.Add(ce1);

TableCell ce2 = new TableCell();
ce2.Attributes.Add("Width", "20%");
ce2.ID = "TextBoxsave";
ce2.Text = "";
ce2.Attributes.Add("contentEditable", "true");
ce2.Attributes.Add("Width", "20%");
tr11.Cells.Add(ce2);

TableCell ce3 = new TableCell();
ce3.Attributes.Add("Width", "20%");
ce3.Attributes.Add("Style", "text-align:center;");
Button button3 = new Button();
button3.ID = "tijiao13";
button3.CssClass = "tijiao3";
button3.Attributes.Add("Style", "Width:90px;height: 30px;background-color:#CAE8EA;font-weight: bold;font-size: 14px;text-align:center;");
button3.Text = "校 验";
//button3.Click += new EventHandler(CheckButton_Click);
button3.OnClientClick = "jianyan(this);return false;";
ce3.Controls.Add(button3);
tr11.Cells.Add(ce3);

TableCell ce22 = new TableCell();
ce22.Attributes.Add("Width", "20%");
ce22.Text = "";
ce22.Attributes.Add("Width", "20%");
tr11.Cells.Add(ce22);

TableCell ce32 = new TableCell();
ce32.Attributes.Add("Width", "20%");
ce32.Text = "";
ce32.Attributes.Add("Width", "20%");
tr11.Cells.Add(ce32);

DataSet ds2 = this.getReturnGoods(ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString());
if (Convert.ToInt32(ds2.Tables[0].Rows.Count) > 0)
{
table.Rows.Add(tr11);
}
}
}
}
//=================================================第三个TR
TableRow trt = new TableRow();

TableCell cellt1 = new TableCell();
cellt1.Text = "司机备注";
cellt1.Attributes.Add("Style", "font-weight:bold;");
cellt1.Attributes.Add("Width", "25%");
cellt1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
trt.Cells.Add(cellt1);

TableCell cellt3 = new TableCell();
cellt3.Attributes.Add("Width", "25%");
cellt3.Text = "客服备注(可输入)";
cellt3.Attributes.Add("Style", "font-weight:bold;");
cellt3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
cellt3.ColumnSpan = 2;
trt.Cells.Add(cellt3);

TableCell cellt5 = new TableCell();
cellt5.Attributes.Add("Width", "25%");
cellt5.Text = "财务备注";
cellt5.Attributes.Add("Style", "font-weight:bold;");
cellt5.BackColor = System.Drawing.Color.FromName("#CAE8EA");

trt.Cells.Add(cellt5);


TableCell cellt7 = new TableCell();
cellt7.Attributes.Add("Width", "25%");
cellt7.Text = "可用余额";
cellt7.Attributes.Add("Style", "font-weight:bold;");
cellt7.BackColor = System.Drawing.Color.FromName("#CAE8EA");
trt.Cells.Add(cellt7);

table.Rows.Add(trt);

TableRow trtt = new TableRow();
TableCell cellt6 = new TableCell();
cellt6.ID = "drivercomment";
cellt6.Attributes.Add("Width", "25%");
if (ds.Tables[0].Rows[GridView1.Rows.Count]["beizhu"].ToString() == "")
{
cellt6.Text = "&nbsp; ";
}
else
{
cellt6.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["beizhu"].ToString();
}
trtt.Cells.Add(cellt6);

TableCell cellt8 = new TableCell();
cellt8.ID = "servicecomment";
cellt8.Attributes.Add("Width", "25%");
if (ds.Tables[0].Rows[GridView1.Rows.Count]["kefubeizhu"].ToString() == "")
{
cellt8.Text = "";
cellt8.Attributes.Add("contentEditable", "true");
}
else
{
cellt8.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["kefubeizhu"].ToString();
}
cellt8.ColumnSpan = 2;
trtt.Cells.Add(cellt8);

TableCell cellt10 = new TableCell();
cellt10.Attributes.Add("Width", "25%");
if (ds.Tables[0].Rows[GridView1.Rows.Count]["caiwubeizhu"].ToString() == "")
{
cellt10.Text = "";
}
else
{
cellt10.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["caiwubeizhu"].ToString();
}

trtt.Cells.Add(cellt10);

TableCell cellt9 = new TableCell();
cellt9.Attributes.Add("Width", "25%");
if (ds.Tables[0].Rows[GridView1.Rows.Count]["yukuan"].ToString() == "")
{
cellt9.Text = "0";
}
else
{
cellt9.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["yukuan"].ToString();
}

trtt.Cells.Add(cellt9);


table.Rows.Add(trtt);


if (!ds.Tables[0].Rows[GridView1.Rows.Count]["status"].ToString().Equals("9"))
{
//if (!ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString().Equals(ds.Tables[0].Rows[0]["gjpOrderId"].ToString()))
//{
string billNumberId = ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString();
string btypeid = ds.Tables[0].Rows[GridView1.Rows.Count]["btypeid"].ToString();
string payType = ds.Tables[0].Rows[GridView1.Rows.Count]["payType"].ToString();
string totalmoney = ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString();
string reallyPrice = ds.Tables[0].Rows[GridView1.Rows.Count]["reallyPrice"].ToString();
TableRow tr3 = new TableRow();

TableCell cell331 = new TableCell();
//cell331.Attributes.Add("Width", "100%");
cell331.ColumnSpan = 5;
Button button32 = new Button();
button32.ID = "tijiao13xa";
button32.CssClass = "tijiao3xa";
button32.Attributes.Add("Style", "Width:150px;float:center;margin-right:15px;;font-weight:bold;background-color:#CAE8EA;height:30px;");
button32.Text = "待 确 定 订 单";
button32.OnClientClick = "daiqueren(this," + ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString() + ",'" + this.UserId + "','" + ds.Tables[0].Rows[GridView1.Rows.Count]["BName"].ToString() + "');return false;";
//button32.Click += new EventHandler(daiqueren_Click);
//button32.CommandArgument = ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString();
cell331.Controls.Add(button32);
//Button button31 = new Button();
//button31.ID = "tijiao13xa";
//button31.CssClass = "tijiao3xaa";
//button31.Attributes.Add("Style", "Width:150px;float;center;margin-left:15px;font-weight:bold;background-color:#CAE8EA;height:30px; ");

////button31.Attributes.Add("Style","Visible:false;");
//button31.Text = "确 定 订 单";
//string obj = billNumberId + "," + btypeid + "," + payType + "," + totalmoney + "," + reallyPrice;
//button31.OnClientClick = "queren('"+obj+"');return false;";
////button31.Click += new EventHandler(SaveButton_Click);
//button31.CommandArgument = billNumberId + "," + btypeid + "," + payType + "," + totalmoney + "," + reallyPrice;
//cell331.Controls.Add(button31);
tr3.Cells.Add(cell331);

//TableCell cell11 = new TableCell();
//TextBox tb1 = new TextBox();
//tb1.ID = "Text11";
//tb1.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["billNumberId"].ToString();
//tb1.Attributes.Add("Style", "display:none;border:0px");
//cell11.Controls.Add(tb1);
//tr3.Cells.Add(cell11);

//TableCell cell22 = new TableCell();
//TextBox tb2 = new TextBox();
//tb2.ID = "Text12";
//tb2.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["btypeid"].ToString();
//tb2.Attributes.Add("Style", "display:none;border:0px");
//cell22.Controls.Add(tb2);
//tr3.Cells.Add(cell22);

//TableCell cell33 = new TableCell();
//TextBox tb3 = new TextBox();
//tb3.ID = "Text13";
//tb3.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["payType"].ToString();
//tb3.Attributes.Add("Style", "display:none;border:0px");
//cell33.Controls.Add(tb3);
//tr3.Cells.Add(cell33);

//TableCell cell44 = new TableCell();
//TextBox tb4 = new TextBox();
//tb4.ID = "Text14";
//tb4.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["totalmoney"].ToString();
//tb4.Attributes.Add("Style", "display:none;border:0px");
//cell44.Controls.Add(tb4);
//tr3.Cells.Add(cell44);

//TableCell cell55 = new TableCell();
//TextBox tb5 = new TextBox();
//tb5.ID = "Text15";
//tb5.Text = ds.Tables[0].Rows[GridView1.Rows.Count]["reallyPrice"].ToString();
//tb5.Attributes.Add("Style", "display:none;border:0px");
//cell55.Controls.Add(tb5);
//tr3.Cells.Add(cell55);

table.Rows.Add(tr3);
}
e.Row.Cells[2].Controls.Add(table);
//if (e.Row.FindControl("ButtonOK") != null)
//{
// Button CtlButton = (Button)e.Row.FindControl("ButtonOK");
// CtlButton.Click += new EventHandler(OKButton_Click);
//}
}
}

public void getList2(string state, C1GridViewRowEventArgs e)
{
int count = GridView2.Rows.Count;
string sql = "";
string datewhere = "";
if (this.textbox_date2.Text == null || this.textbox_date2.Text.Trim() == "") { }
else
{
datewhere = " and o.orderCreateTime='" + this.textbox_date2.Text.Trim() + " 00:00:00.000'";
}

if (this.UserId.ToString() == "5")
{

sql = "select distinct * from view_selectOrderBillnewnew as v,Orders as o where v.billNumberId = o.gjpOrderId and o.daiquren='1' and o.qiankuanzhuangtai='0' and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox2.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt2.Text.Trim() + "%' Order by v.billNumberId desc";


}
else
{
if (!state.Equals(""))
{
string stuas = getfanstatus(state);
// and o.qiankuanzhuangtai='0'
sql = "select distinct * from view_selectOrderBillnewnew as v,Orders as o where v.billNumberId = o.gjpOrderId and o.status='" + stuas + "' and o.daiquren='1' and o.qiankuanzhuangtai='0' and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox2.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt2.Text.Trim() + "%' Order by v.billNumberId desc";
}
else
{
// and o.qiankuanzhuangtai='0'
sql = "select distinct * from view_selectOrderBillnewnew as v,Orders as o where v.billNumberId = o.gjpOrderId and o.daiquren='1' and o.qiankuanzhuangtai='0' and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox2.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt2.Text.Trim() + "%' Order by v.billNumberId desc";
}
}
DataSet ds = DbHelper.DAL.DateSet(sql);
DataTable dtt = DbHelper.DAL.ReplaceFullName(ds.Tables[0], "BName"); ds.Tables.Clear(); ds.Tables.Add(dtt);
//string sqlretu = " select * from OrderReturnGoods";
//DataSet dsre = db.Query(sqlretu);
if (ds.Tables[0].Rows.Count <= count)
{
}
else
{
Table table = new Table();
table.ID = "tabel";
table.Attributes.Add("cellspacing", "0");
table.CssClass = "table01";
//=================================================第一个TR
TableRow tr0 = new TableRow();

TableCell cell1 = new TableCell();
cell1.Text = "客户名称";
cell1.Attributes.Add("Style", "font-weight:bold;");
cell1.Attributes.Add("Width", "20%");
cell1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell1);

TableCell cell3 = new TableCell();
cell3.Attributes.Add("Width", "20%");
cell3.Text = "订单编号";
cell3.Attributes.Add("Style", "font-weight:bold;");
cell3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell3);

TableCell cell5 = new TableCell();
cell5.Attributes.Add("Width", "20%");
cell5.Text = "商城订单编号";
cell5.Attributes.Add("Style", "font-weight:bold;");
cell5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell5);

TableCell cell2 = new TableCell();
cell2.Attributes.Add("Width", "20%");
cell2.Text = "订单状态";
cell2.Attributes.Add("Style", "font-weight:bold;");
cell2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell2);

TableCell cell4 = new TableCell();
cell4.Attributes.Add("Width", "20%");
cell4.Text = "订单明细";
cell4.Attributes.Add("Style", "font-weight:bold;");
cell4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell4);

table.Rows.Add(tr0);

TableRow tr = new TableRow();
TableCell cell6 = new TableCell();
cell6.ID = "txtname";
cell6.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView2.Rows.Count]["BName"].ToString() == "")
{
cell6.Text = "";
}
else
{
cell6.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["BName"].ToString();
}
tr.Cells.Add(cell6);

TableCell cell8 = new TableCell();
cell8.ID = "txtcode";
cell8.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView2.Rows.Count]["Billcode"].ToString() == "")
{
cell8.Text = "";
}
else
{
cell8.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["Billcode"].ToString();
}
tr.Cells.Add(cell8);

TableCell cell10 = new TableCell();
cell10.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView2.Rows.Count]["explain"].ToString() == "")
{
cell10.Text = "";
}
else
{
cell10.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["explain"].ToString();
}
tr.Cells.Add(cell10);

TableCell cell7 = new TableCell();
cell7.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView2.Rows.Count]["status"].ToString().Equals("4"))
{
cell7.ForeColor = System.Drawing.Color.Green;
}
else
{
cell7.ForeColor = System.Drawing.Color.Red;
}
cell7.Text = getstatus(ds.Tables[0].Rows[GridView2.Rows.Count]["status"].ToString());

if (ds.Tables[0].Rows[GridView2.Rows.Count]["status"].ToString()=="5")
{
cell7.Text = "预确认";
}

tr.Cells.Add(cell7);

TableCell cell9 = new TableCell();
Button btnmingxi = new Button();
btnmingxi.ID = "btn_mingxi";
btnmingxi.Text = "详情";
btnmingxi.PreRender += new EventHandler(btn_mingxi_Click);
btnmingxi.CommandArgument = ds.Tables[0].Rows[GridView2.Rows.Count]["Billcode"].ToString();
cell9.Controls.Add(btnmingxi);
cell9.Attributes.Add("Width", "20%");
tr.Cells.Add(cell9);

table.Rows.Add(tr);
//=================================================第二个TR
TableRow tr1 = new TableRow();
TableCell c0 = new TableCell();
c0.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["gjpOrderId"].ToString();
c0.Style.Add("display", "none");
tr1.Cells.Add(c0);

TableCell c1 = new TableCell();
c1.Text = "付款方式";
c1.Attributes.Add("Width", "20%");
c1.Attributes.Add("Style", "font-weight:bold;");
c1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c1);

TableCell c2 = new TableCell();
c2.Attributes.Add("Width", "20%");
c2.Text = "订单金额";
c2.Attributes.Add("Style", "font-weight:bold;");
c2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c2);

TableCell c3 = new TableCell();
c3.Attributes.Add("Width", "20%");
c3.Text = "应收金额";
c3.Attributes.Add("Style", "font-weight:bold;");
c3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c3);

TableCell c4 = new TableCell();
c4.Attributes.Add("Width", "20%");
c4.Text = "实收金额/余额付";
c4.Attributes.Add("Style", "font-weight:bold;");
c4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c4);

TableCell c5 = new TableCell();
c5.Attributes.Add("Width", "20%");
c5.Text = "欠款";
c5.Attributes.Add("Style", "font-weight:bold;");
c5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c5);
table.Rows.Add(tr1);
TableRow tr2 = new TableRow();

TableCell c6 = new TableCell();
c6.Attributes.Add("Width", "20%");
c6.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["payType"].ToString();//this.getpay(ds.Tables[0].Rows[GridView2.Rows.Count]["payType"].ToString());
c6.RowSpan = 2;
tr2.Cells.Add(c6);

TableCell c7 = new TableCell();
c7.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString() == "")
{
c7.Text = "";
}
else
{
c7.Text = "¥" + Convert.ToDouble(ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"]).ToString("N");
}
c7.RowSpan = 2;
tr2.Cells.Add(c7);

//TableCell c5 = new TableCell();
//c5.Text = "总金额";
//c5.Attributes.Add("Style", "font-weight:bold;");
//c5.BackColor = System.Drawing.Color.FromName("#5D7B9D");
//c5.Attributes.Add("Width", "20%");
//tr2.Cells.Add(c5);
string bill = ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString();
//string strtui = "select money from OrderReturnGoods where ";
TableCell c8 = new TableCell();
if (ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString() == "")
{
c8.Text = "";
}
else
{
if (ds.Tables[0].Rows[GridView2.Rows.Count]["yingshou"] != DBNull.Value && ds.Tables[0].Rows[GridView2.Rows.Count]["yingshou"] != null)
{
c8.Text = "¥" + Convert.ToDouble(ds.Tables[0].Rows[GridView2.Rows.Count]["yingshou"]).ToString("N");
}
else
{

c8.Text = "¥" + Convert.ToDouble(ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"]).ToString("N");

}

}
c8.Attributes.Add("Width", "20%");
c8.RowSpan = 2;
tr2.Cells.Add(c8);

//TableCell c55 = new TableCell();
//c55.Text = "下单日期";
//c55.Attributes.Add("Style", "font-weight:bold;");
//c55.BackColor = System.Drawing.Color.FromName("#5D7B9D");
//c55.Attributes.Add("Width", "20%");
//tr2.Cells.Add(c55);

TableCell c9 = new TableCell();
if (ds.Tables[0].Rows[GridView2.Rows.Count]["reallyPrice"].ToString() == "")
{
double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}

}

}


c9.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");

}
else
{
double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}


}

}


c9.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");

}
c9.Attributes.Add("Width", "20%");
c9.RowSpan = 2;
tr2.Cells.Add(c9);
TableCell c10 = new TableCell();
string qiankuan = "";
//if (ds.Tables[0].Rows[GridView2.Rows.Count]["reallyPrice"].ToString() == "")
//{
// qiankuan = (Convert.ToDouble(ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString()) - 0).ToString("N");
//}
//if (ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString() == "")
//{
// qiankuan = (0 - Convert.ToDouble(ds.Tables[0].Rows[GridView2.Rows.Count]["reallyPrice"].ToString())).ToString("N");
//}
//if (ds.Tables[0].Rows[GridView2.Rows.Count]["reallyPrice"].ToString() == "" && ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString() == "")
//{ qiankuan = "0"; }
//if (ds.Tables[0].Rows[GridView2.Rows.Count]["reallyPrice"].ToString() != "" && ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString() != "")
//{
//qiankuan = (Convert.ToDouble(ds.Tables[0].Rows[GridView2.Rows.Count]["yingshou"].ToString()) - 0).ToString("N");
if (ds.Tables[0].Rows[GridView2.Rows.Count]["yingshou"] != DBNull.Value && ds.Tables[0].Rows[GridView2.Rows.Count]["yingshou"] != null)
{
qiankuan = (Convert.ToDouble(ds.Tables[0].Rows[GridView2.Rows.Count]["yingshou"].ToString()) - 0).ToString("N");
}
else
{

qiankuan = "0";

}
//- Convert.ToDouble(ds.Tables[0].Rows[GridView2.Rows.Count]["reallyPrice"].ToString())
//}
string strqiankuansum = "select sum(cast(huankje as decimal(18,2))) from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqksum = DbHelper.DAL.DateSet(strqiankuansum).Tables[0];
double huanke = 0;
try
{
if (dqksum.Rows.Count > 0)
{
if (Convert.IsDBNull(dqksum.Rows[0][0]))
{

}
else
{
//huanke = Convert.ToDouble(dqksum.Rows[0][0]);
double tempd = 0;
if (double.TryParse(dqksum.Rows[0][0].ToString(), out tempd))
{

huanke = Convert.ToDouble(tempd);

}
}
}
}
catch (Exception ex)
{
huanke = 0;

}
if (Convert.ToDouble(qiankuan) - huanke > 0)
{
table.BackColor = System.Drawing.ColorTranslator.FromHtml("#fef1bd");
c10.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffff00");
}

string qiankuanstr = Math.Round((Convert.ToDouble(qiankuan) - huanke), 2).ToString();

c10.Text = "¥" + qiankuanstr;
c10.Attributes.Add("Width", "20%");
c10.RowSpan = 2;
tr2.Cells.Add(c10);

table.Rows.Add(tr2);

TableRow tr2_1 = new TableRow();
TableCell c9_1 = new TableCell();
if (ds.Tables[0].Rows[GridView2.Rows.Count]["reallyPrice"].ToString() == "")
{

double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);

double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}

}

}


c9_1.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");

}
else
{
double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);

double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}

}

}


c9_1.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");
}
c9_1.Attributes.Add("Width", "20%");
c9_1.RowSpan = 2;
tr2_1.Cells.Add(c9_1);
table.Rows.Add(tr2_1);


//=================================================欠款显示
if (Convert.ToDouble(qiankuan) > 0)
{
double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}
if (dqk.Rows.Count == 1)
{
TableRow tr03 = new TableRow();
TableCell d1 = new TableCell();
d1.Text = "支付方式";
d1.Attributes.Add("Style", "font-weight:bold;");
d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d1.Attributes.Add("Width", "20%");
tr03.Cells.Add(d1);

TableCell d2 = new TableCell();
d2.Text = "支付时间";
d2.Attributes.Add("Style", "font-weight:bold;");
d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d2.Attributes.Add("Width", "20%");
tr03.Cells.Add(d2);

TableCell d3 = new TableCell();
d3.Text = "还款金额";
d3.Attributes.Add("Style", "font-weight:bold;");
d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d3.Attributes.Add("Width", "20%");
tr03.Cells.Add(d3);

TableCell d4 = new TableCell();
d4.Text = "还款率";
d4.Attributes.Add("Style", "font-weight:bold;");
d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d4.Attributes.Add("Width", "20%");
tr03.Cells.Add(d4);

TableCell d5 = new TableCell();
d5.Text = "操作";
d5.Attributes.Add("Style", "font-weight:bold;");
d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d5.Attributes.Add("Width", "20%");
tr03.Cells.Add(d5);
table.Rows.Add(tr03);

TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
//d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}
d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView2.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView2.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView2.Rows.Count]["Billcode"].ToString();
d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
if (Convert.ToDouble(qiankuan) <= qiankuanjine)
{
btn.Enabled = false;
btn1.Enabled = false;
}

//btn变灰
btn.Enabled = false;
btn1.Enabled = false;
}
else
{
if (i == dqk.Rows.Count - 1)
{
TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
//d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}
d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView2.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView2.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView2.Rows.Count]["Billcode"].ToString();
d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
if (Convert.ToDouble(qiankuan) <= qiankuanjine)
{
btn.Enabled = false;
btn1.Enabled = false;
}
//btn变灰
btn.Enabled = false;
btn1.Enabled = false;
}
else
{
if (i == 0)
{
TableRow tr03 = new TableRow();
TableCell d1 = new TableCell();
d1.Text = "支付方式";
d1.Attributes.Add("Style", "font-weight:bold;");
d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d1.Attributes.Add("Width", "20%");
tr03.Cells.Add(d1);

TableCell d2 = new TableCell();
d2.Text = "支付时间";
d2.Attributes.Add("Style", "font-weight:bold;");
d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d2.Attributes.Add("Width", "20%");
tr03.Cells.Add(d2);

TableCell d3 = new TableCell();
d3.Text = "还款金额";
d3.Attributes.Add("Style", "font-weight:bold;");
d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d3.Attributes.Add("Width", "20%");
tr03.Cells.Add(d3);

TableCell d4 = new TableCell();
d4.Text = "还款率";
d4.Attributes.Add("Style", "font-weight:bold;");
d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d4.Attributes.Add("Width", "20%");
tr03.Cells.Add(d4);

TableCell d5 = new TableCell();
d5.Text = "操作";
d5.Attributes.Add("Style", "font-weight:bold;");
d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d5.Attributes.Add("Width", "20%");
tr03.Cells.Add(d5);
table.Rows.Add(tr03);

TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
//d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}
d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
//btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
//d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
//btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView2.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView2.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView2.Rows.Count]["Billcode"].ToString();
//d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
}
else
{
TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
//d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}
d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
//d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView2.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView2.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView2.Rows.Count]["Billcode"].ToString();
//d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
}

}
}
}
}
else
{
TableRow tr03 = new TableRow();
TableCell d1 = new TableCell();
d1.Text = "支付方式";
d1.Attributes.Add("Style", "font-weight:bold;");
d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d1.Attributes.Add("Width", "20%");
tr03.Cells.Add(d1);

TableCell d2 = new TableCell();
d2.Text = "支付时间";
d2.Attributes.Add("Style", "font-weight:bold;");
d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d2.Attributes.Add("Width", "20%");
tr03.Cells.Add(d2);

TableCell d3 = new TableCell();
d3.Text = "还款金额";
d3.Attributes.Add("Style", "font-weight:bold;");
d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d3.Attributes.Add("Width", "20%");
tr03.Cells.Add(d3);

TableCell d4 = new TableCell();
d4.Text = "还款率";
d4.Attributes.Add("Style", "font-weight:bold;");
d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d4.Attributes.Add("Width", "20%");
tr03.Cells.Add(d4);

TableCell d5 = new TableCell();
d5.Text = "操作";
d5.Attributes.Add("Style", "font-weight:bold;");
d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d5.Attributes.Add("Width", "20%");
tr03.Cells.Add(d5);
table.Rows.Add(tr03);

TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = "<select id='xingjia' disabled="disabled"><option>现金</option><option>微信</option><option>支付宝</option><option>余额</option></select>";

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = "";
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
d8.Text = "";
d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = "";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView2.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView2.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView2.Rows.Count]["Billcode"].ToString();
d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");

//btn变灰
btn.Enabled = false;
btn1.Enabled = false;

tr04.Cells.Add(d10);
table.Rows.Add(tr04);
}


}

//if (Convert.ToDouble(qiankuan) > 0)
//{

// TableRow tr03 = new TableRow();
// TableCell d1 = new TableCell();
// d1.Text = "支付方式";
// d1.Attributes.Add("Style", "font-weight:bold;");
// d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d1.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d1);

// TableCell d2 = new TableCell();
// d2.Text = "支付时间";
// d2.Attributes.Add("Style", "font-weight:bold;");
// d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d2.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d2);

// TableCell d3 = new TableCell();
// d3.Text = "还款金额";
// d3.Attributes.Add("Style", "font-weight:bold;");
// d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d3.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d3);

// TableCell d4 = new TableCell();
// d4.Text = "还款率";
// d4.Attributes.Add("Style", "font-weight:bold;");
// d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d4.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d4);

// TableCell d5 = new TableCell();
// d5.Text = "操作";
// d5.Attributes.Add("Style", "font-weight:bold;");
// d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d5.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d5);
// table.Rows.Add(tr03);

// string str = "select * from [qiankuanbiao] where [billcode]='" + ds.Tables[0].Rows[GridView2.Rows.Count]["Billcode"].ToString()+"'";
// ShujuBand(str);

// TableRow tr04 = new TableRow();
// TableCell d6 = new TableCell();
// d6.ID = "zffs";
// d6.Text = "<select id='xingjia'><option>现金全收</option><option>现金半收</option><option>现金不收</option><option>微信支付</option><option>其他</option></select>";

// d6.Attributes.Add("contentEditable", "true");
// d6.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d6);

// TableCell d7 = new TableCell();
// d7.ID = "zfsj";
// d7.Text = "";
// d7.Attributes.Add("contentEditable", "true");
// d7.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d7);

// TableCell d8 = new TableCell();
// d8.ID = "hkje";
// d8.Text = "";
// d8.Attributes.Add("contentEditable", "true");
// d8.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d8);

// TableCell d9 = new TableCell();
// d9.ID = "hkl";
// d9.Text = "";
// d9.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d9);

// TableCell d10 = new TableCell();
// Button btn = new Button();
// btn.ID = "btn_addqiankuan";
// btn.Text = "添加";
// btn.OnClientClick = "addqiankuan(this);return false;";
// d10.Controls.Add(btn);
// Button btn1 = new Button();
// btn1.ID = "btn_addbaocun";
// btn1.Text = "保存";
// btn1.OnClientClick = "huanqian(this);return false;";
// //btn1.Click += new EventHandler(btn_addqiankuan_Click);
// btn.CommandArgument = ds.Tables[0].Rows[GridView2.Rows.Count]["Billcode"].ToString();
// d10.Controls.Add(btn1);
// d10.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d10);
// table.Rows.Add(tr04);

//}
//=================================================退单显示
//TableRow tr05 = new TableRow();
//TableCell e1 = new TableCell();
//e1.Text = "退货单编号";
//e1.Attributes.Add("Style", "font-weight:bold;");
//e1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e1.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e1);

//TableCell e2 = new TableCell();
//e2.Text = "";
//e2.Attributes.Add("Style", "font-weight:bold;");
//e2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e2.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e2);

//TableCell e3 = new TableCell();
//e3.Text = "检查";
//e3.Attributes.Add("Style", "font-weight:bold;");
//e3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e3.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e3);

//TableCell e4 = new TableCell();
//e4.Text = "";
//e4.Attributes.Add("Style", "font-weight:bold;");
//e4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e4.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e4);

//TableCell e5 = new TableCell();
//e5.Text = "明细";
//e5.Attributes.Add("Style", "font-weight:bold;");
//e5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e5.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e5);
//table.Rows.Add(tr05);

//TableRow tr06 = new TableRow();
//TableCell e6 = new TableCell();
//e6.Text = "¥" + ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString();
//e6.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e6);

//TableCell e7 = new TableCell();
//e7.Text = "";
//e7.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e7);

//TableCell e8 = new TableCell();
//e8.Text = "¥" + ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString();
//e8.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e8);

//TableCell e9 = new TableCell();
//e9.Text = "";
//e9.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e9);

//TableCell e10 = new TableCell();
//e10.Text = "¥" + ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString();
//e10.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e10);
//table.Rows.Add(tr06);

//=================================================第四个TR
string sql01 = " select COUNT(*) as num from Orders as o,OrderReturnGoods as oo where o.gjpOrderId = oo.billNumberId ";
DataSet ds01 = DbHelper.DAL.DateSet(sql01);
if (Convert.ToInt32(ds01.Tables[0].Rows[0]["num"].ToString()) > 0)
{
DataSet ds1 = this.getReturnGoods(ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString());
//if (ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString().Equals(ds.Tables[0].Rows[0]["gjpOrderId"].ToString())) {
TableRow tr33 = new TableRow();
TableCell get1 = new TableCell();
get1.Text = "实际返品信息";
get1.Attributes.Add("Style", "10%;");
get1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
get1.Attributes.Add("Style", "font-weight:bold;");
tr33.Cells.Add(get1);

TableCell getF = new TableCell();
//getF.Attributes.Add("Style", "90%;");
getF.ColumnSpan = 4;
Table tab1 = new Table();
tab1.CssClass = "tab1";
if (Convert.ToInt32(ds1.Tables[0].Rows.Count) > 0)
{
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
if (i == 0)
{
TableRow tr01 = new TableRow();
TableCell c301 = new TableCell();
c301.Text = "商品号";
c301.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c301.Attributes.Add("Style", "font-weight:bold;");
c301.Attributes.Add("Width", "25%");
c301.ColumnSpan = 0;
tr01.Cells.Add(c301);
//


TableCell c30 = new TableCell();
c30.Text = "商品名";
c30.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c30.Attributes.Add("Style", "font-weight:bold;");
c30.Attributes.Add("Width", "25%");
c30.ColumnSpan = 0;
tr01.Cells.Add(c30);

TableCell c32 = new TableCell();
c32.Text = "返品数量";
c32.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c32.Attributes.Add("Style", "font-weight:bold;");
c32.Attributes.Add("Width", "25%");
c32.ColumnSpan = 0;
tr01.Cells.Add(c32);

TableCell c34 = new TableCell();
c34.Text = "返品单价";
c34.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c34.Attributes.Add("Style", "font-weight:bold;");
c34.Attributes.Add("Width", "25%");
c34.ColumnSpan = 0;
tr01.Cells.Add(c34);


//TableCell c40 = new TableCell();
//c40.Attributes.Add("Width", "20%");
//c40.Text = "";
//c40.Attributes.Add("Style", "font-weight:bold;");
//c40.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//tr01.Cells.Add(c40);

TableRow tr02 = new TableRow();

TableCell c311 = new TableCell();
c311.Text = ds1.Tables[0].Rows[i]["ptypeid"].ToString();
c311.Attributes.Add("Width", "25%");
tr02.Cells.Add(c311);

TableCell c31 = new TableCell();
c31.Text = ds1.Tables[0].Rows[i]["goodsName"].ToString();
c31.Attributes.Add("Width", "25%");
tr02.Cells.Add(c31);

TableCell c33 = new TableCell();
c33.Attributes.Add("Width", "25%");
c33.Text = ds1.Tables[0].Rows[i]["qty"].ToString() + ds1.Tables[0].Rows[i]["unitName"].ToString();
tr02.Cells.Add(c33);

TableCell c35 = new TableCell();
c35.Text = "¥" + Convert.ToDouble(ds1.Tables[0].Rows[i]["Price"]).ToString("N");
c35.Attributes.Add("Width", "25%");
tr02.Cells.Add(c35);

//TableCell c42 = new TableCell();
//c42.Attributes.Add("Width", "20%");
//c42.Text = "";
//tr02.Cells.Add(c42);

tab1.Rows.Add(tr01);
tab1.Rows.Add(tr02);
}
else
{
TableRow tr02 = new TableRow();

TableCell c311 = new TableCell();
c311.Text = ds1.Tables[0].Rows[i]["ptypeid"].ToString();
c311.Attributes.Add("Width", "25%");
tr02.Cells.Add(c311);

TableCell c31 = new TableCell();
c31.Text = ds1.Tables[0].Rows[i]["goodsName"].ToString();
c31.Attributes.Add("Width", "25%");
tr02.Cells.Add(c31);

TableCell c33 = new TableCell();
c33.Attributes.Add("Width", "25%");
c33.Text = ds1.Tables[0].Rows[i]["qty"].ToString() + ds1.Tables[0].Rows[i]["unitName"].ToString();
tr02.Cells.Add(c33);

TableCell c35 = new TableCell();
c35.Text = "¥" + Convert.ToDouble(ds1.Tables[0].Rows[i]["Price"]).ToString("N");
c35.Attributes.Add("Width", "25%");
tr02.Cells.Add(c35);

//TableCell c42 = new TableCell();
//c42.Attributes.Add("Width", "20%");
//c42.Text = "";
//tr02.Cells.Add(c42);

tab1.Rows.Add(tr02);
}
}
getF.Controls.Add(tab1);
tr33.Cells.Add(getF);
table.Rows.Add(tr33);
}
else
{
TableRow tr01 = new TableRow();
TableCell c301 = new TableCell();
c301.Text = "无返品";
c301.Attributes.Add("Style", "font-weight:bold;text-align:center;font-size:15px;");
c301.Attributes.Add("Width", "100%");
c301.ColumnSpan = 8;
tr01.Cells.Add(c301);

tab1.Rows.Add(tr01);
getF.Controls.Add(tab1);
tr33.Cells.Add(getF);
table.Rows.Add(tr33);
}
}


string ordersql = " select COUNT(*) as num from Orders as o,OrderReturnGoods as oo where o.gjpOrderId = oo.billNumberId ";
DataSet dst = DbHelper.DAL.DateSet(ordersql);
if (!ds.Tables[0].Rows[GridView2.Rows.Count]["status"].ToString().Equals("3"))
{
if (Convert.ToInt32(dst.Tables[0].Rows[0]["num"].ToString()) > 0)
{
string getOrd = " select * from view_selectOrderfanpin where BillNumberId =" + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString();
DataSet dt = DbHelper.DAL.DateSet(getOrd);
if (dt.Tables[0].Rows.Count > 0)
{
TableRow tr11 = new TableRow();
TableCell ce0 = new TableCell();
ce0.Text = dt.Tables[0].Rows[0]["BillNumberId"].ToString();
ce0.Style.Add("display", "none");
tr11.Cells.Add(ce0);

TableCell ce1 = new TableCell();
ce1.Text = "返品订单号";
ce1.Attributes.Add("Style", "font-weight:bold;text-align:center;");
ce1.Attributes.Add("Width", "10%");
//ce1.BackColor = System.Drawing.Color.FromName("#5D7B9D");
tr11.Cells.Add(ce1);

TableCell ce2 = new TableCell();
ce2.Attributes.Add("Width", "20%");
ce2.ID = "TextBoxsave";
ce2.Text = "";
ce2.Attributes.Add("contentEditable", "true");
ce2.Attributes.Add("Width", "20%");
tr11.Cells.Add(ce2);

TableCell ce3 = new TableCell();
ce3.Attributes.Add("Width", "20%");
ce3.Attributes.Add("Style", "text-align:center;");
Button button3 = new Button();
button3.ID = "tijiao13";
button3.CssClass = "tijiao3";
button3.Attributes.Add("Style", "Width:90px;height: 30px;background-color:#CAE8EA;font-weight: bold;font-size: 14px;text-align:center;");
button3.Text = "校 验";
//button3.Click += new EventHandler(CheckButton_Click);
button3.OnClientClick = "jianyan(this);return false;";
ce3.Controls.Add(button3);
tr11.Cells.Add(ce3);

TableCell ce22 = new TableCell();
ce22.Attributes.Add("Width", "20%");
ce22.Text = "";
ce22.Attributes.Add("Width", "20%");
tr11.Cells.Add(ce22);

TableCell ce32 = new TableCell();
ce32.Attributes.Add("Width", "20%");
ce32.Text = "";
ce32.Attributes.Add("Width", "20%");
tr11.Cells.Add(ce32);

DataSet ds2 = this.getReturnGoods(ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString());
if (Convert.ToInt32(ds2.Tables[0].Rows.Count) > 0)
{
table.Rows.Add(tr11);
}
}
}
}
//=================================================第三个TR
TableRow trt = new TableRow();

TableCell cellt1 = new TableCell();
cellt1.Text = "司机备注";
cellt1.Attributes.Add("Style", "font-weight:bold;");
cellt1.Attributes.Add("Width", "25%");
cellt1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
trt.Cells.Add(cellt1);

TableCell cellt3 = new TableCell();
cellt3.Attributes.Add("Width", "25%");
cellt3.Text = "客服备注(可输入)";
cellt3.Attributes.Add("Style", "font-weight:bold;");
cellt3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
cellt3.ColumnSpan = 2;
trt.Cells.Add(cellt3);

TableCell cellt5 = new TableCell();
cellt5.Attributes.Add("Width", "25%");
cellt5.Text = "财务备注";
cellt5.Attributes.Add("Style", "font-weight:bold;");
cellt5.BackColor = System.Drawing.Color.FromName("#CAE8EA");

trt.Cells.Add(cellt5);

TableCell cellt7 = new TableCell();
cellt7.Attributes.Add("Width", "25%");
cellt7.Text = "可用余额";
cellt7.Attributes.Add("Style", "font-weight:bold;");
cellt7.BackColor = System.Drawing.Color.FromName("#CAE8EA");
trt.Cells.Add(cellt7);

table.Rows.Add(trt);

table.Rows.Add(trt);

TableRow trtt = new TableRow();
TableCell cellt6 = new TableCell();
cellt6.ID = "drivercomment";
cellt6.Attributes.Add("Width", "33%");
if (ds.Tables[0].Rows[GridView2.Rows.Count]["beizhu"].ToString() == "")
{
cellt6.Text = "&nbsp; ";
}
else
{
cellt6.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["beizhu"].ToString();
}
trtt.Cells.Add(cellt6);

TableCell cellt8 = new TableCell();
cellt8.ID = "servicecomment";
cellt8.Attributes.Add("Width", "33%");
if (ds.Tables[0].Rows[GridView2.Rows.Count]["kefubeizhu"].ToString() == "")
{
cellt8.Text = "";
cellt8.Attributes.Add("contentEditable", "true");
}
else
{
cellt8.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["kefubeizhu"].ToString();
}
cellt8.ColumnSpan = 2;
trtt.Cells.Add(cellt8);

TableCell cellt10 = new TableCell();
cellt10.Attributes.Add("Width", "34%");
if (ds.Tables[0].Rows[GridView2.Rows.Count]["caiwubeizhu"].ToString() == "")
{
cellt10.Text = "";
}
else
{
cellt10.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["caiwubeizhu"].ToString();
}

trtt.Cells.Add(cellt10);

TableCell cellt9 = new TableCell();
cellt9.Attributes.Add("Width", "25%");
if (ds.Tables[0].Rows[GridView2.Rows.Count]["yukuan"].ToString() == "")
{
cellt9.Text = "0";
}
else
{
cellt9.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["yukuan"].ToString();
}

trtt.Cells.Add(cellt9);


table.Rows.Add(trtt);


//if (!ds.Tables[0].Rows[GridView2.Rows.Count]["status"].ToString().Equals("9"))
//{
// //if (!ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString().Equals(ds.Tables[0].Rows[0]["gjpOrderId"].ToString()))
// //{
// string billNumberId = ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString();
// string btypeid = ds.Tables[0].Rows[GridView2.Rows.Count]["btypeid"].ToString();
// string payType = ds.Tables[0].Rows[GridView2.Rows.Count]["payType"].ToString();
// string totalmoney = ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString();
// string reallyPrice = ds.Tables[0].Rows[GridView2.Rows.Count]["reallyPrice"].ToString();
// TableRow tr3 = new TableRow();

// TableCell cell331 = new TableCell();
// //cell331.Attributes.Add("Width", "100%");
// cell331.ColumnSpan = 5;
// Button button32 = new Button();
// button32.ID = "tijiao13xa";
// button32.CssClass = "tijiao3xa";
// button32.Attributes.Add("Style", "Width:150px;float:center;margin-right:15px;;font-weight:bold;background-color:#CAE8EA;height:30px;");
// button32.Text = "待 确 定 订 单";
// button32.OnClientClick = "daiqueren(this," + ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString() + ");return false;";
// //button32.Click += new EventHandler(daiqueren_Click);
// //button32.CommandArgument = ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString();
// cell331.Controls.Add(button32);
// //Button button31 = new Button();
// //button31.ID = "tijiao13xa";
// //button31.CssClass = "tijiao3xaa";
// //button31.Attributes.Add("Style", "Width:150px;float;center;margin-left:15px;font-weight:bold;background-color:#CAE8EA;height:30px; ");

// ////button31.Attributes.Add("Style","Visible:false;");
// //button31.Text = "确 定 订 单";
// //string obj = billNumberId + "," + btypeid + "," + payType + "," + totalmoney + "," + reallyPrice;
// //button31.OnClientClick = "queren('"+obj+"');return false;";
// ////button31.Click += new EventHandler(SaveButton_Click);
// //button31.CommandArgument = billNumberId + "," + btypeid + "," + payType + "," + totalmoney + "," + reallyPrice;
// //cell331.Controls.Add(button31);
// tr3.Cells.Add(cell331);

// //TableCell cell11 = new TableCell();
// //TextBox tb1 = new TextBox();
// //tb1.ID = "Text11";
// //tb1.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["billNumberId"].ToString();
// //tb1.Attributes.Add("Style", "display:none;border:0px");
// //cell11.Controls.Add(tb1);
// //tr3.Cells.Add(cell11);

// //TableCell cell22 = new TableCell();
// //TextBox tb2 = new TextBox();
// //tb2.ID = "Text12";
// //tb2.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["btypeid"].ToString();
// //tb2.Attributes.Add("Style", "display:none;border:0px");
// //cell22.Controls.Add(tb2);
// //tr3.Cells.Add(cell22);

// //TableCell cell33 = new TableCell();
// //TextBox tb3 = new TextBox();
// //tb3.ID = "Text13";
// //tb3.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["payType"].ToString();
// //tb3.Attributes.Add("Style", "display:none;border:0px");
// //cell33.Controls.Add(tb3);
// //tr3.Cells.Add(cell33);

// //TableCell cell44 = new TableCell();
// //TextBox tb4 = new TextBox();
// //tb4.ID = "Text14";
// //tb4.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["totalmoney"].ToString();
// //tb4.Attributes.Add("Style", "display:none;border:0px");
// //cell44.Controls.Add(tb4);
// //tr3.Cells.Add(cell44);

// //TableCell cell55 = new TableCell();
// //TextBox tb5 = new TextBox();
// //tb5.ID = "Text15";
// //tb5.Text = ds.Tables[0].Rows[GridView2.Rows.Count]["reallyPrice"].ToString();
// //tb5.Attributes.Add("Style", "display:none;border:0px");
// //cell55.Controls.Add(tb5);
// //tr3.Cells.Add(cell55);

// table.Rows.Add(tr3);
//}
e.Row.Cells[2].Controls.Add(table);
//if (e.Row.FindControl("ButtonOK") != null)
//{
// Button CtlButton = (Button)e.Row.FindControl("ButtonOK");
// CtlButton.Click += new EventHandler(OKButton_Click);
//}
}
}

public void getList3(string state, C1GridViewRowEventArgs e)
{
int count = GridView3.Rows.Count;
string sql = "";
string datewhere = "";
if (this.textbox_date.Text == null || this.textbox_date.Text.Trim() == "") { }
else
{
datewhere = " and o.orderCreateTime='" + this.textbox_date.Text.Trim() + " 00:00:00.000'";
}


if (textbox1all.Text == "1")
{
if (this.UserId.ToString() == "5")
{
sql = "select distinct * from view_selectOrderBillnewnew as v,(select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou) as o where v.billNumberId = o.gjpOrderId and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' Order by v.billNumberId desc";
}
else
{
if (!state.Equals(""))
{
string stuas = getfanstatus(state);

//sql = "select distinct * from view_selectOrderBillnewnew as v,Orders as o where v.billNumberId = o.gjpOrderId and o.status='" + stuas + "' and o.gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' Order by billNumberId desc";
sql = "select distinct * from view_selectOrderBillnewnew as v,(select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou) as o where v.billNumberId = o.gjpOrderId and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' Order by v.billNumberId desc";
}
else
{

//sql = "select distinct * from view_selectOrderBillnewnew as v,Orders as o where v.billNumberId = o.gjpOrderId and o.gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' Order by billNumberId desc";
sql = "select distinct * from view_selectOrderBillnewnew as v,(select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou) as o where v.billNumberId = o.gjpOrderId and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' Order by v.billNumberId desc";
}
}
}
else
{
if (this.UserId.ToString() == "5")
{
sql = "select distinct * from view_selectOrderBillnewnew as v,(select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou) as o where v.billNumberId = o.gjpOrderId and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' Order by v.billNumberId desc";
}
else
{
if (!state.Equals(""))
{
string stuas = getfanstatus(state);
//sql = "select distinct * from view_selectOrderBillnewnew as v,Orders as o where v.billNumberId = o.gjpOrderId and o.status='" + stuas + "' and o.gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' Order by billNumberId desc";
sql = "select distinct * from view_selectOrderBillnewnew as v,(select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou) as o where v.billNumberId = o.gjpOrderId and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' Order by v.billNumberId desc";
}
else
{
//sql = "select distinct * from view_selectOrderBillnewnew as v,Orders as o where v.billNumberId = o.gjpOrderId and o.gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' Order by billNumberId desc";
sql = "select distinct * from view_selectOrderBillnewnew as v,(select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou) as o where v.billNumberId = o.gjpOrderId and o.SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and o.CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') " + datewhere + " and v.Billcode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' Order by v.billNumberId desc";
}
}
}

DataSet ds = DbHelper.DAL.DateSet(sql);
DataTable dtt = DbHelper.DAL.ReplaceFullName(ds.Tables[0], "BName"); ds.Tables.Clear(); ds.Tables.Add(dtt);
//string sqlretu = " select * from OrderReturnGoods";
//DataSet dsre = db.Query(sqlretu);
if (ds.Tables[0].Rows.Count <= count)
{
}
else
{
Table table = new Table();
table.ID = "tabel";
table.Attributes.Add("cellspacing", "0");
table.CssClass = "table01";
//=================================================第一个TR
TableRow tr0 = new TableRow();

TableCell cell1 = new TableCell();
cell1.Text = "客户名称";
cell1.Attributes.Add("Style", "font-weight:bold;");
cell1.Attributes.Add("Width", "20%");
cell1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell1);

TableCell cell3 = new TableCell();
cell3.Attributes.Add("Width", "20%");
cell3.Text = "订单编号";
cell3.Attributes.Add("Style", "font-weight:bold;");
cell3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell3);

TableCell cell5 = new TableCell();
cell5.Attributes.Add("Width", "20%");
cell5.Text = "商城订单编号";
cell5.Attributes.Add("Style", "font-weight:bold;");
cell5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell5);

TableCell cell2 = new TableCell();
cell2.Attributes.Add("Width", "20%");
cell2.Text = "订单状态";
cell2.Attributes.Add("Style", "font-weight:bold;");
cell2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell2);

TableCell cell4 = new TableCell();
cell4.Attributes.Add("Width", "20%");
cell4.Text = "订单明细";
cell4.Attributes.Add("Style", "font-weight:bold;");
cell4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr0.Cells.Add(cell4);

table.Rows.Add(tr0);

TableRow tr = new TableRow();
TableCell cell6 = new TableCell();
cell6.ID = "txtname";
cell6.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView3.Rows.Count]["BName"].ToString() == "")
{
cell6.Text = "";
}
else
{
cell6.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["BName"].ToString();
}
tr.Cells.Add(cell6);

TableCell cell8 = new TableCell();
cell8.ID = "txtcode";
cell8.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView3.Rows.Count]["Billcode"].ToString() == "")
{
cell8.Text = "";
}
else
{
cell8.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["Billcode"].ToString();
}
tr.Cells.Add(cell8);

TableCell cell10 = new TableCell();
cell10.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView3.Rows.Count]["explain"].ToString() == "")
{
cell10.Text = "";
}
else
{
cell10.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["explain"].ToString();
}
tr.Cells.Add(cell10);

TableCell cell7 = new TableCell();
cell7.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView3.Rows.Count]["status"].ToString().Equals("4"))
{
cell7.ForeColor = System.Drawing.Color.Green;
}
else
{
cell7.ForeColor = System.Drawing.Color.Red;
}
cell7.Text = getstatus(ds.Tables[0].Rows[GridView3.Rows.Count]["status"].ToString());

if (ds.Tables[0].Rows[GridView3.Rows.Count]["status"].ToString() == "5")
{
cell7.Text = "已完成";
}
tr.Cells.Add(cell7);

TableCell cell9 = new TableCell();
Button btnmingxi = new Button();
btnmingxi.ID = "btn_mingxi";
btnmingxi.Text = "详情";
btnmingxi.PreRender += new EventHandler(btn_mingxi_Click);
btnmingxi.CommandArgument = ds.Tables[0].Rows[GridView3.Rows.Count]["Billcode"].ToString();
cell9.Controls.Add(btnmingxi);
cell9.Attributes.Add("Width", "20%");
tr.Cells.Add(cell9);

table.Rows.Add(tr);
//=================================================第二个TR
TableRow tr1 = new TableRow();
TableCell c0 = new TableCell();
c0.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["gjpOrderId"].ToString();
c0.Style.Add("display", "none");
tr1.Cells.Add(c0);

TableCell c1 = new TableCell();
c1.Text = "付款方式";
c1.Attributes.Add("Width", "20%");
c1.Attributes.Add("Style", "font-weight:bold;");
c1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c1);

TableCell c2 = new TableCell();
c2.Attributes.Add("Width", "20%");
c2.Text = "订单金额";
c2.Attributes.Add("Style", "font-weight:bold;");
c2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c2);

TableCell c3 = new TableCell();
c3.Attributes.Add("Width", "20%");
c3.Text = "应收金额";
c3.Attributes.Add("Style", "font-weight:bold;");
c3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c3);

TableCell c4 = new TableCell();
c4.Attributes.Add("Width", "20%");
c4.Text = "实收金额/余额付";
c4.Attributes.Add("Style", "font-weight:bold;");
c4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c4);

TableCell c5 = new TableCell();
c5.Attributes.Add("Width", "20%");
c5.Text = "欠款";
c5.Attributes.Add("Style", "font-weight:bold;");
c5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
tr1.Cells.Add(c5);
table.Rows.Add(tr1);
TableRow tr2 = new TableRow();

TableCell c6 = new TableCell();
c6.Attributes.Add("Width", "20%");
c6.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["payType"].ToString();//this.getpay(ds.Tables[0].Rows[GridView3.Rows.Count]["payType"].ToString());
c6.RowSpan = 2;
tr2.Cells.Add(c6);

TableCell c7 = new TableCell();
c7.Attributes.Add("Width", "20%");
if (ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString() == "")
{
c7.Text = "";
}
else
{
c7.Text = "¥" + Convert.ToDouble(ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"]).ToString("N");
}
c7.RowSpan = 2;
tr2.Cells.Add(c7);

//TableCell c5 = new TableCell();
//c5.Text = "总金额";
//c5.Attributes.Add("Style", "font-weight:bold;");
//c5.BackColor = System.Drawing.Color.FromName("#5D7B9D");
//c5.Attributes.Add("Width", "20%");
//tr2.Cells.Add(c5);
string bill = ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString();
//string strtui = "select money from OrderReturnGoods where ";
TableCell c8 = new TableCell();
if (ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString() == "")
{
c8.Text = "";
}
else
{
if (ds.Tables[0].Rows[GridView3.Rows.Count]["yingshou"] != DBNull.Value && ds.Tables[0].Rows[GridView3.Rows.Count]["yingshou"] != null)
{
c8.Text = "¥" + Convert.ToDouble(ds.Tables[0].Rows[GridView3.Rows.Count]["yingshou"]).ToString("N");
}
else
{

c8.Text = "¥" + Convert.ToDouble(ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"]).ToString("N");

}

}
c8.Attributes.Add("Width", "20%");
c8.RowSpan = 2;
tr2.Cells.Add(c8);

//TableCell c55 = new TableCell();
//c55.Text = "下单日期";
//c55.Attributes.Add("Style", "font-weight:bold;");
//c55.BackColor = System.Drawing.Color.FromName("#5D7B9D");
//c55.Attributes.Add("Width", "20%");
//tr2.Cells.Add(c55);

TableCell c9 = new TableCell();
if (ds.Tables[0].Rows[GridView3.Rows.Count]["reallyPrice"].ToString() == "")
{
double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}


}

}


c9.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");

}
else
{
double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}


}

}


c9.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");

}
c9.Attributes.Add("Width", "20%");
c9.RowSpan = 2;
tr2.Cells.Add(c9);
TableCell c10 = new TableCell();
string qiankuan = "";
//if (ds.Tables[0].Rows[GridView3.Rows.Count]["reallyPrice"].ToString() == "")
//{
// qiankuan = (Convert.ToDouble(ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString()) - 0).ToString("N");
//}
//if (ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString() == "")
//{
// qiankuan = (0 - Convert.ToDouble(ds.Tables[0].Rows[GridView3.Rows.Count]["reallyPrice"].ToString())).ToString("N");
//}
//if (ds.Tables[0].Rows[GridView3.Rows.Count]["reallyPrice"].ToString() == "" && ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString() == "")
//{ qiankuan = "0"; }
//if (ds.Tables[0].Rows[GridView3.Rows.Count]["reallyPrice"].ToString() != "" && ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString() != "")
//{
//qiankuan = (Convert.ToDouble(ds.Tables[0].Rows[GridView3.Rows.Count]["yingshou"].ToString()) - 0).ToString("N");
if (ds.Tables[0].Rows[GridView3.Rows.Count]["yingshou"] != DBNull.Value && ds.Tables[0].Rows[GridView3.Rows.Count]["yingshou"] != null)
{
qiankuan = (Convert.ToDouble(ds.Tables[0].Rows[GridView3.Rows.Count]["yingshou"].ToString()) - 0).ToString("N");
}
else
{

qiankuan = "0";

}
//- Convert.ToDouble(ds.Tables[0].Rows[GridView3.Rows.Count]["reallyPrice"].ToString())
//}
string strqiankuansum = "select sum(cast(huankje as decimal(18,2))) from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqksum = DbHelper.DAL.DateSet(strqiankuansum).Tables[0];
double huanke = 0;
try
{
if (dqksum.Rows.Count > 0)
{
if (Convert.IsDBNull(dqksum.Rows[0][0]))
{

}
else
{
//huanke = Convert.ToDouble(dqksum.Rows[0][0]);
double tempd = 0;
if (double.TryParse(dqksum.Rows[0][0].ToString(), out tempd))
{

huanke = Convert.ToDouble(tempd);

}
}
}
}
catch (Exception ex)
{
huanke = 0;

}
if (Convert.ToDouble(qiankuan) - huanke > 0)
{
table.BackColor = System.Drawing.ColorTranslator.FromHtml("#fef1bd");
c10.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffff00");
}
string qiankuanstr = Math.Round((Convert.ToDouble(qiankuan) - huanke), 2).ToString();

c10.Text = "¥" + qiankuanstr;
c10.Attributes.Add("Width", "20%");
c10.RowSpan = 2;
tr2.Cells.Add(c10);

table.Rows.Add(tr2);

TableRow tr2_1 = new TableRow();
TableCell c9_1 = new TableCell();
if (ds.Tables[0].Rows[GridView3.Rows.Count]["reallyPrice"].ToString() == "")
{

double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}


}

}


c9_1.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");

}
else
{
double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}


}

}


c9_1.Text = "¥" + Convert.ToDouble(qiankuanjine).ToString("N");

}
c9_1.Attributes.Add("Width", "20%");
c9_1.RowSpan = 2;
tr2_1.Cells.Add(c9_1);
table.Rows.Add(tr2_1);


//=================================================欠款显示
if (Convert.ToDouble(qiankuan) > 0)
{
double qiankuanjine = 0;
string str = "select * from [qiankuanbiao] where [BillNumberId]='" + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + "'";
DataTable dqk = DbHelper.DAL.DateSet(str).Tables[0];
if (dqk.Rows.Count > 0)
{
for (int i = 0; i < dqk.Rows.Count; i++)
{
//qiankuanjine = qiankuanjine + Convert.ToDouble(dqk.Rows[i]["huankje"]);
double tempd = 0;
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{

qiankuanjine = qiankuanjine + Convert.ToDouble(tempd);

}
if (dqk.Rows.Count == 1)
{
TableRow tr03 = new TableRow();
TableCell d1 = new TableCell();
d1.Text = "支付方式";
d1.Attributes.Add("Style", "font-weight:bold;");
d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d1.Attributes.Add("Width", "20%");
tr03.Cells.Add(d1);

TableCell d2 = new TableCell();
d2.Text = "支付时间";
d2.Attributes.Add("Style", "font-weight:bold;");
d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d2.Attributes.Add("Width", "20%");
tr03.Cells.Add(d2);

TableCell d3 = new TableCell();
d3.Text = "还款金额";
d3.Attributes.Add("Style", "font-weight:bold;");
d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d3.Attributes.Add("Width", "20%");
tr03.Cells.Add(d3);

TableCell d4 = new TableCell();
d4.Text = "还款率";
d4.Attributes.Add("Style", "font-weight:bold;");
d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d4.Attributes.Add("Width", "20%");
tr03.Cells.Add(d4);

TableCell d5 = new TableCell();
d5.Text = "操作";
d5.Attributes.Add("Style", "font-weight:bold;");
d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d5.Attributes.Add("Width", "20%");
tr03.Cells.Add(d5);
table.Rows.Add(tr03);

TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
//d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}

d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView3.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView3.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView3.Rows.Count]["Billcode"].ToString();
d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
if (Convert.ToDouble(qiankuan) <= qiankuanjine)
{
btn.Enabled = false;
btn1.Enabled = false;
}
//btn变灰
btn.Enabled = false;
btn1.Enabled = false;
}
else
{
if (i == dqk.Rows.Count - 1)
{
TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
//d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}

d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView3.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView3.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView3.Rows.Count]["Billcode"].ToString();
d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
if (Convert.ToDouble(qiankuan) <= qiankuanjine)
{
btn.Enabled = false;
btn1.Enabled = false;
}
//btn变灰
btn.Enabled = false;
btn1.Enabled = false;
}
else
{
if (i == 0)
{
TableRow tr03 = new TableRow();
TableCell d1 = new TableCell();
d1.Text = "支付方式";
d1.Attributes.Add("Style", "font-weight:bold;");
d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d1.Attributes.Add("Width", "20%");
tr03.Cells.Add(d1);

TableCell d2 = new TableCell();
d2.Text = "支付时间";
d2.Attributes.Add("Style", "font-weight:bold;");
d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d2.Attributes.Add("Width", "20%");
tr03.Cells.Add(d2);

TableCell d3 = new TableCell();
d3.Text = "还款金额";
d3.Attributes.Add("Style", "font-weight:bold;");
d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d3.Attributes.Add("Width", "20%");
tr03.Cells.Add(d3);

TableCell d4 = new TableCell();
d4.Text = "还款率";
d4.Attributes.Add("Style", "font-weight:bold;");
d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d4.Attributes.Add("Width", "20%");
tr03.Cells.Add(d4);

TableCell d5 = new TableCell();
d5.Text = "操作";
d5.Attributes.Add("Style", "font-weight:bold;");
d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d5.Attributes.Add("Width", "20%");
tr03.Cells.Add(d5);
table.Rows.Add(tr03);

TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
//d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}

d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
//btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
//d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
//btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView3.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView3.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView3.Rows.Count]["Billcode"].ToString();
//d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
}
else
{
TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = dqk.Rows[i]["zhifufs"].ToString();

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = dqk.Rows[i]["zhifusj"].ToString();
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
//d8.Text = "¥" + Convert.ToDouble(dqk.Rows[i]["huankje"]).ToString("N");
if (double.TryParse(dqk.Rows[i]["huankje"].ToString(), out tempd))
{


d8.Text = "¥" + Convert.ToDouble(tempd).ToString("N");
}
else
{
d8.Text = "¥0";
}

d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = Math.Round((qiankuanjine / Convert.ToDouble(qiankuan) * 100), 2).ToString() + "%"; //dqk.Rows[i]["huanklv"].ToString() + "%";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
//d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView3.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView3.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView3.Rows.Count]["Billcode"].ToString();
//d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
}

}
}
}
}
else
{
TableRow tr03 = new TableRow();
TableCell d1 = new TableCell();
d1.Text = "支付方式";
d1.Attributes.Add("Style", "font-weight:bold;");
d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d1.Attributes.Add("Width", "20%");
tr03.Cells.Add(d1);

TableCell d2 = new TableCell();
d2.Text = "支付时间";
d2.Attributes.Add("Style", "font-weight:bold;");
d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d2.Attributes.Add("Width", "20%");
tr03.Cells.Add(d2);

TableCell d3 = new TableCell();
d3.Text = "还款金额";
d3.Attributes.Add("Style", "font-weight:bold;");
d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d3.Attributes.Add("Width", "20%");
tr03.Cells.Add(d3);

TableCell d4 = new TableCell();
d4.Text = "还款率";
d4.Attributes.Add("Style", "font-weight:bold;");
d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d4.Attributes.Add("Width", "20%");
tr03.Cells.Add(d4);

TableCell d5 = new TableCell();
d5.Text = "操作";
d5.Attributes.Add("Style", "font-weight:bold;");
d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
d5.Attributes.Add("Width", "20%");
tr03.Cells.Add(d5);
table.Rows.Add(tr03);

TableRow tr04 = new TableRow();
TableCell d6 = new TableCell();
d6.ID = "zffs";
d6.Text = "<select id='xingjia' disabled="disabled"><option>现金</option><option>微信</option><option>支付宝</option><option>余额</option></select>";

d6.Attributes.Add("Width", "20%");
tr04.Cells.Add(d6);

TableCell d7 = new TableCell();
d7.ID = "zfsj";
d7.Text = "";
d7.Attributes.Add("Width", "20%");
tr04.Cells.Add(d7);

TableCell d8 = new TableCell();
d8.ID = "hkje";
d8.Text = "";
d8.Attributes.Add("contentEditable", "true");
d8.Attributes.Add("Width", "20%");
tr04.Cells.Add(d8);

TableCell d9 = new TableCell();
d9.ID = "hkl";
d9.Text = "";
d9.Attributes.Add("Width", "20%");
tr04.Cells.Add(d9);

TableCell d10 = new TableCell();
Button btn = new Button();
btn.ID = "btn_addqiankuan";
btn.Text = "添加";
btn.OnClientClick = "addqiankuan(this);return false;";
d10.Controls.Add(btn);
Button btn1 = new Button();
btn1.ID = "btn_addbaocun";
btn1.Text = "保存";
btn1.OnClientClick = "huanqian(this," + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + ",'" + ds.Tables[0].Rows[GridView3.Rows.Count]["btypeid"].ToString() + "','" + ds.Tables[0].Rows[GridView3.Rows.Count]["BName"].ToString() + "','" + this.UserId + "');return false;";
//btn1.Click += new EventHandler(btn_addqiankuan_Click);
btn.CommandArgument = ds.Tables[0].Rows[GridView3.Rows.Count]["Billcode"].ToString();

//btn变灰
btn.Enabled = false;
btn1.Enabled = false;

d10.Controls.Add(btn1);
d10.Attributes.Add("Width", "20%");
tr04.Cells.Add(d10);
table.Rows.Add(tr04);
}


}

//if (Convert.ToDouble(qiankuan) > 0)
//{

// TableRow tr03 = new TableRow();
// TableCell d1 = new TableCell();
// d1.Text = "支付方式";
// d1.Attributes.Add("Style", "font-weight:bold;");
// d1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d1.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d1);

// TableCell d2 = new TableCell();
// d2.Text = "支付时间";
// d2.Attributes.Add("Style", "font-weight:bold;");
// d2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d2.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d2);

// TableCell d3 = new TableCell();
// d3.Text = "还款金额";
// d3.Attributes.Add("Style", "font-weight:bold;");
// d3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d3.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d3);

// TableCell d4 = new TableCell();
// d4.Text = "还款率";
// d4.Attributes.Add("Style", "font-weight:bold;");
// d4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d4.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d4);

// TableCell d5 = new TableCell();
// d5.Text = "操作";
// d5.Attributes.Add("Style", "font-weight:bold;");
// d5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
// d5.Attributes.Add("Width", "20%");
// tr03.Cells.Add(d5);
// table.Rows.Add(tr03);

// string str = "select * from [qiankuanbiao] where [billcode]='" + ds.Tables[0].Rows[GridView3.Rows.Count]["Billcode"].ToString()+"'";
// ShujuBand(str);

// TableRow tr04 = new TableRow();
// TableCell d6 = new TableCell();
// d6.ID = "zffs";
// d6.Text = "<select id='xingjia'><option>现金全收</option><option>现金半收</option><option>现金不收</option><option>微信支付</option><option>其他</option></select>";

// d6.Attributes.Add("contentEditable", "true");
// d6.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d6);

// TableCell d7 = new TableCell();
// d7.ID = "zfsj";
// d7.Text = "";
// d7.Attributes.Add("contentEditable", "true");
// d7.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d7);

// TableCell d8 = new TableCell();
// d8.ID = "hkje";
// d8.Text = "";
// d8.Attributes.Add("contentEditable", "true");
// d8.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d8);

// TableCell d9 = new TableCell();
// d9.ID = "hkl";
// d9.Text = "";
// d9.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d9);

// TableCell d10 = new TableCell();
// Button btn = new Button();
// btn.ID = "btn_addqiankuan";
// btn.Text = "添加";
// btn.OnClientClick = "addqiankuan(this);return false;";
// d10.Controls.Add(btn);
// Button btn1 = new Button();
// btn1.ID = "btn_addbaocun";
// btn1.Text = "保存";
// btn1.OnClientClick = "huanqian(this);return false;";
// //btn1.Click += new EventHandler(btn_addqiankuan_Click);
// btn.CommandArgument = ds.Tables[0].Rows[GridView3.Rows.Count]["Billcode"].ToString();
// d10.Controls.Add(btn1);
// d10.Attributes.Add("Width", "20%");
// tr04.Cells.Add(d10);
// table.Rows.Add(tr04);

//}
//=================================================退单显示
//TableRow tr05 = new TableRow();
//TableCell e1 = new TableCell();
//e1.Text = "退货单编号";
//e1.Attributes.Add("Style", "font-weight:bold;");
//e1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e1.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e1);

//TableCell e2 = new TableCell();
//e2.Text = "";
//e2.Attributes.Add("Style", "font-weight:bold;");
//e2.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e2.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e2);

//TableCell e3 = new TableCell();
//e3.Text = "检查";
//e3.Attributes.Add("Style", "font-weight:bold;");
//e3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e3.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e3);

//TableCell e4 = new TableCell();
//e4.Text = "";
//e4.Attributes.Add("Style", "font-weight:bold;");
//e4.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e4.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e4);

//TableCell e5 = new TableCell();
//e5.Text = "明细";
//e5.Attributes.Add("Style", "font-weight:bold;");
//e5.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//e5.Attributes.Add("Width", "20%");
//tr05.Cells.Add(e5);
//table.Rows.Add(tr05);

//TableRow tr06 = new TableRow();
//TableCell e6 = new TableCell();
//e6.Text = "¥" + ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString();
//e6.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e6);

//TableCell e7 = new TableCell();
//e7.Text = "";
//e7.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e7);

//TableCell e8 = new TableCell();
//e8.Text = "¥" + ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString();
//e8.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e8);

//TableCell e9 = new TableCell();
//e9.Text = "";
//e9.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e9);

//TableCell e10 = new TableCell();
//e10.Text = "¥" + ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString();
//e10.Attributes.Add("Width", "20%");
//tr06.Cells.Add(e10);
//table.Rows.Add(tr06);

//=================================================第四个TR
string sql01 = " select COUNT(*) as num from Orders as o,OrderReturnGoods as oo where o.gjpOrderId = oo.billNumberId ";
DataSet ds01 = DbHelper.DAL.DateSet(sql01);
if (Convert.ToInt32(ds01.Tables[0].Rows[0]["num"].ToString()) > 0)
{
DataSet ds1 = this.getReturnGoods(ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString());
//if (ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString().Equals(ds.Tables[0].Rows[0]["gjpOrderId"].ToString())) {
TableRow tr33 = new TableRow();
TableCell get1 = new TableCell();
get1.Text = "实际返品信息";
get1.Attributes.Add("Style", "10%;");
get1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
get1.Attributes.Add("Style", "font-weight:bold;");
tr33.Cells.Add(get1);

TableCell getF = new TableCell();
//getF.Attributes.Add("Style", "90%;");
getF.ColumnSpan = 4;
Table tab1 = new Table();
tab1.CssClass = "tab1";
if (Convert.ToInt32(ds1.Tables[0].Rows.Count) > 0)
{
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
if (i == 0)
{
TableRow tr01 = new TableRow();
TableCell c301 = new TableCell();
c301.Text = "商品号";
c301.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c301.Attributes.Add("Style", "font-weight:bold;");
c301.Attributes.Add("Width", "25%");
c301.ColumnSpan = 0;
tr01.Cells.Add(c301);
//


TableCell c30 = new TableCell();
c30.Text = "商品名";
c30.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c30.Attributes.Add("Style", "font-weight:bold;");
c30.Attributes.Add("Width", "25%");
c30.ColumnSpan = 0;
tr01.Cells.Add(c30);

TableCell c32 = new TableCell();
c32.Text = "返品数量";
c32.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c32.Attributes.Add("Style", "font-weight:bold;");
c32.Attributes.Add("Width", "25%");
c32.ColumnSpan = 0;
tr01.Cells.Add(c32);

TableCell c34 = new TableCell();
c34.Text = "返品单价";
c34.BackColor = System.Drawing.Color.FromName("#CAE8EA");
c34.Attributes.Add("Style", "font-weight:bold;");
c34.Attributes.Add("Width", "25%");
c34.ColumnSpan = 0;
tr01.Cells.Add(c34);


//TableCell c40 = new TableCell();
//c40.Attributes.Add("Width", "20%");
//c40.Text = "";
//c40.Attributes.Add("Style", "font-weight:bold;");
//c40.BackColor = System.Drawing.Color.FromName("#CAE8EA");
//tr01.Cells.Add(c40);

TableRow tr02 = new TableRow();

TableCell c311 = new TableCell();
c311.Text = ds1.Tables[0].Rows[i]["ptypeid"].ToString();
c311.Attributes.Add("Width", "25%");
tr02.Cells.Add(c311);

TableCell c31 = new TableCell();
c31.Text = ds1.Tables[0].Rows[i]["goodsName"].ToString();
c31.Attributes.Add("Width", "25%");
tr02.Cells.Add(c31);

TableCell c33 = new TableCell();
c33.Attributes.Add("Width", "25%");
c33.Text = ds1.Tables[0].Rows[i]["qty"].ToString() + ds1.Tables[0].Rows[i]["unitName"].ToString();
tr02.Cells.Add(c33);

TableCell c35 = new TableCell();
c35.Text = "¥" + Convert.ToDouble(ds1.Tables[0].Rows[i]["Price"]).ToString("N");
c35.Attributes.Add("Width", "25%");
tr02.Cells.Add(c35);

//TableCell c42 = new TableCell();
//c42.Attributes.Add("Width", "20%");
//c42.Text = "";
//tr02.Cells.Add(c42);

tab1.Rows.Add(tr01);
tab1.Rows.Add(tr02);
}
else
{
TableRow tr02 = new TableRow();

TableCell c311 = new TableCell();
c311.Text = ds1.Tables[0].Rows[i]["ptypeid"].ToString();
c311.Attributes.Add("Width", "25%");
tr02.Cells.Add(c311);

TableCell c31 = new TableCell();
c31.Text = ds1.Tables[0].Rows[i]["goodsName"].ToString();
c31.Attributes.Add("Width", "25%");
tr02.Cells.Add(c31);

TableCell c33 = new TableCell();
c33.Attributes.Add("Width", "25%");
c33.Text = ds1.Tables[0].Rows[i]["qty"].ToString() + ds1.Tables[0].Rows[i]["unitName"].ToString();
tr02.Cells.Add(c33);

TableCell c35 = new TableCell();
c35.Text = "¥" + Convert.ToDouble(ds1.Tables[0].Rows[i]["Price"]).ToString("N");
c35.Attributes.Add("Width", "25%");
tr02.Cells.Add(c35);

//TableCell c42 = new TableCell();
//c42.Attributes.Add("Width", "20%");
//c42.Text = "";
//tr02.Cells.Add(c42);

tab1.Rows.Add(tr02);
}
}
getF.Controls.Add(tab1);
tr33.Cells.Add(getF);
table.Rows.Add(tr33);
}
else
{
TableRow tr01 = new TableRow();
TableCell c301 = new TableCell();
c301.Text = "无返品";
c301.Attributes.Add("Style", "font-weight:bold;text-align:center;font-size:15px;");
c301.Attributes.Add("Width", "100%");
c301.ColumnSpan = 8;
tr01.Cells.Add(c301);

tab1.Rows.Add(tr01);
getF.Controls.Add(tab1);
tr33.Cells.Add(getF);
table.Rows.Add(tr33);
}
}


string ordersql = " select COUNT(*) as num from Orders as o,OrderReturnGoods as oo where o.gjpOrderId = oo.billNumberId ";
DataSet dst = DbHelper.DAL.DateSet(ordersql);
if (!ds.Tables[0].Rows[GridView3.Rows.Count]["status"].ToString().Equals("3"))
{
if (Convert.ToInt32(dst.Tables[0].Rows[0]["num"].ToString()) > 0)
{
string getOrd = " select * from view_selectOrderfanpin where BillNumberId =" + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString();
DataSet dt = DbHelper.DAL.DateSet(getOrd);
if (dt.Tables[0].Rows.Count > 0)
{
TableRow tr11 = new TableRow();
TableCell ce0 = new TableCell();
ce0.Text = dt.Tables[0].Rows[0]["BillNumberId"].ToString();
ce0.Style.Add("display", "none");
tr11.Cells.Add(ce0);

TableCell ce1 = new TableCell();
ce1.Text = "返品订单号";
ce1.Attributes.Add("Style", "font-weight:bold;text-align:center;");
ce1.Attributes.Add("Width", "10%");
//ce1.BackColor = System.Drawing.Color.FromName("#5D7B9D");
tr11.Cells.Add(ce1);

TableCell ce2 = new TableCell();
ce2.Attributes.Add("Width", "20%");
ce2.ID = "TextBoxsave";
ce2.Text = "";
ce2.Attributes.Add("contentEditable", "true");
ce2.Attributes.Add("Width", "20%");
tr11.Cells.Add(ce2);

TableCell ce3 = new TableCell();
ce3.Attributes.Add("Width", "20%");
ce3.Attributes.Add("Style", "text-align:center;");
Button button3 = new Button();
button3.ID = "tijiao13";
button3.CssClass = "tijiao3";
button3.Attributes.Add("Style", "Width:90px;height: 30px;background-color:#CAE8EA;font-weight: bold;font-size: 14px;text-align:center;");
button3.Text = "校 验";
//button3.Click += new EventHandler(CheckButton_Click);
button3.OnClientClick = "jianyan(this);return false;";
ce3.Controls.Add(button3);
tr11.Cells.Add(ce3);

TableCell ce22 = new TableCell();
ce22.Attributes.Add("Width", "20%");
ce22.Text = "";
ce22.Attributes.Add("Width", "20%");
tr11.Cells.Add(ce22);

TableCell ce32 = new TableCell();
ce32.Attributes.Add("Width", "20%");
ce32.Text = "";
ce32.Attributes.Add("Width", "20%");
tr11.Cells.Add(ce32);

DataSet ds2 = this.getReturnGoods(ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString());
if (Convert.ToInt32(ds2.Tables[0].Rows.Count) > 0)
{
table.Rows.Add(tr11);
}
}
}
}
//=================================================第三个TR
TableRow trt = new TableRow();

TableCell cellt1 = new TableCell();
cellt1.Text = "司机备注";
cellt1.Attributes.Add("Style", "font-weight:bold;");
cellt1.Attributes.Add("Width", "25%");
cellt1.BackColor = System.Drawing.Color.FromName("#CAE8EA");
trt.Cells.Add(cellt1);

TableCell cellt3 = new TableCell();
cellt3.Attributes.Add("Width", "25%");
cellt3.Text = "客服备注(可输入)";
cellt3.Attributes.Add("Style", "font-weight:bold;");
cellt3.BackColor = System.Drawing.Color.FromName("#CAE8EA");
cellt3.ColumnSpan = 2;
trt.Cells.Add(cellt3);

TableCell cellt5 = new TableCell();
cellt5.Attributes.Add("Width", "25%");
cellt5.Text = "财务备注";
cellt5.Attributes.Add("Style", "font-weight:bold;");
cellt5.BackColor = System.Drawing.Color.FromName("#CAE8EA");

trt.Cells.Add(cellt5);

TableCell cellt7 = new TableCell();
cellt7.Attributes.Add("Width", "25%");
cellt7.Text = "可用余额";
cellt7.Attributes.Add("Style", "font-weight:bold;");
cellt7.BackColor = System.Drawing.Color.FromName("#CAE8EA");
trt.Cells.Add(cellt7);

table.Rows.Add(trt);

table.Rows.Add(trt);

TableRow trtt = new TableRow();
TableCell cellt6 = new TableCell();
cellt6.ID = "drivercomment";
cellt6.Attributes.Add("Width", "33%");
if (ds.Tables[0].Rows[GridView3.Rows.Count]["beizhu"].ToString() == "")
{
cellt6.Text = "&nbsp; ";
}
else
{
cellt6.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["beizhu"].ToString();
}
trtt.Cells.Add(cellt6);

TableCell cellt8 = new TableCell();
cellt8.ID = "servicecomment";
cellt8.Attributes.Add("Width", "33%");
if (ds.Tables[0].Rows[GridView3.Rows.Count]["kefubeizhu"].ToString() == "")
{
cellt8.Text = "";
cellt8.Attributes.Add("contentEditable", "true");
}
else
{
cellt8.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["kefubeizhu"].ToString();
}
cellt8.ColumnSpan = 2;
trtt.Cells.Add(cellt8);

TableCell cellt10 = new TableCell();
cellt10.Attributes.Add("Width", "34%");
if (ds.Tables[0].Rows[GridView3.Rows.Count]["caiwubeizhu"].ToString() == "")
{
cellt10.Text = "";
}
else
{
cellt10.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["caiwubeizhu"].ToString();
}

trtt.Cells.Add(cellt10);


TableCell cellt9 = new TableCell();
cellt9.Attributes.Add("Width", "25%");
if (ds.Tables[0].Rows[GridView3.Rows.Count]["yukuan"].ToString() == "")
{
cellt9.Text = "0";
}
else
{
cellt9.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["yukuan"].ToString();
}

trtt.Cells.Add(cellt9);


table.Rows.Add(trtt);


//if (!ds.Tables[0].Rows[GridView3.Rows.Count]["status"].ToString().Equals("9"))
//{
// //if (!ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString().Equals(ds.Tables[0].Rows[0]["gjpOrderId"].ToString()))
// //{
// string billNumberId = ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString();
// string btypeid = ds.Tables[0].Rows[GridView3.Rows.Count]["btypeid"].ToString();
// string payType = ds.Tables[0].Rows[GridView3.Rows.Count]["payType"].ToString();
// string totalmoney = ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString();
// string reallyPrice = ds.Tables[0].Rows[GridView3.Rows.Count]["reallyPrice"].ToString();
// TableRow tr3 = new TableRow();

// TableCell cell331 = new TableCell();
// //cell331.Attributes.Add("Width", "100%");
// cell331.ColumnSpan = 5;
// Button button32 = new Button();
// button32.ID = "tijiao13xa";
// button32.CssClass = "tijiao3xa";
// button32.Attributes.Add("Style", "Width:150px;float:center;margin-right:15px;;font-weight:bold;background-color:#CAE8EA;height:30px;");
// button32.Text = "待 确 定 订 单";
// button32.OnClientClick = "daiqueren(this," + ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString() + ");return false;";
// //button32.Click += new EventHandler(daiqueren_Click);
// //button32.CommandArgument = ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString();
// cell331.Controls.Add(button32);
// //Button button31 = new Button();
// //button31.ID = "tijiao13xa";
// //button31.CssClass = "tijiao3xaa";
// //button31.Attributes.Add("Style", "Width:150px;float;center;margin-left:15px;font-weight:bold;background-color:#CAE8EA;height:30px; ");

// ////button31.Attributes.Add("Style","Visible:false;");
// //button31.Text = "确 定 订 单";
// //string obj = billNumberId + "," + btypeid + "," + payType + "," + totalmoney + "," + reallyPrice;
// //button31.OnClientClick = "queren('"+obj+"');return false;";
// ////button31.Click += new EventHandler(SaveButton_Click);
// //button31.CommandArgument = billNumberId + "," + btypeid + "," + payType + "," + totalmoney + "," + reallyPrice;
// //cell331.Controls.Add(button31);
// tr3.Cells.Add(cell331);

// //TableCell cell11 = new TableCell();
// //TextBox tb1 = new TextBox();
// //tb1.ID = "Text11";
// //tb1.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["billNumberId"].ToString();
// //tb1.Attributes.Add("Style", "display:none;border:0px");
// //cell11.Controls.Add(tb1);
// //tr3.Cells.Add(cell11);

// //TableCell cell22 = new TableCell();
// //TextBox tb2 = new TextBox();
// //tb2.ID = "Text12";
// //tb2.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["btypeid"].ToString();
// //tb2.Attributes.Add("Style", "display:none;border:0px");
// //cell22.Controls.Add(tb2);
// //tr3.Cells.Add(cell22);

// //TableCell cell33 = new TableCell();
// //TextBox tb3 = new TextBox();
// //tb3.ID = "Text13";
// //tb3.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["payType"].ToString();
// //tb3.Attributes.Add("Style", "display:none;border:0px");
// //cell33.Controls.Add(tb3);
// //tr3.Cells.Add(cell33);

// //TableCell cell44 = new TableCell();
// //TextBox tb4 = new TextBox();
// //tb4.ID = "Text14";
// //tb4.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["totalmoney"].ToString();
// //tb4.Attributes.Add("Style", "display:none;border:0px");
// //cell44.Controls.Add(tb4);
// //tr3.Cells.Add(cell44);

// //TableCell cell55 = new TableCell();
// //TextBox tb5 = new TextBox();
// //tb5.ID = "Text15";
// //tb5.Text = ds.Tables[0].Rows[GridView3.Rows.Count]["reallyPrice"].ToString();
// //tb5.Attributes.Add("Style", "display:none;border:0px");
// //cell55.Controls.Add(tb5);
// //tr3.Cells.Add(cell55);

// table.Rows.Add(tr3);
//}
e.Row.Cells[2].Controls.Add(table);
//if (e.Row.FindControl("ButtonOK") != null)
//{
// Button CtlButton = (Button)e.Row.FindControl("ButtonOK");
// CtlButton.Click += new EventHandler(OKButton_Click);
//}
}
}

#endregion

private void SaveButton_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
//GridViewRow gvr = (GridViewRow)button.Parent.Parent;
//string tt1 = GridView1.Rows[gvr.RowIndex].Cells[3].ToString();
//string tt2 = GridView1.Rows[gvr.RowIndex].Cells[4].ToString();
//string tt3 = GridView1.Rows[gvr.RowIndex].Cells[5].ToString();
//string tt4 = GridView1.Rows[gvr.RowIndex].Cells[6].ToString();
//string tt5 = GridView1.Rows[gvr.RowIndex].Cells[7].ToString();
string[] btn = button.CommandArgument.ToString().Split(',');
string tt1 = btn[0];
string tt2 = btn[1];
string tt3 = btn[2];
string tt4 = btn[3];
string tt5 = btn[4];
//TextBox tt1 = (TextBox)gvr.Cells[0].FindControl("Text11");//BillNumberId-订单id
//TextBox tt2 = (TextBox)gvr.Cells[1].FindControl("Text12");//btypeid-管家婆id
//TextBox tt3 = (TextBox)gvr.Cells[2].FindControl("Text13");//payType-支付类型
//TextBox tt4 = (TextBox)gvr.Cells[3].FindControl("Text14");//total-总钱数
//TextBox tt5 = (TextBox)gvr.Cells[4].FindControl("Text15");//reallyPrice-支付金额
//Decimal price = 0;

//string getCustomer_Sql = " select predeposit from Customer where gjp_btype_id= '" + tt2 + "'";
//DataSet dd = DbHelper.DAL.DateSet(getCustomer_Sql);

//if (tt3.Equals("2"))
//{
// Decimal ceshi = Convert.ToDecimal(tt4) - Convert.ToDecimal(tt5);
// price = Convert.ToDecimal(Convert.ToDecimal(dd.Tables[0].Rows[0]["predeposit"]) - ceshi);
//}
//else if (tt3.Equals("3"))
//{
// price = Convert.ToDecimal(Convert.ToDecimal(dd.Tables[0].Rows[0]["predeposit"]) - Convert.ToDecimal(tt4));
//}


//string updOrder_Sql = " update Orders set status = '3' where gjpOrderId = " + tt1;
//DbHelper.DAL.DateSet(updOrder_Sql);

//string updCustomer_Sql = " update Customer set predeposit=" + price + " where gjp_btype_id= '" + tt2 + "'";
//DbHelper.DAL.DateSet(updCustomer_Sql);

//Response.Redirect(Request.Url.ToString());
}


private void CheckButton_Click(object sender, EventArgs e)
{
string gjp = DbHelper.DAL.GJPSqlServer;
Button button = (Button)sender;
TableRow gvr = (TableRow)button.Parent.Parent;
InsusJsUtility objJs = new InsusJsUtility();
TextBox tt = (TextBox)gvr.Cells[2].FindControl("TextBoxsave");
if (tt.Text != "")
{
string sql_ord = " select s.*,u.FullName as unitName,t.* from ptype as t,saleBackBill as s,PType_Units as u where t.typeId=s.PtypeId and s.UnitID=u.UnitsId and s.BillNumberId in (select BillNumberId from BillIndex as b where b.BillType=45 and b.BillCode='" + tt.Text + "' and (b.etypeid<>'0000100051' or b.etypeid is null) )";
DataSet ds = GJPDbHelper.DAL.DateSet(sql_ord);
if (ds.Tables[0].Rows.Count.ToString() == "0")
{
//objJs.JsAlert("无数据!!");
tt.Text = "";
tt.Focus();
return;
}
else
{

Table table = (Table)button.Parent.Parent.Parent;
//Table table = new Table();
TableRow tr33 = new TableRow();
tr33.CssClass = "tr33";
TableCell get1 = new TableCell();
get1.Text = "管家婆返品信息";
get1.Attributes.Add("Style", "10%;");
get1.BackColor = System.Drawing.Color.FromName("#5D7B9D");
get1.Attributes.Add("Style", "font-weight:bold;");
tr33.Cells.Add(get1);
//table.Rows.Add(tr33);

//Button btn = (Button)sender;
//table.Attributes.Add("cellspacing", "0");
//table.CssClass = "table1";

TableCell get2 = new TableCell();
get2.Attributes.Add("Style", "90%;");
get2.ColumnSpan = 8;

Table tb01 = new Table();
tb01.Attributes.Add("Style", "100%;");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TableRow tr = new TableRow();
TableCell cell0 = new TableCell();
TextBox tb1 = new TextBox();
tb1.ID = "TextBoxsave1";
tb1.Attributes.Add("Style", "200px;Display:none;");
cell0.Attributes.Add("Style", "Display:none;");
cell0.Controls.Add(tb1);
tb1.Text = ds.Tables[0].Rows[0]["Ptypeid"].ToString();
tr.Cells.Add(cell0);

TableCell cell1 = new TableCell();
cell1.Text = "返回商品号";
cell1.Attributes.Add("Style", "font-weight:bold;");
cell1.Attributes.Add("Width", "10%");
cell1.BackColor = System.Drawing.Color.FromName("#5D7B9D");
tr.Cells.Add(cell1);

TableCell cell2 = new TableCell();
cell2.Attributes.Add("Width", "20%");
cell2.Attributes.Add("Style", "border-bottom:0px solid #FFFFFF;");
cell2.Text = ds.Tables[0].Rows[0]["ptypeid"].ToString();
tr.Cells.Add(cell2);

TableCell cell3 = new TableCell();
cell3.Attributes.Add("Width", "10%");
cell3.Text = "返品商品名";
cell3.Attributes.Add("Style", "font-weight:bold;");
cell3.BackColor = System.Drawing.Color.FromName("#5D7B9D");
tr.Cells.Add(cell3);

TableCell cell4 = new TableCell();
cell4.Attributes.Add("Width", "20%");
cell4.Attributes.Add("Style", "border-bottom:0px solid #FFFFFF;");
cell4.Text = ds.Tables[0].Rows[i]["FullName"].ToString();
tr.Cells.Add(cell4);

TableCell cell5 = new TableCell();
cell5.Text = "返回数量";
cell5.Attributes.Add("Style", "font-weight:bold;");
cell5.BackColor = System.Drawing.Color.FromName("#5D7B9D");
cell5.Attributes.Add("Width", "10%");
tr.Cells.Add(cell5);

TableCell cell6 = new TableCell();
cell6.Text = Convert.ToInt32(ds.Tables[0].Rows[i]["qty"]).ToString() + ds.Tables[0].Rows[i]["unitName"].ToString();
cell6.Attributes.Add("Width", "5%");
cell6.Attributes.Add("Style", "border-bottom:0px solid #FFFFFF;");
tr.Cells.Add(cell6);

//TableCell cell7 = new TableCell();
//cell7.Attributes.Add("Width", "40%");
//cell7.ColumnSpan = 0;
//Button button31 = new Button();
//button31.ID = "tijiao13x";
//button31.CssClass = "tijiao3x";
//button31.Attributes.Add("Style", "Width:100px");
//button31.Text = "确定订单";
//button31.Click += new EventHandler(OKButton_Click);
//cell7.Controls.Add(button31);
TableCell c34 = new TableCell();
c34.Text = "返品单价";
c34.BackColor = System.Drawing.Color.FromName("#5D7B9D");
c34.Attributes.Add("Style", "font-weight:bold;");
c34.Attributes.Add("Width", "10%");
c34.ColumnSpan = 0;
tr.Cells.Add(c34);

TableCell c35 = new TableCell();
c35.Text = "¥" + Convert.ToDouble(ds.Tables[0].Rows[i]["SalePrice"].ToString());
c35.Attributes.Add("Width", "5%");
c35.Attributes.Add("Style", "border-bottom:0px solid #FFFFFF;");
tr.Cells.Add(c35);

tb01.Rows.Add(tr);
}
get2.Controls.Add(tb01);
tr33.Cells.Add(get2);
table.Rows.Add(tr33);

TableRow tr02 = new TableRow();
TableCell cell331 = new TableCell();
cell331.Attributes.Add("Width", "100%");
cell331.ColumnSpan = 8;
Button button31 = new Button();
button31.ID = "tijiao13xa";
button31.CssClass = "tijiao3xa";
button31.Attributes.Add("Style", "Width:150px;float: right;font-weight:bold;background-color:#5D7B9D;margin-right:365px;height:30px;");
button31.Text = "确定订单";
button31.Click += new EventHandler(SaveButton_Click);

cell331.Controls.Add(button31);
tr02.Cells.Add(cell331);
table.Rows.Add(tr02);

string dd = gvr.Cells[0].Text.ToString();
string sql01 = "select v.FullName as goodsName,p.FullName as unitName,o.qty as qty,o.ptypeid as ptypeid,s.price from view_selectOrderGoods v,view_selectOrderDetails as s,(select ptypeid,qty from Orders as o,OrderReturnGoods as oo where o.gjpOrderId = oo.billNumberId) o,suntest.dbo.PType_Units as p where v.typeid = o.ptypeid and v.SaleUnitId = p.UnitsId and s.billNumberId=" + dd;
DataSet ds01 = GJPDbHelper.DAL.DateSet(sql01);

string sql02 = " select t.FullName,cast(s.Qty as Int) as Qty,s.PtypeId,u.FullName as unitName,s.SalePrice from dbo.ptype as t,dbo.saleBackBill as s,dbo.PType_Units as u where t.typeId=s.PtypeId and s.UnitID=u.UnitsId and s.BillNumberId in (select BillNumberId from dbo.BillIndex as b where b.BillType=45 and b.BillCode='" + tt.Text + "' and (b.etypeid<>'0000100051' or b.etypeid is null))";
DataSet ds02 = GJPDbHelper.DAL.DateSet(sql02);

for (int j = 0; j < ds01.Tables[0].Rows.Count; j++)
{
if (ds01.Tables[0].Rows[j]["goodsName"].ToString().Trim().Equals(ds02.Tables[0].Rows[j]["FullName"].ToString().Trim()) && ds01.Tables[0].Rows[j]["unitName"].ToString().Trim().Equals(ds02.Tables[0].Rows[j]["unitName"].ToString().Trim()) && Convert.ToUInt32(ds01.Tables[0].Rows[j]["qty"]) == Convert.ToUInt32(ds02.Tables[0].Rows[j]["Qty"]) && ds01.Tables[0].Rows[j]["ptypeid"].ToString().Trim().Equals(ds02.Tables[0].Rows[j]["PtypeId"].ToString().Trim()) && ds01.Tables[0].Rows[j]["price"].ToString().Trim().Equals(ds02.Tables[0].Rows[j]["SalePrice"].ToString().Trim()))
{
get2.Controls.Add(tb01);
tr33.Cells.Add(get2);
table.Rows.Add(tr33);

cell331.Controls.Add(button31);
tr02.Cells.Add(cell331);
table.Rows.Add(tr02);
}
else
{
get2.Controls.Add(tb01);
tr33.Attributes.Add("Style", "background-color: #FF3030;");
tr33.Cells.Add(get2);
table.Rows.Add(tr33);

button31.Enabled = false;
cell331.Controls.Add(button31);
tr02.Cells.Add(cell331);
table.Rows.Add(tr02);
}
}
}
}
}

public DataSet getReturnGoods(string billnumberid)
{
DataSet dt = new DataSet();
string ordersql = " select COUNT(*) as num from Orders as o,OrderReturnGoods as oo where o.gjpOrderId = oo.billNumberId ";
DataSet dst = DbHelper.DAL.DateSet(ordersql);
if (Convert.ToInt32(dst.Tables[0].Rows[0]["num"].ToString()) > 0)
{
string getOrd = " select s.FullName as goodsName,og.qty as qty,s.ptypeid,s.unitsName as unitName,s.price from view_selectOrderDetails1_o as s right JOIN dbo.OrderReturnGoods as og ON s.billNumberId=og.billNumberId and s.ptypeid=og.ptypeid where og.billNumberId = "+billnumberid+"";
dt = DbHelper.DAL.DateSet(getOrd);
//for (int i = 0; i < dt.Tables[0].Rows.Count; i++) {
// txt = dt.Tables[0].Rows[i]["goodsName"].ToString() + " —— " + dt.Tables[0].Rows[i]["qty"].ToString() + " " + dt.Tables[0].Rows[i]["unitName"].ToString() + "</br>";
//}
return dt;
}
else
{
return dst;
}
}

public string getpay(string pay)
{
string getpay = "";
if (pay.Equals("1"))
{
getpay = "现金全收";
}
else if (pay.Equals("2"))
{
getpay = "现金半收";
}
else if (pay.Equals("3"))
{
getpay = "现金不收";
}
else if (pay.Equals("4"))
{
getpay = "微信支付";
}
else if (pay.Equals("5"))
{
getpay = "其他";
}
return getpay;
}
public string getCust(string billcode)
{
string txt = "";
string getnums = "select predeposit from Customer where gjp_btype_id in (select btypeid from view_selectOrderBill where Billcode='" + billcode + "')";
DataSet dts = DbHelper.DAL.DateSet(getnums);
for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
{
txt = dts.Tables[0].Rows[i]["predeposit"].ToString();
}
return txt;
}
protected void btn_addqiankuan_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
TableRow gvr = (TableRow)button.Parent.Parent;
C1GridViewRow gvr1 = (C1GridViewRow)button.Parent.Parent;
string Billcode = button.CommandArgument;
string zffs = gvr.Cells[0].Text;
string zfsj = gvr.Cells[1].Text;
string hkje = gvr.Cells[2].Text;
string hkl = gvr.Cells[3].Text;
string str = "insert into [qiankuanbiao] values('" + Billcode + "','" + zffs + "','" + zfsj + "','" + hkje + "','" + hkl + "','')";
DbHelper.DAL.ExecuteNonQuery(str);
}
protected void btn_mingxi_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
string tt2 = button.CommandArgument;
TableRow gvr = (TableRow)button.Parent.Parent;
string tt1 = gvr.Cells[1].Text;
button.Attributes.Add("onclick", "return dnnModal.show('/DesktopModules/duizhang_riqing/mingxi.aspx?billcode=" + tt2 + "&popUp=true',true,600,1000,false)");
}
protected void daiqueren_Click(object sender, EventArgs e)
{

}
protected void textbox_datebtn_Click(object sender, EventArgs e)
{
textbox1all.Text = "";
string state = this.textbox_state.Text.Trim();
string sql2 = "";
string datewhere = "";
if (this.textbox_date.Text == null || this.textbox_date.Text.Trim() == "") { }
else
{
datewhere = " and orderCreateTime='" + this.textbox_date.Text.Trim() + " 00:00:00.000'";
}
if (this.UserId.ToString() == "5")
{
sql2 = "select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null)) " + datewhere + " order by gjpOrderID desc";
}
else
{
if (!state.Equals(""))
{
string stuas = getfanstatus(state);

//sql2 = "select id,gjpOrderID,status,picPath from Orders as o where o.status='" + stuas + "' and gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null)) " + datewhere + " order by gjpOrderID desc";
sql2 = "select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null)) " + datewhere + " order by gjpOrderID desc";
}
else
{

//sql2 = "select id,gjpOrderID,status,picPath from Orders where gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null)) " + datewhere + " order by gjpOrderID desc";
sql2 = "select * from Orders left join ( select sum(CAST(qiankuanbiao.huankje as decimal(18,2)))as huankje,qiankuanbiao.BillNumberId from qiankuanbiao,AAyukuan_detail where AAyukuan_detail.zhuangtai=1 and AAyukuan_detail.BillNumberId=qiankuanbiao.BillNumberId group by qiankuanbiao.BillNumberId ) as AAyukuan_detail on Orders.gjpOrderId=AAyukuan_detail.BillNumberId where AAyukuan_detail.huankje>=Orders.yingshou and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null)) " + datewhere + " order by gjpOrderID desc";
}
}

DataSet ds2 = DbHelper.DAL.DateSet(sql2);
//if (ds2.Tables[0].Rows.Count > 0)
//{
this.GridView3.DataSource = ds2;
this.GridView3.DataBind();
//}
//else
//{

//}


}

protected void textbox_datebtnALL_Click(object sender, EventArgs e)
{
textbox1all.Text = "1";
string state = this.textbox_state.Text.Trim();
string sql2 = "";
if (this.UserId.ToString() == "5")
{
sql2 = "select id,gjpOrderID,status,picPath from Orders where gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null))";
}
else
{

if (!state.Equals(""))
{
string stuas = getfanstatus(state);

sql2 = "select id,gjpOrderID,status,picPath from Orders as o where o.status='" + stuas + "' and gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null))";
}
else
{

sql2 = "select id,gjpOrderID,status,picPath from Orders where gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null))";
}

}
DataSet ds2 = DbHelper.DAL.DateSet(sql2);
//if (ds2.Tables[0].Rows.Count > 0)
//{
this.GridView3.DataSource = ds2;
this.GridView3.DataBind();
//}
//else
//{

//}


}

protected void customerButton1_Click(object sender, EventArgs e)
{
string textboxc1 = CustomerTextbox1.Text.Trim();

string wherestring = "";
if (this.orderState.SelectedValue == "99")
{
wherestring = " (daiquren='0' or qiankuanzhuangtai='1') ";
}
else
{
if (this.orderState.SelectedValue == "1")
{
wherestring = " daiquren='1' and qiankuanzhuangtai='1' ";
}
else
{
wherestring = " (daiquren='0' or qiankuanzhuangtai='1') and status='" + this.orderState.SelectedValue + "' ";
}
}
string state = this.textbox_state.Text.Trim();
string sql = "";
string datewhere = "";
if (this.textbox_date1.Text == null || this.textbox_date1.Text.Trim() == "") { }
else
{
datewhere = " and orderCreateTime='" + this.textbox_date1.Text.Trim() + " 00:00:00.000'";
}
if (this.UserId.ToString() == "5")
{
sql = "select id,gjpOrderID,status,picPath from Orders where " + wherestring + " and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson ))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + textboxc1 + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null)) " + datewhere + " order by gjpOrderID desc";
}
else
{
if (!state.Equals(""))
{
string stuas = getfanstatus(state);

sql = "select id,gjpOrderID,status,picPath from Orders as o where (daiquren='0' or qiankuanzhuangtai='1') and status='" + stuas + "' and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + textboxc1 + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null)) " + datewhere + " order by gjpOrderID desc";

}
else
{
sql = "select id,gjpOrderID,status,picPath from Orders where " + wherestring + " and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + textboxc1 + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null)) " + datewhere + " order by gjpOrderID desc";

}
}
DataSet ds2 = DbHelper.DAL.DateSet(sql);
//if (ds2.Tables[0].Rows.Count > 0)
//{
this.GridView1.DataSource = ds2;
this.GridView1.DataBind();
//}
//else
//{

//}


}

protected void customerButton2_Click(object sender, EventArgs e)
{
string textboxc1 = CustomerTextbox2.Text.Trim();
string state = this.textbox_state.Text.Trim();
string sql1 = "";
string datewhere = "";
if (this.textbox_date2.Text == null || this.textbox_date2.Text.Trim() == "") { }
else
{
datewhere = " and orderCreateTime='" + this.textbox_date2.Text.Trim() + " 00:00:00.000'";
}
if (this.UserId.ToString() == "5")
{
sql1 = "select id,gjpOrderID,status,picPath from Orders where daiquren='1' and qiankuanzhuangtai='0' and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + textboxc1 + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null) ) " + datewhere + " order by gjpOrderID desc";
}
else
{
if (!state.Equals(""))
{
string stuas = getfanstatus(state);
// and qiankuanzhuangtai='0'
sql1 = "select id,gjpOrderID,status,picPath from Orders as o where o.status='" + stuas + "' and daiquren='1' and qiankuanzhuangtai='0' and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + textboxc1 + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null) ) " + datewhere + " order by gjpOrderID desc";

}
else
{
// and qiankuanzhuangtai='0'
sql1 = "select id,gjpOrderID,status,picPath from Orders where daiquren='1' and qiankuanzhuangtai='0' and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + textboxc1 + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null) ) " + datewhere + " order by gjpOrderID desc";

}
}
DataSet ds2 = DbHelper.DAL.DateSet(sql1);
//if (ds2.Tables[0].Rows.Count > 0)
//{
this.GridView2.DataSource = ds2;
this.GridView2.DataBind();
//}
//else
//{

//}


}
protected void C1GridView3_PageIndexChanging(object sender, C1GridViewPageEventArgs e)
{
GridView3.PageIndex = e.NewPageIndex;
if (textbox1all.Text == "1") {
string state = this.textbox_state.Text.Trim();
string sql2 = "";
string datewhere = "";
//if (this.textbox_date.Text == null || this.textbox_date.Text.Trim() == "") { }
//else
//{
// datewhere = " and orderCreateTime='" + this.textbox_date.Text.Trim() + " 00:00:00.000'";
//}
if (this.UserId.ToString() == "5")
{
sql2 = "select id,gjpOrderID,status,picPath from Orders where gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null) ) " + datewhere + " order by gjpOrderID desc";
}
else
{
if (!state.Equals(""))
{
string stuas = getfanstatus(state);

sql2 = "select id,gjpOrderID,status,picPath from Orders as o where o.status='" + stuas + "' and gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null) ) " + datewhere + " order by gjpOrderID desc";
}
else
{

sql2 = "select id,gjpOrderID,status,picPath from Orders where gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null) ) " + datewhere + " order by gjpOrderID desc";
}
}
DataSet ds2 = DbHelper.DAL.DateSet(sql2);
//if (ds2.Tables[0].Rows.Count > 0)
//{
this.GridView3.DataSource = ds2;
this.GridView3.DataBind();
//}
//else
//{

//}
}
else
{
string state = this.textbox_state.Text.Trim();
string sql2 = "";
string datewhere = "";
if (this.textbox_date.Text == null || this.textbox_date.Text.Trim() == "") { }
else
{
datewhere = " and orderCreateTime='" + this.textbox_date.Text.Trim() + " 00:00:00.000'";
}
if (this.UserId.ToString() == "5")
{
sql2 = "select id,gjpOrderID,status,picPath from Orders where gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null) ) " + datewhere + " order by gjpOrderID desc";
}
else
{
if (!state.Equals(""))
{
string stuas = getfanstatus(state);

sql2 = "select id,gjpOrderID,status,picPath from Orders as o where o.status='" + stuas + "' and gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null) ) " + datewhere + " order by gjpOrderID desc";
}
else
{

sql2 = "select id,gjpOrderID,status,picPath from Orders where gjpOrderId in(select BillNumberId from caiwu_tongjibiao where [state]=1) and SalesPerson_ID in(select id from SalesPerson where etypeid in(select etypeid from kefuPP where k_id in(select k_id from KefuPerson where dnnUserId=" + this.UserId.ToString() + "))) and CustomerId in(select typeId from " + DbHelper.DAL.GJPSqlServer + "btype where FullName like '%" + this.CustomerTextbox3.Text.Trim() + "%') and gjpOrderId in( select BillNumberId from " + DbHelper.DAL.GJPSqlServer + "BillIndex where BillCode like '%" + this.billcodeTextBoxt3.Text.Trim() + "%' and (etypeid<>'0000100051' or etypeid is null) ) " + datewhere + " order by gjpOrderID desc";
}
}

DataSet ds2 = DbHelper.DAL.DateSet(sql2);
//if (ds2.Tables[0].Rows.Count > 0)
//{
this.GridView3.DataSource = ds2;
this.GridView3.DataBind();
//}
//else
//{

//}
}
}

}

}

原文地址:https://www.cnblogs.com/1971855407qq/p/8539124.html