private void setData(string id)
    {
        if (string.IsNullOrEmpty(id))
        {
            return;
        }
        ProfitBudgetAdapter pba  = new ProfitBudgetAdapter();
        DataSet             head = pba.getProfitBudgetSummaryByID(id);

        lblt_sale_bill_no.Text = id;
        lbl_extra_charges.Text = Decimal.Parse(head.Tables[0].Rows[0]["extra_charges"].ToString()).ToString("f2");

        DataSet list = pba.getProfitBudgetList(id);

        gridviewBind(list);
    }
    protected void submit_Click(object sender, EventArgs e)
    {
        ProfitBudgetAdapter pba = new ProfitBudgetAdapter();

        //收集利润核算表头信息
        T_ProfitAccounting item = new T_ProfitAccounting();

        item.UpdateTime = DateTime.Now;
        decimal extra_charges = 0;

        if (!string.IsNullOrEmpty(txt_extra_charges.Text.Trim()))
        {
            extra_charges += Decimal.Parse(txt_extra_charges.Text.Trim());
        }

        if (!string.IsNullOrEmpty(txt_extra_charges_lists_all.Text.Trim()))
        {
            extra_charges += Decimal.Parse(txt_extra_charges_lists_all.Text.Trim());
        }
        item.ExtraCharges  = extra_charges;
        item.FInterID      = finterid;
        item.SaleBillNo    = sale_bill_no;
        item.AuditState    = false;
        item.IsActualAudit = false;

        //收集利润核算表体信息
        List <T_ProfitAccountingList> lists = new List <T_ProfitAccountingList>();
        List <T_ProfitBudgetList>     pbls  = new List <T_ProfitBudgetList>();

        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            T_ProfitAccountingList list = new T_ProfitAccountingList();
            T_ProfitBudgetList     pbl  = new T_ProfitBudgetList();

            list.FInterID     = Int32.Parse(((HiddenField)GridView1.Rows[i].Cells[18].FindControl("hdf_finter_id")).Value);
            list.SaleFentryid = Int32.Parse(((HiddenField)GridView1.Rows[i].Cells[18].FindControl("hdf_sale_fentry_id")).Value);
            list.BuyFentryid  = Int32.Parse(((HiddenField)GridView1.Rows[i].Cells[18].FindControl("hdf_buy_fentry_id")).Value);
            list.FItemID      = Int32.Parse(((HiddenField)GridView1.Rows[i].Cells[18].FindControl("hdf_fitem_id")).Value);
            list.SaleBillNo   = sale_bill_no;
            list.BuyBillNo    = GridView1.Rows[i].Cells[0].Text;
            list.FName        = GridView1.Rows[i].Cells[1].Text;
            list.FNumber      = GridView1.Rows[i].Cells[2].Text;
            list.DeptId       = Int32.Parse(((HiddenField)GridView1.Rows[i].Cells[18].FindControl("hdf_dept_id")).Value);
            list.EmpId        = Int32.Parse(((HiddenField)GridView1.Rows[i].Cells[18].FindControl("hdf_emp_id")).Value);
            list.SalePrice    = Decimal.Parse(GridView1.Rows[i].Cells[3].Text);
            list.Currency     = GridView1.Rows[i].Cells[4].Text;
            TextBox txt_exchange_rate = (TextBox)GridView1.Rows[i].Cells[5].FindControl("txt_exchange_rate");
            if (string.IsNullOrEmpty(txt_exchange_rate.Text))
            {
                list.ExchangeRate = 0;
            }
            else
            {
                list.ExchangeRate = Decimal.Parse(txt_exchange_rate.Text);
            }
            list.BuyPrice  = Decimal.Parse(GridView1.Rows[i].Cells[7].Text);
            list.SaleQty   = Decimal.Parse(GridView1.Rows[i].Cells[9].Text);
            list.BuyQty    = Decimal.Parse(GridView1.Rows[i].Cells[10].Text);
            list.Accessory = (GridView1.Rows[i].Cells[11].FindControl("txt_accessory") as TextBox).Text;
            TextBox txt_accessory_price = GridView1.Rows[i].Cells[12].FindControl("txt_accessory_price") as TextBox;
            if (!String.IsNullOrEmpty(txt_accessory_price.Text))
            {
                list.AccessoryPrice = Decimal.Parse(txt_accessory_price.Text);
            }
            else
            {
                list.AccessoryPrice = 0;
            }
            string length = (GridView1.Rows[i].Cells[13].FindControl("txt_length") as TextBox).Text;
            if (string.IsNullOrEmpty(length))
            {
                list.Length = 0;
            }
            else
            {
                list.Length = Decimal.Parse(length);
            }
            string width = (GridView1.Rows[i].Cells[13].FindControl("txt_width") as TextBox).Text;
            if (string.IsNullOrEmpty(width))
            {
                list.Width = 0;
            }
            else
            {
                list.Width = Decimal.Parse(width);
            }
            string height = (GridView1.Rows[i].Cells[13].FindControl("txt_height") as TextBox).Text;
            if (string.IsNullOrEmpty(height))
            {
                list.Height = 0;
            }
            else
            {
                list.Height = Decimal.Parse(height);
            }
            string capacity = (GridView1.Rows[i].Cells[16].FindControl("txt_capacity") as TextBox).Text;
            if (string.IsNullOrEmpty(capacity))
            {
                list.Capacity = 0;
            }
            else
            {
                list.Capacity = Decimal.Parse(capacity);
            }
            string estimate_freight_charge = (GridView1.Rows[i].Cells[15].FindControl("txt_estimate_freight_charge") as TextBox).Text;
            if (string.IsNullOrEmpty(estimate_freight_charge))
            {
                list.EstimateFreightCharge = 0;
            }
            else
            {
                list.EstimateFreightCharge = Decimal.Parse(estimate_freight_charge);
            }
            string tax_rate = (GridView1.Rows[i].Cells[17].FindControl("txt_tax_rate") as TextBox).Text;
            if (string.IsNullOrEmpty(tax_rate))
            {
                list.TaxRate = 0;
            }
            else
            {
                list.TaxRate = Decimal.Parse(tax_rate);
            }
            list.SaleRate = GridView1.Rows[i].Cells[6].Text == "是" ? true : false;
            list.BuyRate  = GridView1.Rows[i].Cells[8].Text == "是" ? true : false;
            string profit = (GridView1.Rows[i].Cells[19].FindControl("lbl_profit") as Label).Text;
            if (string.IsNullOrEmpty(profit))
            {
                list.Profit = 0;
            }
            else
            {
                list.Profit = Decimal.Parse(profit);
            }
            string volume = (GridView1.Rows[i].Cells[14].FindControl("lbl_volume") as Label).Text;
            if (string.IsNullOrEmpty(volume))
            {
                list.Volume = 0;
            }
            else
            {
                list.Volume = Decimal.Parse(volume);
            }
            string return_rate = (GridView1.Rows[i].Cells[18].FindControl("txt_return_rate") as TextBox).Text;
            if (string.IsNullOrEmpty(return_rate))
            {
                list.ReturnRate = 0;
            }
            else
            {
                list.ReturnRate = Decimal.Parse(return_rate);
            }
            Label lbCommission = GridView1.Rows[i].Cells[20].FindControl("lbl_commission") as Label;
            list.Commission = Decimal.Parse(lbCommission.Text);
            list.SEOrderID  = GridView1.Rows[i].Cells[21].Text;
            lists.Add(list);

            pbl.BuyFentryid = list.BuyFentryid;
            pbl.SaleBillNo  = list.SEOrderID;
            pbl.BuyBillNo   = list.BuyBillNo;

            DataSet ds = pba.getProfitBudgetList(pbl);
            decimal un_accounting_qty = Decimal.Parse(ds.Tables[0].Rows[0]["un_accounting_qty"].ToString());
            pbl.UnAccountingQty = un_accounting_qty - list.SaleQty;
            if (un_accounting_qty - list.SaleQty == 0)
            {
                pbl.CheckStatus = true;
            }
            else
            {
                pbl.CheckStatus = false;
            }
            pbls.Add(pbl);
        }
        try
        {
            //更新check_status字段为true,如果表体相关记录check_status字段全为true
            //var query1 = (from tt in pbls
            //            where tt.CheckStatus == true
            //             select tt.SaleBillNo).Distinct().ToList();
            //var query2 = (from tt in pbls
            //              where tt.CheckStatus == false
            //              select tt.SaleBillNo).Distinct().ToList();
            //var query = query1.Except(query2).ToList();



            ProfitAccountingAdapter paa = new ProfitAccountingAdapter();
            paa.addProfitBudgetHead(item);
            paa.addProfitBudgetList(lists);

            pba.updateList(pbls);

            Label2.Text    = "保存成功!";
            Label2.Visible = true;
        }
        catch (Exception ex)
        {
            Label2.Text    = ex.Message;
            Label2.Visible = true;
            return;
        }
    }