• 发票后台


    //
    // DotNetNuke?- http://www.dotnetnuke.com
    // Copyright (c) 2002-2017
    // 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 DbHelper;
    using Insus.NET;
    using C1.Web.Wijmo.Controls.C1GridView;
    using System.Data.SqlClient;
    using System.Data;

    namespace Modules.AGL_FP_DSR_KF_TONGJI
    {

    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The ViewAGL_FP_DSR_KF_TONGJI class displays the content
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// </history>
    /// -----------------------------------------------------------------------------
    partial class ViewAGL_FP_DSR_KF_TONGJI : 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 (!Page.IsPostBack)
    {
    ViewState["urllocation"] = Request.RawUrl;
    c1banding();
    SCTEST.Visible = false;
    Div12.Visible = false;
    }
    if (TextBox21.Value == "")
    {
    Button10.Enabled = false;
    }
    else
    {
    Button10.Enabled = true;
    }

    }

    catch (Exception exc)
    {
    //Module failed to load
    Exceptions.ProcessModuleLoadException(this, exc);
    }
    }
    #endregion
    #region
    /// -----------------------------------------------------------------------------
    /// <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(AGL_FP_DSR_KF_TONGJIInfo));
    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
    #region C1GridView1_RowDataBound
    //发票列表表示前处理
    protected void C1GridView1_RowDataBound(object sender, C1GridViewRowEventArgs e)
    {
    if (e.Row.RowType == C1GridViewRowType.DataRow)
    {
    if (e.Row.Cells[17].Text.Trim().Replace("&nbsp;", "") == "0")
    {
    e.Row.Cells[17].Text = "未处理";
    Button buttonEdit = (Button)e.Row.Cells[23].FindControl("udpbuttonupd");
    Button buttonDel = (Button)e.Row.Cells[23].FindControl("udpbuttondel");
    buttonEdit.Enabled = true;
    buttonDel.Enabled = true;

    }
    else if (e.Row.Cells[17].Text.Trim().Replace("&nbsp;", "") == "1")
    {
    e.Row.Cells[17].Text = "已处理";
    Button buttonEdit = (Button)e.Row.Cells[23].FindControl("udpbuttonupd");
    Button buttonDel = (Button)e.Row.Cells[23].FindControl("udpbuttondel");
    buttonEdit.Enabled = false;
    buttonDel.Enabled = false;
    }
    else if (e.Row.Cells[17].Text.Trim().Replace("&nbsp;", "") == "2")
    {
    e.Row.Cells[17].Text = "已处理";
    Button buttonEdit = (Button)e.Row.Cells[23].FindControl("udpbuttonupd");
    Button buttonDel = (Button)e.Row.Cells[23].FindControl("udpbuttondel");
    buttonEdit.Enabled = false;
    buttonDel.Enabled = false;
    }

    //时间
    DropDownList shijianText = (DropDownList)e.Row.FindControl("DropDownList12");
    string shijian = shijianText.Text.Trim().Replace("&nbsp;", "");
    String yue = e.Row.Cells[9].Text.Trim().Replace("&nbsp;", "");


    //结算类型
    if (e.Row.Cells[9].Text.Trim().Replace("&nbsp;", "") == "1")
    {
    if (e.Row.Cells[20].Text.Trim().Replace("&nbsp;", "") == "1")
    {
    e.Row.Cells[9].Text = "临时次结";
    TextBox kaifapiaoTest = (TextBox)e.Row.Cells[16].FindControl("TextBox411");
    string a = e.Row.Cells[15].Text.Trim();
    if (a == "" || a == null || Convert.IsDBNull(a))
    {
    kaifapiaoTest.Text = "0";
    }
    else
    {
    kaifapiaoTest.Text = e.Row.Cells[15].Text.Trim();
    }
    }
    else
    {
    e.Row.Cells[9].Text = "固定月结";

    //e.Row.Cells[9].Text = "固定月结";
    string zhe = DateTime.Now.ToString("yyyy-MM");
    //string zhe = "2018-01";
    string[] mon = zhe.Split('-');
    int m = Convert.ToInt32(mon[1]);
    int shang;
    shang = Convert.ToInt32(m) - 1;
    string sgy = "";
    if (shang < 10)
    {
    sgy = "0" + shang.ToString();
    }
    else
    {
    sgy = shang.ToString();
    }
    string nian;
    if (Convert.ToString(mon[1]) == "01")
    {
    nian = (Convert.ToInt32(mon[0]) - 1).ToString();
    sgy = "12";
    }
    else
    {
    nian = mon[0].ToString();
    }
    //修改为按customer_id查询
    //string fullName = e.Row.Cells[5].Text;
    //string benyue = "SELECT isnull(sum(cast(S.total as decimal)),0) AS 金额 FROM dbo.ASum_SaleBill AS S LEFT OUTER JOIN dbo.ASum_BillIndex AS BI ON S.BillNumberId = BI.BillNumberId LEFT OUTER JOIN dbo.btype AS BT ON BI.btypeid = BT.typeId where BT.FullName='" + fullName + "' and left(CAST(S.OutFactoryDate AS DATE),10) between '" + nian + "-" + sgy + "-26' and '" + zhe + "-25'";

    string customer_id = e.Row.Cells[1].Text;
    string benyue = "SELECT isnull(sum(cast(S.total as decimal)),0) AS 金额 FROM dbo.ASum_SaleBill AS S LEFT OUTER JOIN dbo.ASum_BillIndex AS BI ON S.BillNumberId = BI.BillNumberId LEFT OUTER JOIN dbo.btype AS BT ON BI.btypeid = BT.typeId where BT.typeId='" + customer_id + "' and left(CAST(S.OutFactoryDate AS DATE),10) between '" + nian + "-" + sgy + "-26' and '" + zhe + "-25'";
    DataSet dbenyue = GJPDbHelper.DAL.DateSet(benyue);
    TextBox kaifapiaoTest = (TextBox)e.Row.Cells[16].FindControl("TextBox411");
    string a = dbenyue.Tables[0].Rows[0]["金额"].ToString();
    if (a == "" || a == null || Convert.IsDBNull(a))
    {
    kaifapiaoTest.Text = "0";
    }
    else
    {
    kaifapiaoTest.Text = dbenyue.Tables[0].Rows[0]["金额"].ToString();
    }
    }
    }
    else if (e.Row.Cells[9].Text.Trim().Replace("&nbsp;", "") == "2")
    {
    if (e.Row.Cells[20].Text.Trim().Replace("&nbsp;", "") == "1")
    {
    e.Row.Cells[9].Text = "实次次结";
    TextBox kaifapiaoTest = (TextBox)e.Row.Cells[16].FindControl("TextBox411");
    string a = e.Row.Cells[15].Text.Trim();
    if (a == "" || a == null || Convert.IsDBNull(a))
    {
    kaifapiaoTest.Text = "0";
    }
    else
    {
    kaifapiaoTest.Text = e.Row.Cells[15].Text.Trim();
    }
    }
    else
    {
    e.Row.Cells[9].Text = "临时次结";
    }
    }
    else if (e.Row.Cells[9].Text.Trim().Replace("&nbsp;", "") == "3")
    {
    e.Row.Cells[9].Text = "临时次结";
    TextBox kaifapiaoTest = (TextBox)e.Row.Cells[16].FindControl("TextBox411");
    string a = e.Row.Cells[15].Text.Trim();
    if (a == "" || a == null || Convert.IsDBNull(a))
    {
    kaifapiaoTest.Text = "0";
    }
    else
    {
    kaifapiaoTest.Text = e.Row.Cells[15].Text.Trim();
    }
    }
    //发票类型
    if (e.Row.Cells[8].Text.Trim().Replace("&nbsp;", "") == "1")
    {
    e.Row.Cells[8].Text = "增值税专用";
    }
    else if (e.Row.Cells[8].Text.Trim().Replace("&nbsp;", "") == "2")
    {
    e.Row.Cells[8].Text = "增值税普发";
    }
    //发票状态
    if (e.Row.Cells[9].Text.Trim().Replace("&nbsp;", "") == "固定月结")
    {
    Button buttonEdit = (Button)e.Row.Cells[16].FindControl("buttonEdit");
    Button buttonDel = (Button)e.Row.Cells[16].FindControl("buttonDel");
    buttonEdit.Enabled = false;
    buttonDel.Enabled = false;


    }
    else
    {
    Button buttonEdit = (Button)e.Row.Cells[16].FindControl("buttonEdit");
    Button buttonDel = (Button)e.Row.Cells[16].FindControl("buttonDel");
    buttonEdit.Enabled = true;
    buttonDel.Enabled = true;
    }
    string id = e.Row.Cells[11].Text.Trim();
    string lingqu = "select * from InvoiceSure where invid in(select id from Invoices_linshi where duicuo=0) and invid =" + id + " and billNumberId ='1'";
    DataTable dt = DbHelper.DAL.DateSet(lingqu).Tables[0];
    if (dt.Rows.Count >= 1)
    {
    e.Row.Cells[18].Text = "已领取";
    }
    else
    {
    e.Row.Cells[18].Text = "未领取";
    }
    System.Web.UI.WebControls.Button btnzhangshu = (System.Web.UI.WebControls.Button)e.Row.Cells[2].FindControl("Button5");

    btnzhangshu.Attributes.Add("onclick", "return dnnModal.show('/DesktopModules/AGL_FP_DSR_KF_TONGJI/linshi.aspx?id=" + id + "&popUp=true',true,600,1000,false)");


    }
    }

    protected void C1GridView1_RowCommand(object sender, C1GridViewCommandEventArgs e)
    {
    if (e.CommandName == "cupd")
    {
    C1GridViewRow row = ((C1GridViewRow)(((Button)(e.CommandSource)).Parent.Parent));


    if (row != null)
    {

    string datakeys = e.CommandArgument.ToString();
    string updlinshiStr = "select * FROM Invoices_linshi WHERE id=" + datakeys + "";
    string iid = row.Cells[11].Text;


    DataSet dsinvlinshi = DbHelper.DAL.ExecuteDataSet(updlinshiStr);

    string updinvStr = "select inv.*,c.* from Invoices inv left join " + DbHelper.DAL.GJPSqlServer + "btype c on c.typeid = inv.[customer_id] where c.typeid='" + dsinvlinshi.Tables[0].Rows[0]["customer_id"].ToString() + "' and inv.customer_id in (select customer_id from Invoices_linshi where id=" + datakeys + ")";

    DataSet dsinv = DbHelper.DAL.ExecuteDataSet(updinvStr);
    Label12.Text = datakeys;
    TextBox2.Value = dsinv.Tables[0].Rows[0]["fullname"].ToString();//管家婆客户名称
    TextBox3.Value = dsinv.Tables[0].Rows[0]["company"].ToString();//公司名称
    string fpty = "";
    if (dsinv.Tables[0].Rows[0]["fp_type"].ToString() == "1")
    {
    fpty = "增值税专用发票";
    }
    else
    {
    fpty = "增值税普通发票";
    }
    DropDownList1.Value = dsinv.Tables[0].Rows[0]["fp_type"].ToString();//发票类型

    TextBox7.Value = dsinv.Tables[0].Rows[0]["account_bank"].ToString();
    TextBox9.Value = dsinv.Tables[0].Rows[0]["account_number"].ToString();
    TextBox5.Value = dsinvlinshi.Tables[0].Rows[0]["amount"].ToString();//金额
    if (dsinvlinshi.Tables[0].Rows[0]["state"].ToString() == "" || dsinvlinshi.Tables[0].Rows[0]["state"].ToString() == null)
    { }
    else
    {
    string strdsz = "select BillCode from BillIndex where BillNumberId in(" + dsinvlinshi.Tables[0].Rows[0]["state"].ToString() + ")";
    DataSet dsz = GJPDbHelper.DAL.ExecuteDataSet(strdsz);
    if (dsz.Tables[0].Rows.Count > 0)
    {
    for (int j = 0; j < dsz.Tables[0].Rows.Count; j++)
    {
    if (j == 0)
    {
    TextBox36.Value = dsinvlinshi.Tables[0].Rows[j]["BillCode"].ToString();
    }
    else
    {
    TextBox36.Value = TextBox36.Value + "," + dsinvlinshi.Tables[0].Rows[j]["BillCode"].ToString();
    }
    }

    }
    }
    DropDownList2.Value = dsinvlinshi.Tables[0].Rows[0]["statement_ci"].ToString();//结算类型
    Textarea1.InnerText = dsinvlinshi.Tables[0].Rows[0]["beizhu"].ToString();
    PlaceHolder1.Visible = true;

    }
    }
    else if (e.CommandName == "cdel")
    {
    C1GridViewRow row = ((C1GridViewRow)(((Button)(e.CommandSource)).Parent.Parent));

    if (row != null)
    {

    string datakeys = e.CommandArgument.ToString();
    string gjp = DbHelper.DAL.GJPSqlServer;
    string str = "select b.fullname FROM Invoices_linshi inv left join " + gjp + "btype b on inv.customer_id =b.typeid WHERE id=" + datakeys + "";
    object ob = DbHelper.DAL.ExecuteScalar(str);
    string dellinshiStr = "DELETE FROM Invoices_linshi WHERE id=" + datakeys + "";
    int ii=DbHelper.DAL.ExecuteNonQuery(dellinshiStr);
    if (ii > 0)
    {
    DbHelper.DAL.addOperation_Log(this.UserId.ToString(), "发票申请", "删除", "对客户名称为" + ob.ToString() + " id 为" + datakeys + "的发票进行了删除");
    //InsusJsUtility objJs1 = new InsusJsUtility();
    //objJs1.JsAlert("删除成功!");
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('删除成功!');", true);
    c1banding();
    }
    else
    {
    //InsusJsUtility objJs1 = new InsusJsUtility();
    //objJs1.JsAlert("删除失败稍后再试!");
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('删除失败稍后再试!');", true);
    }

    }
    }
    }
    #endregion
    #region C1GridView2_RowDataBound
    protected void C1GridView2_RowDataBound(object sender, C1GridViewRowEventArgs e)
    {
    if (e.Row.RowType == C1GridViewRowType.DataRow)
    {
    String yue = e.Row.Cells[9].Text.Trim().Replace("&nbsp;", "");
    //结算类型
    if (e.Row.Cells[8].Text.Trim().Replace("&nbsp;", "") == "0")
    {
    e.Row.Cells[8].Text = "固定月结";
    }
    else if (e.Row.Cells[8].Text.Trim().Replace("&nbsp;", "") == "1")
    {
    e.Row.Cells[8].Text = "实次次结";
    }
    else if (e.Row.Cells[8].Text.Trim().Replace("&nbsp;", "") == "2")
    {
    e.Row.Cells[8].Text = "临时次结";
    }
    //次结
    if (e.Row.Cells[10].Text.Trim().Replace("&nbsp;", "") == "0")
    {
    e.Row.Cells[10].Text = "否";
    }
    else if (e.Row.Cells[10].Text.Trim().Replace("&nbsp;", "") == "1")
    {
    e.Row.Cells[10].Text = "是";
    }
    //发票类型
    if (e.Row.Cells[7].Text.Trim().Replace("&nbsp;", "") == "0")
    {
    e.Row.Cells[7].Text = "增值税专用";
    }
    else if (e.Row.Cells[7].Text.Trim().Replace("&nbsp;", "") == "1")
    {
    e.Row.Cells[7].Text = "增值税普发";
    }

    //状态
    if (e.Row.Cells[17].Text.Trim().Replace("&nbsp;", "") == "0")
    {
    e.Row.Cells[17].Text = "审批中";
    }
    else if (e.Row.Cells[17].Text.Trim().Replace("&nbsp;", "") == "1")
    {
    e.Row.Cells[17].Text = "已审批";
    }
    //按钮判断
    if (e.Row.Cells[17].Text.Trim().Replace("&nbsp;", "") == "审批中")
    {

    //tiijiaoTest.Enabled = true;
    //kaifapiaoTest.Enabled = false;
    }
    else if (e.Row.Cells[17].Text.Trim().Replace("&nbsp;", "") == "已审批")
    {

    //tiijiaoTest.Enabled = false;
    //kaifapiaoTest.Enabled = true;
    }
    String FullName = TextBox10.Value;
    String OutFactoryDate = TextBox19.Text;
    String total = TextBox18.Value;
    string a = TextBox6.Text;
    string statement = this.TextBox22.Text;
    string fptype = this.TextBox23.Text;
    string fp = this.DropDownList3.Value;
    string customer_id = this.TextBox24.Text;
    string account_bank = this.TextBox25.Text;
    string account_number = this.TextBox26.Text;
    string identity_number = this.TextBox27.Text;
    string address = this.TextBox28.Text;
    string telephone = this.TextBox29.Text;
    string company = this.TextBox30.Text;
    }
    }
    #endregion
    #region C1GridView5_RowDataBound
    protected void C1GridView5_RowDataBound(object sender, C1GridViewRowEventArgs e)
    {
    if (e.Row.RowType == C1GridViewRowType.DataRow)
    { //结算类型
    if (e.Row.Cells[4].Text.Trim().Replace("&nbsp;", "") == "1")
    {
    e.Row.Cells[4].Text = "固定月结";
    }
    else if (e.Row.Cells[4].Text.Trim().Replace("&nbsp;", "") == "2")
    {
    e.Row.Cells[4].Text = "实次次结";
    }
    else if (e.Row.Cells[4].Text.Trim().Replace("&nbsp;", "") == "3")
    {
    e.Row.Cells[4].Text = "临时次结";
    }
    }
    }
    #endregion
    #region 填写发票信息 选择
    protected void Button2_Click(object sender, EventArgs e)
    {
    string gjp = DbHelper.DAL.GJPSqlServer;
    Button button = (Button)sender;
    C1GridViewRow gvr = (C1GridViewRow)button.Parent.Parent;
    string fullname = C1GridView2.Rows[gvr.RowIndex].Cells[2].Text.Trim().Replace("&nbsp;", "");
    int dr_Count = DbHelper.DAL.ExecuteDataSet("select inv.*,c.* from Invoices inv left join "+gjp+"btype c on c.typeid = inv.[customer_id] where c.fullName='" + fullname + "'").Tables[0].Rows.Count;

    if (dr_Count >= 1)
    {
    //InsusJsUtility objJs1 = new InsusJsUtility();
    //objJs1.JsAlert("已存在客户信息!");
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('已存在客户信息!');", true);
    //银行
    TextBox14.Value = "";
    //账户
    TextBox16.Value = "";
    //纳税人识别号
    TextBox17.Value = "";
    //地址
    TextBox13.Value = "";
    //电话
    TextBox15.Value = "";
    //公司名称
    TextBox11.Value = "";
    //billnumberid

    }
    else
    {
    TextBox10.Value = button.CommandArgument;//C1GridView2.Rows[gvr.RowIndex].Cells[2].Text.Trim().Replace("&nbsp;", "");
    //客户列表
    SCTEST.Visible = false;
    }
    }
    #endregion
    #region 临时发票必填 选择
    protected void Buttonkehuxz_Click(object sender, EventArgs e)
    {
    Button button = (Button)sender;
    C1GridViewRow gvr = (C1GridViewRow)button.Parent.Parent;
    string customer_id = C1GridView5.Rows[gvr.RowIndex].Cells[0].Text.Trim().Replace("&nbsp;", "");
    int dr_Count = DbHelper.DAL.ExecuteDataSet("select * from Invoices where customer_id='" + customer_id + "'").Tables[0].Rows.Count;

    TextBox21.Value = button.CommandArgument; //C1GridView5.Rows[gvr.RowIndex].Cells[2].Text.Trim().Replace("&nbsp;", "");
    TextBox32.Text = C1GridView5.Rows[gvr.RowIndex].Cells[1].Text.Trim().Replace("&nbsp;", "");
    TextBox6.Text = C1GridView5.Rows[gvr.RowIndex].Cells[0].Text.Trim().Replace("&nbsp;", "");
    TextBox22.Text = C1GridView5.Rows[gvr.RowIndex].Cells[5].Text.Trim().Replace("&nbsp;", "");
    TextBox23.Text = C1GridView5.Rows[gvr.RowIndex].Cells[6].Text.Trim().Replace("&nbsp;", "");
    TextBox24.Text = C1GridView5.Rows[gvr.RowIndex].Cells[7].Text.Trim().Replace("&nbsp;", "");
    TextBox25.Text = C1GridView5.Rows[gvr.RowIndex].Cells[8].Text.Trim().Replace("&nbsp;", "");
    TextBox26.Text = C1GridView5.Rows[gvr.RowIndex].Cells[9].Text.Trim().Replace("&nbsp;", "");
    TextBox27.Text = C1GridView5.Rows[gvr.RowIndex].Cells[10].Text.Trim().Replace("&nbsp;", "");
    TextBox28.Text = C1GridView5.Rows[gvr.RowIndex].Cells[11].Text.Trim().Replace("&nbsp;", "");
    TextBox29.Text = C1GridView5.Rows[gvr.RowIndex].Cells[12].Text.Trim().Replace("&nbsp;", "");
    TextBox30.Text = C1GridView5.Rows[gvr.RowIndex].Cells[4].Text.Trim().Replace("&nbsp;", "");
    TextBox1.Value = C1GridView5.Rows[gvr.RowIndex].Cells[2].Text.Trim().Replace("&nbsp;", "");
    TextBox12.Text = customer_id;
    //for (int i = 0; i < DropDownList3.Items.Count; i++)
    //{
    // if (DropDownList3.Items[i].Value == TextBox22.Text)
    // {
    // DropDownList3.Items[i].Selected = true;

    // }
    //}
    DropDownList3.Value = TextBox22.Text;
    //TextBox6.Text = "";
    this.C1GridView5.DataBind();
    //客户列表
    Div12.Visible = false;
    if (TextBox21.Value == "")
    {
    Button10.Enabled = false;
    }
    else
    {
    Button10.Enabled = true;
    }
    //发票列表
    //C1GridView1.Visible = true;
    }
    #endregion
    #region 填写发票信息 客户列表查询
    protected void Button4_Click(object sender, EventArgs e)
    {
    //this.SqlDataSourceSC.SelectParameters["name"].DefaultValue = "%" + TextBox4.Text + "%";
    //this.SqlDataSourceSC.DataBind();
    //this.C1GridView2.DataBind();
    string test = " select id,name,FullName from view_selectCustomerWithGjp where FullName like '%" + TextBox4.Text + "%'";
    DataTable SC = DbHelper.DAL.DateSet(test).Tables[0];
    C1GridView2.DataSource = SC;
    C1GridView2.DataBind();
    }
    #endregion
    #region 其他发票信息查询
    protected void Button7_Click(object sender, EventArgs e)
    {
    string zhe = DateTime.Now.ToString("yyyy-MM");
    //string zhe = "2018-01";
    string[] mon = zhe.Split('-');
    int m = Convert.ToInt32(mon[1]);
    int shang;
    shang = Convert.ToInt32(m) - 1;
    string sgy = "";
    if (shang < 10)
    {
    sgy = "0" + shang.ToString();
    }
    else
    {
    sgy = shang.ToString();
    }
    string nian;
    if (Convert.ToString(mon[1]) == "01")
    {
    nian = (Convert.ToInt32(mon[0]) - 1).ToString();
    sgy = "12";
    }
    else
    {
    nian = mon[0].ToString();
    }
    int a = this.DropDownList4.SelectedIndex;
    string gjp = DbHelper.DAL.GJPSqlServer;
    //string test = " SELECT inv.customer_id,inv.fengzFlag, inv.account_bank, inv.account_number, inv.id, inv.statement,inv.statement_ci,inv.identity_number,inv.address,inv.telephone,inv.fp_type,inv.state,c.fullname,inv.company,inv.amount,inv.FPSHIJIAN,inv.flag,inv.creat_date,inv.beizhu FROM Invoices inv left join "+gjp+"btype c on c.typeid = inv.customer_id where (inv.creat_date between '" + nian + "-" + sgy + "-26' and '" + zhe + "-25' or inv.creat_date ='2000-01-01') and inv.company LIKE '%" + this.TextBox8.Text + "%' and inv.fengzFlag=" + a + " ORDER BY inv.id desc";
    //string test1 = "SELECT inv.customer_id,inv.fengzFlag,inv.user_id,inv.account_bank, inv.account_number, inv.id, inv.statement,inv.statement_ci,inv.identity_number,inv.address,inv.telephone,inv.fp_type,inv.state,c.fullname,inv.company,inv.amount,inv.FPSHIJIAN,inv.flag,inv.creat_date,inv.beizhu FROM Invoices inv left join " + gjp + "btype c on c.typeid = inv.customer_id where inv.company LIKE '%" + this.TextBox8.Text + "%' and inv.fengzFlag=" + a + " and (inv.creat_date between '" + nian + "-" + sgy + "-26' and '" + zhe + "-25' or inv.creat_date ='2000-01-01') and (( inv.statement =1 and inv.statement_ci='') or (inv.statement =2 and inv.statement_ci=1) or (inv.statement =3 and inv.statement_ci!='')) ORDER BY inv.id desc";
    string test1 = "SELECT inv.customer_id,invlinshi.fengzFlag,inv.user_id,inv.account_bank, inv.account_number, inv.id, invlinshi.id as linshiid, inv.statement,invlinshi.statement_ci,inv.identity_number,inv.address,inv.telephone,invlinshi.fp_type,invlinshi.state,c.fullname,inv.company,invlinshi.amount,invlinshi.creat_date,invlinshi.beizhu FROM Invoices inv left join Invoices_linshi invlinshi on invlinshi.customer_id = inv.customer_id left join " + gjp + "btype c on c.typeid = inv.customer_id where inv.company LIKE '%" + this.TextBox8.Text + "%' and invlinshi.fengzFlag=" + a + " and (invlinshi.creat_date between '" + nian + "-" + sgy + "-26' and '" + zhe + "-25' or invlinshi.creat_date ='2000-01-01') and (( inv.statement ='1' and invlinshi.statement_ci='') or (inv.statement ='2' and invlinshi.statement_ci='1') or (inv.statement ='2' and invlinshi.statement_ci='2') or (inv.statement ='1' and invlinshi.statement_ci='1') or (inv.statement ='3' and invlinshi.statement_ci='2')) ORDER BY inv.id desc";

    DataTable SC = DbHelper.DAL.DateSet(test1).Tables[0];
    C1GridView1.DataSource = DbHelper.DAL.ReplaceFullName(SC, "fullname"); //SC;
    C1GridView1.DataBind();
    }
    #endregion
    #region 其他发票信息 选择客户信息(最新)
    protected void Button8_Click(object sender, EventArgs e)
    {
    Button9.Enabled = true;
    //string test = " select inv.*,c.* from [Invoices] inv left join (select id as cusid,fullname from customer) c on c.cusid = inv.customer_id where [fullName]like '%" + this.TextBox8.Text + "%'";
    string test = " select id,name,FullName from view_selectCustomerWithGjp";
    DataTable SC = DbHelper.DAL.DateSet(test).Tables[0];
    C1GridView2.DataSource = SC;
    C1GridView2.DataBind();
    //客户列表
    //this.SqlDataSourceSC.SelectParameters["name"].DefaultValue = "%%";
    //this.SqlDataSourceSC.DataBind();
    //this.C1GridView2.DataBind();
    SCTEST.Visible = true;
    //C1GridView2.DataSource = DbHelper.DAL.DateSet(" select id,name,FullName from view_selectCustomerWithGjp").Tables[0];
    //C1GridView2.DataBind();
    }
    #endregion
    #region 临时发票必填 选择客户信息
    protected void Buttonkehu_Click(object sender, EventArgs e)
    {
    string zhe = DateTime.Now.ToString("yyyy-MM");
    //string zhe = "2017-08";
    string[] mon = zhe.Split('-');
    int m = Convert.ToInt32(mon[1]);
    int shang;
    int sangeyue;
    shang = Convert.ToInt32(m) - 1;
    string sgy = "";
    if (shang < 10)
    {
    sgy = "0" + shang.ToString();
    }
    else
    {
    sgy = shang.ToString();
    }
    sangeyue = Convert.ToInt32(m) - 4;
    if (sangeyue <= 0)
    {
    sangeyue = 1;
    }
    string ssgy = "0" + sangeyue.ToString();
    string gjp = DbHelper.DAL.GJPSqlServer;
    //选择自己的客户赞威胁
    string test = " select inv.*,c.* from [Invoices] inv left join (select typeid as cusid,fullname from " + gjp + "btype) c on c.cusid = inv.customer_id order by inv.id desc";
    DataTable SC = DbHelper.DAL.DateSet(test).Tables[0];
    C1GridView5.DataSource = SC;
    C1GridView5.DataBind();
    //客户列表
    Div12.Visible = true;
    SCTEST.Visible = false;
    //C1GridView2.DataSource = DbHelper.DAL.DateSet(" select id,name,FullName from view_selectCustomerWithGjp").Tables[0];
    //C1GridView2.DataBind();
    }
    #endregion
    #region 临时发票必填 查询
    protected void Button16_Click(object sender, EventArgs e)
    {
    string gjp = DbHelper.DAL.GJPSqlServer;
    string test = " select inv.*,c.* from [Invoices] inv left join (select typeid as cusid,fullname from " + gjp + "btype) c on c.cusid = inv.customer_id where c.fullname like '%" + TextBox33.Text + "%' ";
    DataTable SC = DbHelper.DAL.DateSet(test).Tables[0];
    C1GridView5.DataSource = SC;
    C1GridView5.DataBind();
    //客户列表
    Div12.Visible = true;
    }
    #endregion
    #region 填写发票信息 清空客户信息
    protected void Button8_Click1(object sender, EventArgs e)
    {
    //清空C1GridView1_RowCommand
    TextBox11.Value = "";
    TextBox10.Value = "";
    TextBox12.Text = "";
    TextBox17.Value = "";
    TextBox13.Value = "";
    TextBox15.Value = "";
    TextBox14.Value = "";
    TextBox16.Value = "";
    Select1.Value = "0";
    Select2.Value = "0";
    TextBox18.Value = "";
    //TextBox_Amount.Text = "";
    //客户列表
    SCTEST.Visible = false;
    //发票列表
    //C1GridView1.Visible = true;
    }
    #endregion
    #region 填写发票信息 点击保存
    protected void Button9_Click1(object sender, EventArgs e)
    {
    string nian;
    string zhe = DateTime.Now.ToString("yyyy-MM");
    //string zhe = "2017-08";
    string[] mon = zhe.Split('-');
    int m = Convert.ToInt32(mon[1]);
    int shang;
    int sangeyue;
    shang = Convert.ToInt32(m) - 1;
    string sgy = "";
    if (shang < 10)
    {
    sgy = "0" + shang.ToString();
    }
    else
    {
    sgy = shang.ToString();
    }
    sangeyue = Convert.ToInt32(m) - 4;
    if (sangeyue <= 0)
    {
    sangeyue = 1;
    }
    string ssgy = "0" + sangeyue.ToString();
    string jine = TextBox18.Value.Trim();
    if (Convert.ToString(mon[1]) == "01")
    {
    nian = (Convert.ToInt32(mon[0]) - 1).ToString();
    sgy = "12";
    }
    else
    {
    nian = mon[0].ToString();
    }
    //客户名称
    string name = TextBox10.Value.Trim().Replace("&nbsp;", "");
    //银行
    string account_bank = TextBox14.Value.Trim().Replace("&nbsp;", "");

    //账户
    string account_number = TextBox16.Value.Trim().Replace("&nbsp;", "");

    //纳税人识别号
    string identityNumber = TextBox17.Value.Trim().Replace("&nbsp;", "");
    string userid = this.UserId.ToString();
    //地址
    string address = TextBox13.Value.Trim().Replace("&nbsp;", "");

    //电话
    string telephone = TextBox15.Value.Trim().Replace("&nbsp;", "");
    //公司名称
    string company = TextBox11.Value.Trim().Replace("&nbsp;", "");
    //金额
    string amount = TextBox18.Value.Trim().Replace("&nbsp;", "");

    //发票类型
    string fp_type = Select1.Items[Select1.SelectedIndex].Value;
    //选择结算类型
    string statement = Select2.Items[Select2.SelectedIndex].Value;
    //获取当前时间
    string creat_date = DateTime.Now.ToString("yyyy-MM-dd");
    string creat_date1 = "2000-01-01";
    if (company == "" || company == null)
    {
    //InsusJsUtility objJs = new InsusJsUtility();
    //objJs.JsAlert("请填写公司名称!");
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('请填写公司名称!');", true);
    return;
    }
    //if (address == "" || address == null)
    //{
    // InsusJsUtility objJs = new InsusJsUtility();
    // objJs.JsAlert("请填写地址!");
    // return;
    //}
    //if (account_bank == "" || account_bank == null)
    //{
    // InsusJsUtility objJs = new InsusJsUtility();
    // objJs.JsAlert("请填写开户行!");
    // return;
    //}
    //if (fp_type == "0")
    //{
    // InsusJsUtility objJs = new InsusJsUtility();
    // objJs.JsAlert("请选择发票类型!");
    // return;
    //}
    //if (statement == "0")
    //{
    // InsusJsUtility objJs = new InsusJsUtility();
    // objJs.JsAlert("请选择结算类型!");
    // return;
    //}
    if (identityNumber == "" || identityNumber == null)
    {
    //InsusJsUtility objJs = new InsusJsUtility();
    //objJs.JsAlert("请填写纳税人识别号!");
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('请填写纳税人识别号!');", true);
    return;
    }
    //if (telephone == "" || telephone == null)
    //{
    // InsusJsUtility objJs = new InsusJsUtility();
    // objJs.JsAlert("请填写电话!");
    // return;
    //}
    //if (account_number == "" || account_number == null)
    //{
    // InsusJsUtility objJs = new InsusJsUtility();
    // objJs.JsAlert("请填写账号!");
    // return;
    //}
    string panduanname = TextBox10.Value;

    string billid = "";
    string amoun = "0";
    string gjp1 = DbHelper.DAL.GJPSqlServer;
    string SqlSelect = "SELECT count(c.typeid) FROM Invoices inv left join " + gjp1 + "btype c on c.typeid =inv.customer_id WHERE c.fullName='" + panduanname + "' and (statement='1' or statement ='2') ";
    object count1 = DbHelper.DAL.ExecuteScalar(SqlSelect);
    if (count1.ToString() == "1")
    {
    //InsusJsUtility objJs = new InsusJsUtility();
    //objJs.JsAlert("已存在客户信息!");
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('已存在客户信息!');", true);
    }
    else
    {
    this.UserId.ToString();
    string fullname = TextBox10.Value.Trim();
    string strcusid = "select typeid from btype where fullName ='" + fullname + "'";
    object ob = GJPDbHelper.DAL.ExecuteScalar(strcusid);
    if (Convert.IsDBNull(ob) || ob == null || ob == "")
    {
    //InsusJsUtility objJs = new InsusJsUtility();
    //objJs.JsAlert("没有对应上客户!");
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('没有对应上客户!');", true);
    return;
    }
    int count = 0;
    SqlParameter[] sp1 = new SqlParameter[] {
    new SqlParameter("@portal_id", Convert.ToInt32(this.PortalId)),
    new SqlParameter("@customer_id", ob.ToString()),
    new SqlParameter("@account_bank", account_bank.ToString()),
    new SqlParameter("@account_number", account_number.ToString()),
    new SqlParameter("@statement", statement.ToString()),
    new SqlParameter("@identity_number", identityNumber.ToString()),
    new SqlParameter("@address", address.ToString()),
    new SqlParameter("@telephone", telephone.ToString()),
    new SqlParameter("@fp_type", fp_type.ToString()),
    new SqlParameter("@company", company.ToString()),
    //new SqlParameter("@user_id", user_id.ToString()),
    };
    //拆分发票表新增信息
    string newInsertSql = "INSERT INTO Invoices ([portal_id],[customer_id],[account_bank],[account_number],[statement],[identity_number],[address],[telephone],[fp_type],[creat_date],[user_id],[company])VALUES(@portal_id,@customer_id,@account_bank,@account_number,@statement,@identity_number,@address,@telephone,@fp_type,'" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + userid + "',@company);SELECT @@IDENTITY;";
    int insertId = Convert.ToInt32(DbHelper.DAL.ExecuteScalar(newInsertSql, sp1));
    //log 日志 添加 2.9
    DbHelper.DAL.addOperation_Log(userid, "发票申请", "新增", "增加基础发票信息:客户名称为" + fullname + "客户id为" + ob.ToString() + "的发票进行的新增");

    count = insertId;
    if (statement == "1")
    {
    if (jine == null || jine == "")
    {
    jine = "0";
    }
    //string sqlInsertguding = "insert into Invoices values (@portal_id,@customer_id,@account_bank,@account_number,@statement,'',@identity_number,@address,@telephone,@fp_type,''," + userid + ",'2000-01-01','" + jine + "',@company,0,'',0,0 ,'');";
    //count = DbHelper.DAL.ExecuteNonQuery(sqlInsertguding, sp1);

    String sqlInsert = "insert into Invoices_linshi([portal_id],[customer_id],[statement_ci],[state],[fp_type],[user_id],[creat_date],[amount],[fengzFlag],[duicuo],[beizhu]) values (0,'" + ob.ToString() + "','','" + billid + "','" + fp_type + "','" + userid + "','2000-01-01','" + jine + "',0,0,'');";
    DbHelper.DAL.ExecuteNonQuery(sqlInsert);

    }
    else if (statement == "2")
    {
    // // new SqlParameter("@portal_id", Convert.ToInt32(this.PortalId)),
    // //new SqlParameter("@customer_id", ob.ToString()),
    // //new SqlParameter("@account_bank", account_bank.ToString()),
    // //new SqlParameter("@account_number", account_number.ToString()),
    // //new SqlParameter("@statement", statement.ToString()),
    // //new SqlParameter("@identity_number", identityNumber.ToString()),
    // // new SqlParameter("@address", address.ToString()),
    // //new SqlParameter("@telephone", telephone.ToString()),
    // //new SqlParameter("@fp_type", fp_type.ToString()),
    // //new SqlParameter("@company", company.ToString()),
    //string sqlInsertshiji = "insert into Invoices values (@portal_id,@customer_id,@account_bank,@account_number,@statement,'',@identity_number,@address,@telephone,@fp_type,''," + userid + ",'2000-01-01','" + amoun + "',@company,0,'',0,0 ,'');";
    //DbHelper.DAL.ExecuteNonQuery(sqlInsertshiji, sp1);
    //根据姓名时间获取 当天的 所有 billnumberid 与 金额

    string strbill = "SELECT BI.BillNumberId,sum(cast(S.total as decimal)) AS 金额 FROM dbo.ASum_SaleBill AS S LEFT OUTER JOIN dbo.ASum_BillIndex AS BI ON S.BillNumberId = BI.BillNumberId LEFT OUTER JOIN dbo.btype AS BT ON BI.btypeid = BT.typeId where BT.FullName = '" + panduanname + "' and (CAST(S.OutFactoryDate AS DATE) between '" + nian + "-" + sgy + "-26' and '" + zhe + "-25') group by BT.typeId,BI.BillNumberId,CAST(S.OutFactoryDate AS DATE),BT.FullName order by CAST(S.OutFactoryDate AS DATE)";
    DataTable dt = GJPDbHelper.DAL.DateSet(strbill).Tables[0];
    if (dt.Rows.Count > 0)
    {
    for (int i = 0; i < dt.Rows.Count; i++)
    {
    billid = dt.Rows[i][0].ToString();
    amoun = dt.Rows[i][1].ToString();
    //String sqlInsert = "insert into Invoices values (0,'" + ob.ToString() + "','" + account_bank + "','" + account_number + "','" + statement + "','1','" + identityNumber + "','" + address + "','" + telephone + "','" + fp_type + "','" + billid + "'," + userid + ",'" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + amoun + "','" + company + "',0,'',0,0 ,'');";

    String sqlInsert = "insert into Invoices_linshi([portal_id],[customer_id],[statement_ci],[state],[fp_type],[user_id],[creat_date],[amount],[fengzFlag],[duicuo],[beizhu]) values (0,'" + ob.ToString() + "','1','" + billid + "','" + fp_type + "','" + userid + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + amoun + "',0,0,'');";
    DbHelper.DAL.ExecuteNonQuery(sqlInsert);
    }

    }

    }
    else if (statement == "3")
    {
    //String sqlInsert = "insert into Invoices values (@portal_id,@customer_id,@account_bank,@account_number,@statement,'',@identity_number,@address,@telephone,@fp_type,''," + userid + ",'" + creat_date1.ToString() + "','0',@company,0,'',0,0 ,'');";
    //DbHelper.DAL.ExecuteNonQuery(sqlInsert, sp1);

    //String sqlInsert = "insert into Invoices_linshi([portal_id],[customer_id],[statement_ci],[state],[fp_type],[user_id],[creat_date],[amount],[fengzFlag],[duicuo]) values (0,'" + ob.ToString() + "','','" + billid + "','" + fp_type + "','" + userid + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "','0',0,0);";
    //DbHelper.DAL.ExecuteNonQuery(sqlInsert);

    }


    if (count >= 1)
    {
    //InsusJsUtility objJs1 = new InsusJsUtility();
    //objJs1.JsAlert("保存成功!");
    //ShowLoanding();
    Response.Write("<script>alert('保存成功!');window.location.href='" + ViewState["urllocation"] + "';</script>");
    Button9.Enabled = false;
    }
    //客户列表
    string gjp = DbHelper.DAL.GJPSqlServer;
    C1GridView1.DataSource = DbHelper.DAL.ReplaceFullName(DbHelper.DAL.DateSet("SELECT inv.customer_id,inv.[user_id],invlinshi.beizhu,invlinshi.fengzFlag, inv.account_bank, inv.account_number, inv.id, invlinshi.id as linshiid, inv.statement,invlinshi.statement_ci,inv.identity_number,inv.address,inv.telephone,invlinshi.fp_type,invlinshi.state,c.fullname,inv.company,invlinshi.amount,invlinshi.creat_date FROM Invoices inv left join Invoices_linshi invlinshi on invlinshi.customer_id = inv.customer_id left join " + gjp + "btype c on c.typeid = inv.customer_id where inv.[user_id] =" + this.UserId.ToString() + " and invlinshi.[fengzFlag]=0 and (( inv.statement ='1' and invlinshi.statement_ci='') or (inv.statement ='2' and invlinshi.statement_ci='1') or (inv.statement ='2' and invlinshi.statement_ci='2') or (inv.statement ='1' and invlinshi.statement_ci='1') or (inv.statement ='3' and invlinshi.statement_ci='2') ) and (left(invlinshi.creat_date,7) ='" + zhe + "' or invlinshi.creat_date ='2000-01-01') ORDER BY inv.id desc").Tables[0], "fullname");
    C1GridView1.DataBind();
    TextBox11.Value = "";
    TextBox10.Value = "";
    TextBox12.Text = "";
    TextBox17.Value = "";
    TextBox13.Value = "";
    TextBox15.Value = "";
    TextBox14.Value = "";
    TextBox16.Value = "";
    Select1.Value = "0";
    Select2.Value = "0";
    TextBox18.Value = "";
    SCTEST.Visible = false;

    }
    }
    #endregion
    #region 临时发票必填 订 单 详 情
    protected void Button10_Click(object sender, EventArgs e)
    {
    Button10.Attributes.Add("onclick", "return dnnModal.show('/DesktopModules/AGL_FP_DSR_KF_TONGJI/DingdanXIANGQING.aspx?fullName=" + TextBox32.Text + "&ID=" + TextBox6.Text + "&popUp=true',true,900,1000,false)");
    }
    #endregion
    protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
    {
    string zhe = DateTime.Now.ToString("yyyy-MM");
    //string zhe = "2018-01";
    string[] mon = zhe.Split('-');
    int m = Convert.ToInt32(mon[1]);
    int shang;
    shang = Convert.ToInt32(m) - 1;
    string sgy = "";
    if (shang < 10)
    {
    sgy = "0" + shang.ToString();
    }
    else
    {
    sgy = shang.ToString();
    }
    string nian;
    if (Convert.ToString(mon[1]) == "01")
    {
    nian = (Convert.ToInt32(mon[0]) - 1).ToString();
    sgy = "12";
    }
    else
    {
    nian = mon[0].ToString();
    }
    string gjp = DbHelper.DAL.GJPSqlServer;
    int a = this.DropDownList4.SelectedIndex;
    string getselectedSql = "SELECT inv.customer_id,inv.[user_id],invlinshi.beizhu,invlinshi.fengzFlag, inv.account_bank, inv.account_number, inv.id, invlinshi.id as linshiid, inv.statement,invlinshi.statement_ci,inv.identity_number,inv.address,inv.telephone,invlinshi.fp_type,invlinshi.state,c.fullname,inv.company,invlinshi.amount,invlinshi.creat_date FROM Invoices inv left join Invoices_linshi invlinshi on invlinshi.customer_id = inv.customer_id left join " + gjp + "btype c on c.typeid = inv.customer_id where inv.[user_id] =" + this.UserId.ToString() + " and invlinshi.[fengzFlag]=" + a + " and (( inv.statement ='1' and invlinshi.statement_ci='') or (inv.statement ='2' and invlinshi.statement_ci='1') or (inv.statement ='2' and invlinshi.statement_ci='2') or (inv.statement ='1' and invlinshi.statement_ci='1') or (inv.statement ='3' and invlinshi.statement_ci='2') ) and (left(invlinshi.creat_date,7) ='" + zhe + "' or invlinshi.creat_date ='2000-01-01') ORDER BY inv.id desc";
    C1GridView1.DataSource = DbHelper.DAL.ReplaceFullName(DbHelper.DAL.DateSet(getselectedSql).Tables[0], "fullname");
    C1GridView1.DataBind();

    }
    #region 临时发票必填 点击保存
    protected void Buttonbaocun_Click1(object sender, EventArgs e)
    {
    string zhe = DateTime.Now.ToString("yyyy-MM");
    //string zhe = "2018-01";
    string[] mon = zhe.Split('-');
    int m = Convert.ToInt32(mon[1]);
    int shang;
    shang = Convert.ToInt32(m) - 1;
    string sgy = "";
    if (shang < 10)
    {
    sgy = "0" + shang.ToString();
    }
    else
    {
    sgy = shang.ToString();
    }
    string nian;
    if (Convert.ToString(mon[1]) == "01")
    {
    nian = (Convert.ToInt32(mon[0]) - 1).ToString();
    sgy = "12";
    }
    else
    {
    nian = mon[0].ToString();
    }
    string fptype = this.TextBox22.Text;
    string customer_id = this.TextBox23.Text;
    string fp = this.DropDownList3.Value;
    string account_bank = this.TextBox24.Text;
    string account_number = this.TextBox25.Text;
    string identity_number = this.TextBox26.Text;
    string address = this.TextBox27.Text;
    string telephone = this.TextBox28.Text;
    string company = this.TextBox29.Text;
    string statement = this.TextBox30.Text;
    string jine1 = this.TextBox18.Value.Trim();
    string beizhu1 = this.beiz.Value.Trim();
    string billCodeS = TextBox35.Value.Trim();
    string billNumberS = "";
    string isBillCode = "";
    for (int i = 0; i < billCodeS.Split(',').Length;i++ )
    {
    object obj1=GJPDbHelper.DAL.ExecuteScalar("select BillNumberId from BillIndex where BillCode='"+billCodeS.Split(',')[i]+"'");
    if (obj1 == null || obj1.ToString() == "")
    {
    isBillCode = billCodeS.Split(',')[i];
    break;
    }
    else
    {
    if (billNumberS == "")
    {
    billNumberS = obj1.ToString();
    }
    else
    {

    billNumberS = billNumberS + "," + obj1.ToString();
    }
    }
    }
    if (isBillCode == "")
    {

    string[] bNids = billNumberS.Split(',');
    string isTrue = "";
    for (int z = 0; z < bNids.Length; z++)
    {
    string selectLS = "select count(*) from Invoices_linshi where [state] like '%" + bNids[z] + "%'";
    string countZ = DbHelper.DAL.ExecuteScalar(selectLS).ToString();
    if (countZ == "0")
    {

    }
    else
    {
    isTrue = billCodeS.Split(',')[z];//bNids[z];
    }
    }

    if (isTrue == "")
    {
    double isjine1 = 0;
    if (double.TryParse(jine1, out isjine1))
    {
    string str1 = "select fullname from btype where typeid ='" + customer_id + "'";
    object ob = GJPDbHelper.DAL.ExecuteScalar(str1);
    DbHelper.DAL.addOperation_Log(this.UserId.ToString(), "发票申请", "新增", "增加临时发票信息:对客户名称为" + ob.ToString() + "进行了新增临时发票");
    //if (fp == "增值税专用发票")
    //{
    // fp = "1";
    //}
    //else
    //{
    // fp = "2";
    //}
    if (statement == "固定月结")
    { statement = "1"; }
    else if (statement == "实次次结")
    { statement = "2"; }
    else
    {
    statement = "3";
    }
    if (billNumberS == "" || billNumberS == null)
    { }
    else
    {
    string str = "select SUM(total) from SaleBill where BillNumberId in(" + billNumberS + ")";
    object objsumbill = GJPDbHelper.DAL.ExecuteScalar(str);
    if (objsumbill == null || objsumbill.ToString() == "" || Convert.ToDouble(objsumbill) <= isjine1)
    {

    }
    else
    {
    beizhu1 = beizhu1 + "(价格与申请金额不一致)";
    }
    }

    int newcount = 0;
    if (statement == "1")
    {
    String newsqlInsert = "insert into Invoices_linshi([portal_id],[customer_id],[statement_ci],[state],[fp_type],[user_id],[creat_date],[amount],[fengzFlag],[duicuo],[beizhu]) values (0,'" + customer_id + "','1','" + billNumberS + "','" + fp + "','" + this.UserId.ToString() + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + jine1 + "',0,0,'" + beizhu1 + "');";
    newcount = DbHelper.DAL.ExecuteNonQuery(newsqlInsert);
    }else if (statement == "2")
    {
    String newsqlInsert = "insert into Invoices_linshi([portal_id],[customer_id],[statement_ci],[state],[fp_type],[user_id],[creat_date],[amount],[fengzFlag],[duicuo],[beizhu]) values (0,'" + customer_id + "','2','" + billNumberS + "','" + fp + "','" + this.UserId.ToString() + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + jine1 + "',0,0,'" + beizhu1 + "');";
    newcount = DbHelper.DAL.ExecuteNonQuery(newsqlInsert);
    }
    else
    {
    String newsqlInsert = "insert into Invoices_linshi([portal_id],[customer_id],[statement_ci],[state],[fp_type],[user_id],[creat_date],[amount],[fengzFlag],[duicuo],[beizhu]) values (0,'" + customer_id + "','2','" + billNumberS + "','" + fp + "','" + this.UserId.ToString() + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + jine1 + "',0,0,'" + beizhu1 + "');";
    newcount = DbHelper.DAL.ExecuteNonQuery(newsqlInsert);
    }


    if (newcount > 0)
    {

    string gjp = DbHelper.DAL.GJPSqlServer;
    string getnewSql = "SELECT inv.customer_id,inv.[user_id],invlinshi.beizhu,invlinshi.fengzFlag, inv.account_bank, inv.account_number, inv.id, invlinshi.id as linshiid, inv.statement,invlinshi.statement_ci,inv.identity_number,inv.address,inv.telephone,invlinshi.fp_type,invlinshi.state,c.fullname,inv.company,invlinshi.amount,invlinshi.creat_date FROM Invoices inv left join Invoices_linshi invlinshi on invlinshi.customer_id = inv.customer_id left join " + gjp + "btype c on c.typeid = inv.customer_id where inv.[user_id] =" + this.UserId.ToString() + " and invlinshi.[fengzFlag]=0 and (( inv.statement ='1' and invlinshi.statement_ci='') or (inv.statement ='2' and invlinshi.statement_ci='1') or (inv.statement ='2' and invlinshi.statement_ci='2') or (inv.statement ='1' and invlinshi.statement_ci='1') or (inv.statement ='3' and invlinshi.statement_ci='2') ) and (left(invlinshi.creat_date,7) ='" + zhe + "' or invlinshi.creat_date ='2000-01-01') ORDER BY inv.id desc";


    C1GridView1.DataSource = DbHelper.DAL.ReplaceFullName(DbHelper.DAL.DateSet(getnewSql).Tables[0], "fullname");
    C1GridView1.DataBind();

    this.TextBox6.Text = "";
    this.TextBox1.Value = "";

    this.TextBox18.Value = "";
    this.TextBox21.Value = "";
    this.beiz.Value = "";
    this.TextBox35.Value = "";
    Div12.Visible = false;
    Response.Write("<script>alert('添加成功!');window.location.href='" + ViewState["urllocation"] + "';</script>");
    }
    }
    else
    {
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('金额填写不正确!!!');", true);

    }
    }
    else
    {

    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('订单号" + isTrue + "已使用!!!');", true);
    }
    }
    else
    {
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('订单号" + isBillCode + "不存在!!!');", true);
    }
    }
    #endregion
    #region 分页事件
    protected void C1GridView2_PageIndexChanging(object sender, C1GridViewPageEventArgs e)
    {
    string test = " select id,name,FullName from view_selectCustomerWithGjp";
    DataTable SC = DbHelper.DAL.DateSet(test).Tables[0];
    C1GridView2.PageIndex = e.NewPageIndex;
    C1GridView2.DataSource = SC;
    C1GridView2.DataBind();
    }
    protected void C1GridView5_PageIndexChanging(object sender, C1GridViewPageEventArgs e)
    {
    string zhe = DateTime.Now.ToString("yyyy-MM");
    //string zhe = "2017-08";
    string[] mon = zhe.Split('-');
    int m = Convert.ToInt32(mon[1]);
    int shang;
    int sangeyue;
    shang = Convert.ToInt32(m) - 1;
    string sgy = "";
    if (shang < 10)
    {
    sgy = "0" + shang.ToString();
    }
    else
    {
    sgy = shang.ToString();
    }
    sangeyue = Convert.ToInt32(m) - 4;
    if (sangeyue <= 0)
    {
    sangeyue = 1;
    }
    string ssgy = "0" + sangeyue.ToString();
    //选择自己的客户赞威胁
    string gjp = DbHelper.DAL.GJPSqlServer;
    string test = " select inv.*,c.* from [Invoices] inv left join (select typeid as cusid,fullname from " + gjp + "btype) c on c.cusid = inv.customer_id order by inv.id desc";
    //string test = " select inv.*,c.* from [Invoices] inv left join (select id as cusid,fullname from customer) c on c.cusid = inv.customer_id where [user_id]=" + this.UserId.ToString() + "";
    //string test = " select id,name,FullName from view_selectCustomerWithGjp";
    DataTable SC = DbHelper.DAL.DateSet(test).Tables[0];
    C1GridView5.PageIndex = e.NewPageIndex;
    C1GridView5.DataSource = SC;
    C1GridView5.DataBind();
    }
    #endregion
    protected void Button5_Click1(object sender, EventArgs e)
    {

    }
    public void c1banding()
    {
    string zhe = DateTime.Now.ToString("yyyy-MM");
    //string zhe = "2018-01";
    string[] mon = zhe.Split('-');
    int m = Convert.ToInt32(mon[1]);
    int shang;
    shang = Convert.ToInt32(m) - 1;
    string sgy = "";
    if (shang < 10)
    {
    sgy = "0" + shang.ToString();
    }
    else
    {
    sgy = shang.ToString();
    }
    string nian;
    if (Convert.ToString(mon[1]) == "01")
    {
    nian = (Convert.ToInt32(mon[0]) - 1).ToString();
    sgy = "12";
    }
    else
    {
    nian = mon[0].ToString();
    }
    string gjp = DbHelper.DAL.GJPSqlServer;
    //string str = "SELECT inv.customer_id,inv.fengzFlag,inv.user_id,inv.account_bank, inv.account_number, inv.id, inv.statement,inv.statement_ci,inv.identity_number,inv.address,inv.telephone,inv.fp_type,inv.state,c.fullname,inv.company,inv.amount,inv.FPSHIJIAN,inv.flag,inv.creat_date,inv.beizhu FROM Invoices inv left join "+gjp+"btype c on c.typeid = inv.customer_id where inv.[user_id] = " + this.UserId.ToString() + " and inv.fengzFlag=0 and (inv.creat_date between '" + nian + "-" + sgy + "-26' and '" + zhe + "-25' or inv.creat_date ='2000-01-01') and (( inv.statement =1 and inv.statement_ci='') or (inv.statement =2 and inv.statement_ci=1) or (inv.statement =3 and inv.statement_ci!='') ) ORDER BY inv.id desc";

    string str = "SELECT inv.customer_id,inv.[user_id],invlinshi.beizhu,invlinshi.fengzFlag, inv.account_bank, inv.account_number, inv.id, invlinshi.id as linshiid, inv.statement,invlinshi.statement_ci,inv.identity_number,inv.address,inv.telephone,invlinshi.fp_type,invlinshi.state,invlinshi.id as linshiid,c.fullname,inv.company,invlinshi.amount,invlinshi.creat_date FROM Invoices inv left join Invoices_linshi invlinshi on invlinshi.customer_id = inv.customer_id left join " + gjp + "btype c on c.typeid = inv.customer_id where inv.[user_id] =" + this.UserId.ToString() + " and invlinshi.[fengzFlag]=0 and (( inv.statement ='1' and invlinshi.statement_ci='') or (inv.statement ='2' and invlinshi.statement_ci='1') or (inv.statement ='2' and invlinshi.statement_ci='2') or (inv.statement ='1' and invlinshi.statement_ci='1') or (inv.statement ='3' and invlinshi.statement_ci='2') ) and (left(invlinshi.creat_date,7) ='" + zhe + "' or invlinshi.creat_date ='2000-01-01') ORDER BY inv.id desc";
    C1GridView1.DataSource = DbHelper.DAL.ReplaceFullName(DbHelper.DAL.DateSet(str).Tables[0], "fullname");// DbHelper.DAL.DateSet(str).Tables[0];
    C1GridView1.DataBind();
    }

    protected void xiugaifp_Click(object sender, EventArgs e)
    {
    string linshiid=Label12.Text;
    double lsamount = 0;
    string linshiAmount = TextBox5.Value.ToString().Trim();//金额
    string billCodeS = TextBox36.Value.Trim();
    string billNumberS = "";
    string isBillCode = "";
    for (int i = 0; i < billCodeS.Split(',').Length;i++ )
    {
    object obj1=GJPDbHelper.DAL.ExecuteScalar("select BillNumberId from BillIndex where BillCode='"+billCodeS.Split(',')[i]+"'");
    if (obj1 == null || obj1.ToString() == "")
    {
    isBillCode = billCodeS.Split(',')[i];
    break;
    }
    else
    {
    if (billNumberS == "")
    {
    billNumberS = obj1.ToString();
    }
    else
    {

    billNumberS = billNumberS + "," + obj1.ToString();
    }
    }
    }
    if (isBillCode == "")
    {


    string[] bNids = billNumberS.Split(',');
    string isTrue = "";
    for (int z = 0; z < bNids.Length; z++)
    {
    string selectLS = "select count(*) from Invoices_linshi where [state] like '%" + bNids[z] + "%'";
    string countZ = DbHelper.DAL.ExecuteScalar(selectLS).ToString();
    if (countZ == "0")
    {

    }
    else
    {
    isTrue = bNids[z];
    }
    }

    if (isTrue == "")
    {

    if (double.TryParse(linshiAmount, out lsamount))
    {
    string ls_statement_ci = DropDownList2.Value;
    string beizhu = Textarea1.InnerText;

    beizhu = beizhu.Replace("(价格与申请金额不一致)", "");
    if (billNumberS == "" || billNumberS == null)
    { }
    else
    {
    object objsumbill = GJPDbHelper.DAL.ExecuteScalar("select SUM(total) from SaleBill where BillNumberId in(" + billNumberS + ");");
    if (objsumbill == null || objsumbill.ToString() == "" || Convert.ToDouble(objsumbill) <= lsamount)
    {

    }
    else
    {
    beizhu = beizhu + "(价格与申请金额不一致)";
    }
    }


    string updateSql = "UPDATE Invoices_linshi SET [statement_ci] = '" + ls_statement_ci + "',[amount] = '" + lsamount.ToString() + "',[state] = '" + billNumberS + "',[beizhu] = '" + beizhu + "' WHERE id=" + linshiid;
    int tpint = DbHelper.DAL.ExecuteNonQuery(updateSql);
    if (tpint > 0)
    {
    string str = "select customer_id from Invoices_linshi where id=" + linshiid;
    object ob = DbHelper.DAL.ExecuteScalar(str);
    string fullname = GJPDbHelper.DAL.findFullname(ob.ToString());
    DbHelper.DAL.addOperation_Log(this.UserId.ToString(), "发票申请", "修改", "对客户名称为" + fullname + " id为" + linshiid + "的发票进行了修改");
    Label12.Text = "";
    TextBox2.Value = "";
    TextBox3.Value = "";
    TextBox5.Value = "";
    TextBox36.Value = "";
    DropDownList1.Value = "";
    //DropDownList1.SelectedItem.Text = "";
    Textarea1.InnerText = "";
    TextBox7.Value = "";
    TextBox9.Value = "";
    DropDownList2.Value = "";
    //DropDownList2.SelectedItem.Text = "";//结算类型
    Textarea1.InnerText = "";
    PlaceHolder1.Visible = false;
    c1banding();
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('修改成功!!!');", true);
    }
    }
    else
    {
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('请正确输入金额!!!');", true);
    }
    }
    else
    {
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('订单号" + isTrue + "已使用!!!');", true);
    }
    }
    else
    {
    Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "alert('订单号" + isBillCode + "不存在!!!');", true);
    }
    }

    protected void quxiaofp_Click(object sender, EventArgs e)
    {
    Label12.Text = "";
    TextBox2.Value = "";
    TextBox3.Value = "";
    TextBox5.Value = "";
    TextBox36.Value = "";
    DropDownList1.Value = "";
    //DropDownList1.SelectedItem.Text = "";
    Textarea1.InnerText = "";
    TextBox7.Value = "";
    TextBox9.Value = "";
    DropDownList2.Value = "";
    //DropDownList2.SelectedItem.Text = "";//结算类型
    Textarea1.InnerText = "";
    PlaceHolder1.Visible = false;

    }
    //显示加载进度
    private void ShowLoanding()
    {
    Response.Write("<div style='position:absolute;z-index:600;expression(document.body.clientWidth);height:expression(document.body.clientHeight);background-color:#FFFFFF;text-align:center;padding-top:150px;' id='mydiv' >");
    Response.Write("<img src='http://www.kuwant.com/common/images/waiting.gif'>&nbsp;Loading...");
    Response.Write("</div>");
    Response.Write("<script language=javascript>;");
    Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
    Response.Write("window.setInterval('ShowWait()',1000);}");
    Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
    Response.Write("window.clearInterval();}");
    Response.Write("StartShowWait();window.location.href='" + ViewState["urllocation"] + "';</script>");
    Response.Flush();
    }
    }

    }

  • 相关阅读:
    索引总结篇
    数据库的安全管理
    数据库备份对日志文件的影响
    数据文件与日志文件读取机制
    更新操作所带来的影响
    页拆分-产生碎片
    你不可不知的T-SQL执行顺序
    实用T-SQL收集
    Left Join的神奇效果
    我对数据库索引的理解
  • 原文地址:https://www.cnblogs.com/1971855407qq/p/8539040.html
Copyright © 2020-2023  润新知