/// <summary>
 /// 选择所属公司
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void txtChooseCompanty_ChooserClick(object sender, EventArgs e)
 {
     frmChooseCompany frm = new frmChooseCompany();
     DialogResult result = frm.ShowDialog();
     if (result == DialogResult.OK)
     {
         txtChooseCompanty.Text = frm.Company_Name;
         txtChooseCompanty.Tag = frm.Company_ID;
     }
 }
        private void InitControlDataSource() //初始化数据字段控件数据
        {
            try
            {
                dgv_tb_maintain_three_guaranty_accessory.TableName = "tb_maintain_three_guaranty";
                dgv_tb_maintain_three_guaranty_accessory.TableNameKeyValue = TgId;

                #region 基础数据
                var isSecondStation = DBHelper.GetSingleValue("根据公司编码获取是否为二级站", GlobalStaticObj.CommAccCode, "tb_company", "category", "sap_code = '" + GlobalStaticObj.ServerStationCode+ "'", "");
                if (!String.IsNullOrEmpty(isSecondStation))
                {
                    chk_whether_second_station_true.Checked = isSecondStation == "1";    //一级站
                    chk_whether_second_station_false.Checked = isSecondStation == "2";    //二级站
                }
                txt_service_station_code.Text = GlobalStaticObj.ServerStationCode; //当前服务站代码
                txt_service_station_name.Caption = GlobalStaticObj.ServerStationName; //当前服务站名称

                dtp_repairs_time.Value = DateTime.Now;  //报修日期(系统默认当前时间)

                CommonCtrl.CmbBindDict(cbo_receipt_type, "bill_type_yt", false);   //宇通单据类型
                CommonCtrl.CmbBindDict(cbo_cost_type_service_zczg, "cost_type_care_policy_yt", false);   //费用类型(政策照顾)
                CommonCtrl.BindComboBoxByTable(cbo_product_notice_no, "tb_product_no", "service_code", "activities", false);   //产品改进通知

                CommonCtrl.CmbBindDict(cbo_whether_go_out, "sys_true_false", false);   //是否外出
                cbo_whether_go_out.SelectedValue = DbDic2Enum.FALSE;    //是否外出(默认选择为否)

                CommonCtrl.CmbBindDict(cbo_refit_case, "refit_case", false);   //改装情况
                cbo_refit_case.SelectedValue = DbDic2Enum.REFIT_CASE_FALSE;    //改装请款(默认选择为无改装)

                DataSources.BindComBoxDataEnum(cbo_promise_guarantee, typeof(DataSources.EnumYesNo), false);   //特殊约定质保
                cbo_promise_guarantee.SelectedValue = DataSources.EnumYesNo.NO;    //特殊约定质保(默认选择为否)
                UIAssistants.BindingServiceStationUser(cbo_approver_name_yt, true, "请选择");
                txt_appraiser_name.ChooserClick += delegate   //宇通批准人(鉴定人)选择器
                {
                    var chooser = new frmUsers{ cbo_data_source = { SelectedValue = "2", Enabled = false } };
                    var result = chooser.ShowDialog();
                    if (result != DialogResult.OK) return;
                    if (String.IsNullOrEmpty(chooser.User_Name) || String.IsNullOrEmpty(chooser.CrmId))
                    {
                        MessageBoxEx.Show("选择的数据不符合使用要求");
                        return;
                    }
                    //txt_approver_name_yt.Text = chooser.contName;
                    //txt_approver_name_yt.Tag = chooser.crmId;
                    txt_appraiser_name.Text = chooser.User_Name;
                    txt_appraiser_name.Tag = chooser.CrmId;
                };
                txt_repair_man.ChooserClick += delegate   //维修人
                {
                    var chooser = new frmUsers{ cbo_data_source = { SelectedValue = "2", Enabled = false } };
                    var result = chooser.ShowDialog();
                    if (result != DialogResult.OK) return;
                    if (String.IsNullOrEmpty(chooser.User_Name) || String.IsNullOrEmpty(chooser.CrmId))
                    {
                        MessageBoxEx.Show("选择的数据不符合使用要求");
                        return;
                    }
                    //txt_approver_name_yt.Text = chooser.contName;
                    //txt_approver_name_yt.Tag = chooser.crmId;
                    txt_repair_man.Text = chooser.User_Name;
                    txt_repair_man.Tag = chooser.CrmId;
                };

                CommonCtrl.BindComboBoxByTable(cbo_cost_type_service_fwhd, "tb_product_no", "service_code", "activities", false);   //费用类型(服务活动) unknow

                CommonCtrl.CmbBindDict(cbo_customer_property, "custom_property_yt", false);   //客户性质
                txt_vehicle_use_corp.ChooserClick += delegate  //车辆使用单位选择器
                {
                    var custChooser = new frmCustomerInfo();
                    var result = custChooser.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        if (String.IsNullOrEmpty(custChooser.CustomerInfo.CustName) || String.IsNullOrEmpty(custChooser.CustomerInfo.SAPCode))
                        {
                            MessageBoxEx.Show("选择的数据不符合使用要求");
                            return;
                        }
                        txt_vehicle_use_corp.Text = custChooser.CustomerInfo.CustName;
                        txt_vehicle_use_corp.Tag = custChooser.CustomerInfo.SAPCode;
                    }
                };
                txt_customer_code.ChooserClick += delegate  //客户信息选择器
                {
                    var custChooser = new frmCustomerInfo();
                    var result = custChooser.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        if (String.IsNullOrEmpty(custChooser.CustomerInfo.CustCode))
                        {
                            MessageBoxEx.Show("选择的数据不符合使用要求");
                            return;
                        }
                        txt_customer_code.Text = custChooser.CustomerInfo.CustCode;
                        txt_customer_code.Tag = custChooser.CustomerInfo.CustId;
                        txt_customer_name.Caption = custChooser.CustomerInfo.CustName;
                        txt_customer_address.Caption = custChooser.CustomerInfo.CustAddress;
                        txt_customer_postcode.Caption = custChooser.CustomerInfo.ZipCode;

                        //联系人数据                
                        var dpt = DBHelper.GetTable("联系人数据", "(select tr.relation_object_id, tr.is_default tr_is_default, tb.*  from tb_contacts tb inner join tr_base_contacts tr on tb.cont_id = tr.cont_id) a", "*",
                            string.Format(" a.relation_object_id='{0}'", custChooser.CustomerInfo.CustId), "", "");
                        if (dpt != null && dpt.Rows.Count > 0)
                        {
                            for (var i = 0; i < dpt.Rows.Count; i++)
                            {
                                var dpr = dpt.Rows[i];
                                if (CommonCtrl.IsNullToString(dpr["tr_is_default"]) == "1")
                                {
                                    txt_linkman.Caption = CommonCtrl.IsNullToString(dpr["cont_name"]);
                                    txt_link_man_mobile.Caption = CommonCtrl.IsNullToString(dpr["cont_phone"]);
                                }
                            }
                        }
                        ValidationCustomer();
                    }
                };
                txt_customer_code.Leave += delegate     //客户信息校验
                {
                    ValidationCustomer();
                };
                #endregion

                #region 车辆信息
                CommonCtrl.BindComboBoxByDictionarr(cbo_fault_cause, "cause_fault_yt", false);   //故障原因
                CommonCtrl.BindComboBoxByDictionarr(cbo_fault_duty_corp, "fault_company_yt", false);   //故障责任单位
                txt_vehicle_no.ChooserClick += delegate  //车辆选择器
                {
                    var chooser = new frmVehicleGrade();
                    var result = chooser.ShowDialog();
                    if (result != DialogResult.OK) return;
                    txt_vehicle_no.Text = chooser.strLicensePlate; //车牌号
                    txt_depot_no.Text = chooser.Turner;  //车工号
                    txt_vehicle_vin.Caption = chooser.strVIN;   //VIN
                    txt_engine_num.Caption = chooser.strEngineNum; //发动机号
                    txt_vehicle_model.Tag = chooser.strModel;  //车型
                    ValidationVehicle();
                    //txt_maintain_mileage.Caption = chooser.MaintainMileage; //协议保养里程
                    //txt_maintain_time.Caption = chooser.MaintainTime;    //协议保养日期
                };
                txt_depot_no.ChooserClick += delegate  //车工号选择器
                {
                    var chooser = new frmVehicleGrade();
                    var result = chooser.ShowDialog();
                    if (result != DialogResult.OK) return;
                    txt_vehicle_no.Text = chooser.strLicensePlate; //车牌号
                    txt_depot_no.Text = chooser.Turner;  //车工号
                    txt_vehicle_vin.Caption = chooser.strVIN;   //VIN
                    txt_engine_num.Caption = chooser.strEngineNum; //发动机号
                    txt_vehicle_model.Tag = chooser.strModel;  //车型
                    ValidationDepto();
                    //txt_maintain_mileage.Caption = chooser.MaintainMileage; //协议保养里程
                    //txt_maintain_time.Caption = chooser.MaintainTime;    //协议保养日期
                };
                txt_vehicle_no.Leave += delegate     //车辆信息校验
                {
                    ValidationVehicle();
                };
                txt_depot_no.Leave += delegate     //车辆信息校验
                {
                    ValidationDepto();
                };

                txt_vehicle_model.ChooserClick += delegate  //车型选择器
                {
                    var chooser = new frmVehicleModels();
                    var result = chooser.ShowDialog();
                    if (result != DialogResult.OK) return;
                    txt_vehicle_model.Text = chooser.VMName;  //车型
                    txt_vehicle_model.Tag = chooser.VMID;
                    _vmClass = chooser.VMClass;
                };

                txt_fault_system.ChooserClick += delegate  //故障系统选择器
                {
                    var chooser = new FormChooserFault();
                    var result = chooser.ShowDialog();
                    if (result != DialogResult.OK) return;

                    txt_fault_system.Text = chooser.SystemName;
                    txt_fault_system.Tag = chooser.SystemCode;
                    txt_fault_assembly.Caption = chooser.AssemblyName;
                    txt_fault_assembly.Tag = chooser.AssemblyCode;
                    txt_fault_part.Caption = chooser.PartmName;
                    txt_fault_part.Tag = chooser.PartCode;
                    //txt_fault_schema.Text = chooser.SchemaName;
                    //txt_fault_schema.Tag = chooser.SchemaCode;

                };
                txt_fault_system.Leave += delegate
                {
                    ValidationJDR();
                };
                txt_fault_schema.ChooserClick += delegate  //故障模式选择器
                {
                    var chooser = new FormChooserFaultModel();
                    var result = chooser.ShowDialog();
                    if (result != DialogResult.OK) return;
                    txt_fault_schema.Text = chooser.FmeaName;
                    txt_fault_schema.Tag = chooser.FmeaCode;
                };
                #endregion

                #region 外出信息
                CommonCtrl.BindComboBoxByDictionarr(cbo_whether_yt, "sys_true_false", false);   //是否宇通车
                if(cbo_whether_yt.Items.Contains("0")) cbo_whether_yt.SelectedValue = "0";
                CommonCtrl.BindComboBoxByDictionarr(cbo_means_traffic, "traffic_mode_yt", false);   //外出交通方式
                if (cbo_means_traffic.Items.Count > 0) cbo_means_traffic.SelectedIndex = 0;
                cbo_means_traffic.SelectedIndexChanged += delegate
                {
                    if (CommonCtrl.IsNullToString(cbo_means_traffic.SelectedValue) ==
                        DbDic2Enum.TRAFFIC_MODE_YT_100000000)
                    {
                        txt_journey_subsidy.Enabled = false;
                    }
                    else
                    {
                        txt_journey_subsidy.Enabled = true;
                    }
                };

                UIAssistants.BindingServiceStationUser(cbo_goout_approver, true, "请选择"); //外出批准人选择器
                
                #endregion

                #region 配件信息
                dtp_parts_buy_time.Value = DateTime.Now;
                txt_parts_buy_corp.ChooserClick += delegate  //配件购买单位(客户选择器)
                {
                    var custChooser = new frmChooseCompany();
                    var result = custChooser.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        txt_parts_buy_corp.Text = custChooser.Sap_Code;
                    }
                };
                CommonCtrl.BindComboBoxByDictionarr(cbo_contain_man_hour_cost, "sys_true_false", false);   //是否包含工时费
                cbo_contain_man_hour_cost.SelectedValue = DbDic2Enum.TRUE;

                txt_parts_code.ChooserClick += delegate  //配件编号(配件选择器)
                {
                    var chooser = new frmParts();
                    var result = chooser.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        txt_parts_code.Text = chooser.PartsCode;
                        txt_materiel_describe.Caption = chooser.PartsName;
                    }
                };
                txt_first_install_station.ChooserClick += delegate  //首次安装服务站(客户选择器)
                {
                    var custChooser = new frmChooseCompany();
                    var result = custChooser.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        txt_first_install_station.Text = custChooser.Sap_Code;
                    }
                };
                CommonCtrl.BindComboBoxByDictionarr(cbo_part_guarantee_period, "parts_warranty_agreement_yt", false);   //协议保养日期
                #endregion

                #region 经办人
                txt_responsible_opid.ChooserClick += delegate   //经办人选择器
                {
                    var chooser = new frmUsers();
                    var result = chooser.ShowDialog();
                    if (result != DialogResult.OK) return;
                    txt_responsible_opid.Text = chooser.User_Name;
                    txt_responsible_opid.Tag = chooser.User_ID;
                    txt_org_name.Caption = chooser.OrgName;
                    txt_org_name.Tag = chooser.OrgId;
                };
                #endregion
            }
            catch (Exception ex)
            {
                //日记记录
            }
        }