private void _create_Click(object sender, RoutedEventArgs e)
        {
            if (_card_id.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入检疫证号!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            bool exit_flag = dbOperation.GetDbHelper().Exists(string.Format("SELECT count(cardid) from t_certificate where cardid ='{0}'", _card_id.Text));
            if (exit_flag)
            {
                Toolkit.MessageBox.Show("检疫证号已存在,请重新输入!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_help_user.SelectedIndex < 1)
            {
                Toolkit.MessageBox.Show("请选择协检员!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_shipper_id.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入货主代码!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_object_id.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请选择动物种类!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_object_count.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入数量!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_for_use.SelectedIndex < 1)
            {
                Toolkit.MessageBox.Show("请选择用途!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_city_ks.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入启运地点:市(州)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (_region_ks.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入启运地点:县(市、区)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            //if (_town_ks.Text.Trim().Length == 0)
            //{
            //    Toolkit.MessageBox.Show("请输入启运地点:乡(镇)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
            //    return;
            //}
            if (_village_ks.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入启运地点:村(养殖场、交易市场)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (_city_js.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入到达地点:市(州)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            //if (_region_js.Text.Trim().Length == 0)
            //{
            //    Toolkit.MessageBox.Show("请输入到达地点:县(市、区)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
            //    return;
            //}
            //if (_town_js.Text.Trim().Length == 0)
            //{
            //    Toolkit.MessageBox.Show("请输入到达地点:乡(镇)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
            //    return;
            //}
            if (_village_js.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入到达地点:村(养殖场、交易市场)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            string sql = string.Format("INSERT INTO t_certificate(cardid,companyid,companyname,objectid,objectname,objectcount," +
                                        "phone,foruseid,foruse,cityks,regionks,townks,villageks,cityjs,regionjs,townjs," +
                                        "villagejs,objectlable,createdeptid,createuserid,createdate,createloginid,helpuserid)" +
                                        " values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}'," +
                                        "'{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}')"
                            , _card_id.Text, _shipper_id.Text, _shipper.Text,
                            (_object_id.SelectedItem as Label).Tag.ToString(), _object_id.Text, _object_count.Text + _object_type.Text,
                            _phone.Text, (_for_use.SelectedItem as Label).Tag.ToString(), _for_use.Text, _city_ks.Text,
                             _region_ks.Text, _town_ks.Text, _village_ks.Text, _city_js.Text, _region_js.Text,
                            _town_js.Text, _village_js.Text, _object_lable.Text, deptId, userId,
                            System.DateTime.Now, loginid,(_help_user.SelectedItem as Label).Tag.ToString());

            int i = dbOperation.GetDbHelper().ExecuteSql(sql);
            if (i >= 0)
            {
                List<string> cer_details = new List<string>() {_card_id.Text,_shipper.Text,_object_id.Text, _object_count.Text,_object_type.Text, _phone.Text,
                            _for_use.Text, _city_ks.Text, _region_ks.Text, _town_ks.Text, _village_ks.Text, _city_js.Text, _region_js.Text,
                            _town_js.Text, _village_js.Text, _object_lable.Text,username,loginid,
                            System.DateTime.Now.Year.ToString(),System.DateTime.Now.Month.ToString(),System.DateTime.Now.Day.ToString() };

                UcCertificateDetails cer = new UcCertificateDetails(cer_details);
                //grid_info.Children.Add(cer);
                PrintDialog dialog = new PrintDialog();
                //if (dialog.ShowDialog() == true)
                //{
                    dialog.PrintQueue = GetPrinter();
                    Size printSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
                    cer.Measure(printSize);
                    cer.Arrange(new Rect(0, 0, dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
                    //Size printSize = new Size(793, 529);
                    //cer.Measure(printSize);
                    //cer.Arrange(new Rect(0, 0, 793, 529));

                    dialog.PrintVisual(cer, "动物检疫证");
                //}

                //Toolkit.MessageBox.Show("电子出证单生成成功!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                clear();
                return;
            }
            else
            {
                Toolkit.MessageBox.Show("电子出证单生成失败!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
        }
        private void _create_Click(object sender, RoutedEventArgs e)
        {
            if (_card_id.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入检疫证号!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            bool exit_flag = dbOperation.GetDbHelper().Exists(string.Format("SELECT count(cardid) from t_certificate where cardid ='{0}'", _card_id.Text));

            if (exit_flag)
            {
                Toolkit.MessageBox.Show("检疫证号已存在,请重新输入!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_help_user.SelectedIndex < 1)
            {
                Toolkit.MessageBox.Show("请选择协检员!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_shipper_id.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入货主代码!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_object_id.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请选择动物种类!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_object_count.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入数量!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_for_use.SelectedIndex < 1)
            {
                Toolkit.MessageBox.Show("请选择用途!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (_city_ks.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入启运地点:市(州)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (_region_ks.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入启运地点:县(市、区)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            //if (_town_ks.Text.Trim().Length == 0)
            //{
            //    Toolkit.MessageBox.Show("请输入启运地点:乡(镇)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
            //    return;
            //}
            if (_village_ks.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入启运地点:村(养殖场、交易市场)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (_city_js.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入到达地点:市(州)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            //if (_region_js.Text.Trim().Length == 0)
            //{
            //    Toolkit.MessageBox.Show("请输入到达地点:县(市、区)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
            //    return;
            //}
            //if (_town_js.Text.Trim().Length == 0)
            //{
            //    Toolkit.MessageBox.Show("请输入到达地点:乡(镇)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
            //    return;
            //}
            if (_village_js.Text.Trim().Length == 0)
            {
                Toolkit.MessageBox.Show("请输入到达地点:村(养殖场、交易市场)!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            string sql = string.Format("INSERT INTO t_certificate(cardid,companyid,companyname,objectid,objectname,objectcount," +
                                       "phone,foruseid,foruse,cityks,regionks,townks,villageks,cityjs,regionjs,townjs," +
                                       "villagejs,objectlable,createdeptid,createuserid,createdate,createloginid,helpuserid)" +
                                       " values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}'," +
                                       "'{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}')"
                                       , _card_id.Text, _shipper_id.Text, _shipper.Text,
                                       (_object_id.SelectedItem as Label).Tag.ToString(), _object_id.Text, _object_count.Text + _object_type.Text,
                                       _phone.Text, (_for_use.SelectedItem as Label).Tag.ToString(), _for_use.Text, _city_ks.Text,
                                       _region_ks.Text, _town_ks.Text, _village_ks.Text, _city_js.Text, _region_js.Text,
                                       _town_js.Text, _village_js.Text, _object_lable.Text, deptId, userId,
                                       System.DateTime.Now, loginid, (_help_user.SelectedItem as Label).Tag.ToString());

            int i = dbOperation.GetDbHelper().ExecuteSql(sql);

            if (i >= 0)
            {
                List <string> cer_details = new List <string>()
                {
                    _card_id.Text, _shipper.Text, _object_id.Text, _object_count.Text, _object_type.Text, _phone.Text,
                    _for_use.Text, _city_ks.Text, _region_ks.Text, _town_ks.Text, _village_ks.Text, _city_js.Text, _region_js.Text,
                    _town_js.Text, _village_js.Text, _object_lable.Text, username, loginid,
                    System.DateTime.Now.Year.ToString(), System.DateTime.Now.Month.ToString(), System.DateTime.Now.Day.ToString()
                };

                UcCertificateDetails cer = new UcCertificateDetails(cer_details);
                //grid_info.Children.Add(cer);
                PrintDialog dialog = new PrintDialog();
                //if (dialog.ShowDialog() == true)
                //{
                dialog.PrintQueue = GetPrinter();
                Size printSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
                cer.Measure(printSize);
                cer.Arrange(new Rect(0, 0, dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
                //Size printSize = new Size(793, 529);
                //cer.Measure(printSize);
                //cer.Arrange(new Rect(0, 0, 793, 529));

                dialog.PrintVisual(cer, "动物检疫证");
                //}

                //Toolkit.MessageBox.Show("电子出证单生成成功!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                clear();
                return;
            }
            else
            {
                Toolkit.MessageBox.Show("电子出证单生成失败!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
        }