protected void ListViewRepairSheet_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                ListViewDataItem DataItem = (ListViewDataItem)e.Item;
                DataRowView      dv       = (DataRowView)DataItem.DataItem;
                AfterSaleServiceSystem.DAL.dsRepairSheet.tb_repairsheetRow repairsheetRow = (AfterSaleServiceSystem.DAL.dsRepairSheet.tb_repairsheetRow)dv.Row;

                tb_repairstateTableAdapter repairstateTableAdapter = new tb_repairstateTableAdapter();
                if (repairstateTableAdapter.GetDatabyid(repairsheetRow.repairstateid).Rows.Count > 0)
                {
                    AfterSaleServiceSystem.DAL.dsRepairState.tb_repairstateRow repairstateRow =
                        (AfterSaleServiceSystem.DAL.dsRepairState.tb_repairstateRow)
                        repairstateTableAdapter.GetDatabyid(repairsheetRow.repairstateid).Rows[0];
                    Label lb = (Label)e.Item.FindControl("repairstateidLabel");
                    if (lb != null)
                    {
                        lb.Text = repairstateRow.description;
                    }
                }

                tb_customTableAdapter customTableAdapter = new tb_customTableAdapter();
                if (customTableAdapter.GetDataByid(repairsheetRow.customid).Rows.Count > 0)
                {
                    AfterSaleServiceSystem.DAL.dsCustomer.tb_customRow customRow =
                        (AfterSaleServiceSystem.DAL.dsCustomer.tb_customRow)
                        customTableAdapter.GetDataByid(repairsheetRow.customid).Rows[0];
                    Label lb = (Label)e.Item.FindControl("customidLabel");
                    if (lb != null)
                    {
                        lb.Text = customRow.company;
                    }
                }
            }
        }
        /// <summary>
        /// 点击FormView里面的按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>修改------------------------------------------</remarks>
        protected void FormView_Report_ItemCommand(object sender, FormViewCommandEventArgs e)
        {
            string eName = e.CommandName.ToString();
            try
            {
                if (eName == "Set")
                {
                    //更新tb_custom表
                    string company = companyLabel.Text.Trim();
                    string address = addressLabel.Text.Trim();
                    string name = nameLabel.Text.Trim();
                    string tel = telephoneLabel.Text.Trim();
                    string fax = faxLabel.Text.Trim();
                    int customid = Convert.ToInt32(ddlCustom.SelectedValue);
                    tb_customTableAdapter custom = new tb_customTableAdapter();
                    AfterSaleServiceSystem.DAL.dsCustomer.tb_customRow row = (AfterSaleServiceSystem.DAL.dsCustomer.tb_customRow)custom.GetDataByid(customid).Rows[0];
                    row.company = company;
                    row.address = address;
                    row.name = name;
                    row.telephone = tel;
                    row.fax = fax;
                    custom.Update(row);

                    //更新tb_repairsheet表
                    string producttype = ((TextBox)FormView_Report.FindControl("TextBoxproducttype")).Text;
                    string productnumber = ((TextBox)FormView_Report.FindControl("TextBoxproductnumber")).Text;
                    int userID = 0;
                    if (Session["authorityid"] != null && Session["authorityid"].ToString() == "1")
                    {
                        userID = Convert.ToInt32(Session["UserId"]);
                    }

                    AfterSaleServiceSystem.DAL.dsRepairSheetTableAdapters.tb_repairsheetTableAdapter sheetadp =
                           new AfterSaleServiceSystem.DAL.dsRepairSheetTableAdapters.tb_repairsheetTableAdapter();
                    sheetadp.UpdateQueryForRepairSheet(ReqGUID, producttype, productnumber, 0, userID, Convert.ToInt32(ddlCustom.SelectedValue), 0, SheetId);

                    bool warrantyperiod = ((CheckBox)FormView_Report.FindControl("cbwarrantyperiod")).Checked;
                    DateTime modifytime = DateTime.Now;
                    DateTime.TryParse(((TextBox)FormView_Report.FindControl("TextBoxEdtTime")).Text, out modifytime);
                    if (modifytime == DateTime.MinValue)
                    {
                        modifytime = DateTime.Now;
                    }

                    string productname = ((TextBox)FormView_Report.FindControl("TextBoxproducttype")).Text;
                    string softwareVersion = ((TextBox)FormView_Report.FindControl("TextBoxsoftwareVersion")).Text;
                    string errorcode = ((TextBox)FormView_Report.FindControl("TextBoxerrorcode")).Text;
                    string breakdowndescription = ((TextBox)FormView_Report.FindControl("TextBoxbreakdowndescription")).Text;
                    string breakdownreason = ((TextBox)FormView_Report.FindControl("TextBoxbreakdownreason")).Text;
                    string resulttofrepair = ((TextBox)FormView_Report.FindControl("TextBoxresultofrepair")).Text;

                    decimal laborcost = 0;
                    decimal.TryParse(((TextBox)FormView_Report.FindControl("TextBoxlaborcost")).Text, out laborcost);

                    decimal partcost = 0;
                    decimal.TryParse(((TextBox)FormView_Report.FindControl("TextBoxpartcost")).Text, out partcost);

                    decimal testcost = 0;
                    decimal.TryParse(((TextBox)FormView_Report.FindControl("TextBoxtestcost")).Text, out testcost);

                    decimal tranitcost = 0;
                    decimal.TryParse(((TextBox)FormView_Report.FindControl("TextBoxtransitcost")).Text, out tranitcost);

                    DateTime starttime = DateTime.Now;
                    DateTime.TryParse(((TextBox)FormView_Report.FindControl("TextBoxStartTime")).Text, out starttime);
                    if (starttime == DateTime.MinValue)
                    {
                        starttime = DateTime.Now;
                    }

                    DateTime endtime = DateTime.Now;
                    DateTime.TryParse(((TextBox)FormView_Report.FindControl("TextBoxEndTime")).Text, out endtime);
                    if (endtime == DateTime.MinValue)
                    {
                        endtime = DateTime.Now;
                    }

                    string type_delivery = ((TextBox)FormView_Report.FindControl("TextBoxtype_delivery")).Text;
                    string awbnumber_delivery = ((TextBox)FormView_Report.FindControl("TextBoxawbnumber_delivery")).Text;
                    DateTime time_delivery = DateTime.Now;
                    DateTime.TryParse(((TextBox)FormView_Report.FindControl("TextBoxSendTime")).Text, out time_delivery);
                    if (time_delivery == DateTime.MinValue)
                    {
                        time_delivery = DateTime.Now;
                    }

                    AfterSaleServiceSystem.DAL.dsReportsTableAdapters.tb_reportsTableAdapter reportAdp =
                           new AfterSaleServiceSystem.DAL.dsReportsTableAdapters.tb_reportsTableAdapter();

                    reportAdp.UpdateQueryForReports(userID, SheetId, warrantyperiod, modifytime, productname, productnumber,
                        softwareVersion, errorcode, breakdowndescription, breakdownreason, resulttofrepair, laborcost, partcost, testcost,
                        tranitcost, starttime, endtime, type_delivery, awbnumber_delivery, time_delivery, ReportId);

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "<script type='text/javascript'>创建成功</script>", true);
                }
                else if (eName == "Return")
                {
                    Response.Redirect("/Supervisor/getBarCode.aspx");
                }
            }
            catch (Exception ex) { ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "<script type='text/javascript'>创建失败</script>", true); }
        }
 private void BindCustom()
 {
     int customid = Convert.ToInt32(ddlCustom.SelectedValue);
     tb_customTableAdapter custom = new tb_customTableAdapter();
     AfterSaleServiceSystem.DAL.dsCustomer.tb_customRow row = (AfterSaleServiceSystem.DAL.dsCustomer.tb_customRow)custom.GetDataByid(customid).Rows[0];
     companyLabel.Text = row.company;
     addressLabel.Text = row.address;
     nameLabel.Text = row.name;
     telephoneLabel.Text = row.telephone;
     faxLabel.Text = row.fax;
 }
        //提交之后回主页面
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserId"] == null)
            {
                Response.Redirect("/LogIn.ashx");
                return;
            }

            ReqGUID = Request["GUID"];
            Label_GUID.Text = ReqGUID;
            AfterSaleServiceSystem.DAL.dsRepairSheetTableAdapters.tb_repairsheetTableAdapter sheetadp =
                new AfterSaleServiceSystem.DAL.dsRepairSheetTableAdapters.tb_repairsheetTableAdapter();
            System.Data.DataRowCollection RsRows = sheetadp.GetDataByGUID(ReqGUID).Rows;
            if (RsRows.Count > 0)
            {
                FormView_Report.ChangeMode(FormViewMode.Edit);
                FormView_Report.DefaultMode = FormViewMode.Edit;

                AfterSaleServiceSystem.DAL.dsRepairSheet.tb_repairsheetRow RsRow =
                  (AfterSaleServiceSystem.DAL.dsRepairSheet.tb_repairsheetRow)RsRows[0];
                SheetId = RsRow.id;

                tb_reportsTableAdapter reportAdp = new tb_reportsTableAdapter();
                AfterSaleServiceSystem.DAL.dsReports.tb_reportsDataTable dtReports = reportAdp.GetDataBysheetid(SheetId);
                if (dtReports.Rows.Count > 0)
                {
                    AfterSaleServiceSystem.DAL.dsReports.tb_reportsRow rRow =
                  (AfterSaleServiceSystem.DAL.dsReports.tb_reportsRow)dtReports[0];
                    ReportId = rRow.id;
                }
            }

            if (!IsPostBack)
            {
                if (RsRows.Count == 0)
                {
                    FormView_Report.ChangeMode(FormViewMode.Edit);

                    //新建一条记录
                    sheetadp.InsertNewSheet(ReqGUID, string.Empty, string.Empty, 0, 0, 0, 0);

                    RsRows = sheetadp.GetDataByGUID(ReqGUID).Rows;
                    if (RsRows.Count > 0)
                    {
                        AfterSaleServiceSystem.DAL.dsRepairSheet.tb_repairsheetRow RsRow =
                          (AfterSaleServiceSystem.DAL.dsRepairSheet.tb_repairsheetRow)RsRows[0];
                        SheetId = RsRow.id;

                        tb_reportsTableAdapter reportAdp = new tb_reportsTableAdapter();

                        int userID = 0;
                        if (Session["authorityid"].ToString() == "1")
                        {
                            userID = Convert.ToInt32(Session["UserId"]);
                        }

                        reportAdp.Insert(userID, SheetId, false, DateTime.Today,
                            string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
                            string.Empty, 0, 0, 0, 0, null, null, string.Empty, string.Empty, null);

                        AfterSaleServiceSystem.DAL.dsReports.tb_reportsDataTable dtReports = reportAdp.GetDataBysheetid(SheetId);
                        if (dtReports.Rows.Count > 0)
                        {
                            AfterSaleServiceSystem.DAL.dsReports.tb_reportsRow rRow =
                          (AfterSaleServiceSystem.DAL.dsReports.tb_reportsRow)dtReports[0];
                            ReportId = rRow.id;
                        }
                    }
                }

                #region 绑定代理商
                tb_customTableAdapter custom = new tb_customTableAdapter();
                AfterSaleServiceSystem.DAL.dsCustomer.tb_customDataTable customDt = custom.GetData();
                ddlCustom.DataTextField = "agent";
                ddlCustom.DataValueField = "id";
                ddlCustom.DataSource = customDt;
                ddlCustom.DataBind();
                BindCustom();
                #endregion
            }
        }
        protected void ListViewRepairSheet_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                ListViewDataItem DataItem = (ListViewDataItem)e.Item;
                DataRowView dv = (DataRowView)DataItem.DataItem;
                AfterSaleServiceSystem.DAL.dsRepairSheet.tb_repairsheetRow repairsheetRow = (AfterSaleServiceSystem.DAL.dsRepairSheet.tb_repairsheetRow)dv.Row;

                tb_repairstateTableAdapter repairstateTableAdapter = new tb_repairstateTableAdapter();
                if (repairstateTableAdapter.GetDatabyid(repairsheetRow.repairstateid).Rows.Count > 0)
                {
                    AfterSaleServiceSystem.DAL.dsRepairState.tb_repairstateRow repairstateRow =
                        (AfterSaleServiceSystem.DAL.dsRepairState.tb_repairstateRow)
                        repairstateTableAdapter.GetDatabyid(repairsheetRow.repairstateid).Rows[0];
                    Label lb = (Label)e.Item.FindControl("repairstateidLabel");
                    if (lb != null)
                        lb.Text = repairstateRow.description;
                }

                tb_customTableAdapter customTableAdapter = new tb_customTableAdapter();
                if (customTableAdapter.GetDataByid(repairsheetRow.customid).Rows.Count > 0)
                {
                    AfterSaleServiceSystem.DAL.dsCustomer.tb_customRow customRow =
                        (AfterSaleServiceSystem.DAL.dsCustomer.tb_customRow)
                        customTableAdapter.GetDataByid(repairsheetRow.customid).Rows[0];
                    Label lb = (Label)e.Item.FindControl("customidLabel");
                    if (lb != null)
                        lb.Text = customRow.company;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserId"] == null)
            {
                Response.Redirect("/LogIn.ashx");
                return;
            }
            try
            {
                sheetid = Convert.ToInt32(Request["id"]);

                #region 绑定客户数据
                tb_repairsheetTableAdapter sheet = new tb_repairsheetTableAdapter();
                dsRepairSheet.tb_repairsheetDataTable sheetDt = sheet.GetDataByid(sheetid);
                if (sheetDt != null && sheetDt.Rows.Count > 0)
                {
                    dsRepairSheet.tb_repairsheetRow row = (dsRepairSheet.tb_repairsheetRow)sheetDt.Rows[0];
                    tb_customTableAdapter custom = new tb_customTableAdapter();
                    AfterSaleServiceSystem.DAL.dsCustomer.tb_customDataTable customDt = custom.GetDataByid(Convert.ToInt32(row.customid));
                    FormView_custom.DataSource = customDt;
                    FormView_custom.DataBind();
                }
                #endregion

            }
            catch (Exception)
            {
                //
                throw;
            }

            Label_No.Text = sheetid.ToString();

            tb_reportsTableAdapter reports = new tb_reportsTableAdapter();

            if (reports.GetDataBysheetid(sheetid).Rows.Count > 0)
            {
                FormView_report.DefaultMode = FormViewMode.Edit;
            }
            else
                FormView_report.DefaultMode = FormViewMode.Insert;
        }