/// <summary>
 /// 保存
 /// </summary>
 private void SaveSample()
 {
     if (DataGridRecord.Items.Count > 0)
     {
         bool   check              = true;
         int    result             = 1;
         string err                = string.Empty;
         clsttStandardDecide model = new clsttStandardDecide();
         try
         {
             foreach (clsttStandardDecide item in DataGridRecord.Items.SourceCollection)
             {
                 check = checkValue(item);
                 if (!check)
                 {
                     break;
                 }
             }
             if (check)
             {
                 foreach (clsttStandardDecide item in DataGridRecord.Items.SourceCollection)
                 {
                     model.ID            = item.ID;
                     model.FtypeNmae     = item.FtypeNmae;
                     model.SampleNum     = item.SampleNum;
                     model.Name          = item.Name;
                     model.ItemDes       = item.ItemDes;
                     model.StandardValue = item.StandardValue;
                     model.Demarcate     = item.Demarcate;
                     model.Unit          = item.Unit;
                     _clsttStandardDecideOpr.Insert(model, out err);
                 }
             }
             else
             {
                 MessageBox.Show("信息不完整,请填写完整的国家检测标准信息!", "操作提示");
             }
         }
         catch (Exception exception)
         {
             result = 0;
             MessageBox.Show("操作出错!" + exception.ToString());
         }
         finally
         {
             if (result == 1)
             {
                 MessageBox.Show("保存成功!", "操作提示");
             }
         }
     }
 }
 private void DataGridRecord_PreviewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     //Update();
     try
     {
         if (DataGridRecord.SelectedItems.Count > 0)
         {
             if (!DataGridRecord.SelectedItems[0].ToString().Equals("{NewItemPlaceholder}"))
             {
                 clsttStandardDecide _decide = (clsttStandardDecide)DataGridRecord.SelectedItems[0];
                 AddOrUpdate("update", _decide);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("异常:\n" + ex.Message);
     }
 }
 /// <summary>
 /// 修改样品
 /// </summary>
 private void Update()
 {
     try
     {
         if (DataGridRecord.SelectedItems.Count > 0)
         {
             if (!DataGridRecord.SelectedItems[0].ToString().Equals("{NewItemPlaceholder}"))
             {
                 clsttStandardDecide _decide = (clsttStandardDecide)DataGridRecord.SelectedItems[0];
                 AddOrUpdate("update", _decide);
             }
         }
         else
         {
             MessageBox.Show("未选择任何国家检测标准!", "操作提示");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("异常:\n" + ex.Message);
     }
 }
 /// <summary>
 /// 新增||修改样品
 /// </summary>
 /// <param name="type">add为新增||update为修改</param>
 private void AddOrUpdate(string type, clsttStandardDecide model)
 {
     try
     {
         AddOrUpdateSample addWindow = new AddOrUpdateSample();
         if (type.Equals("add"))
         {
             addWindow.Title = "新增国家检测标准";
         }
         else
         {
             addWindow.Title           = "修改国家检测标准";
             addWindow.btnSave.Content = "修改";
             addWindow._decide         = model;
         }
         addWindow._ItemNames = _ItemNames;
         addWindow.ShowDialog();
         SearchSample();
     }
     catch (Exception ex)
     {
         MessageBox.Show("异常:\n" + ex.Message);
     }
 }
        /// <summary>
        /// 检测完整性
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private bool checkValue(clsttStandardDecide model)
        {
            if (model.FtypeNmae == null)
            {
                return(false);
            }
            else if (model.FtypeNmae.Trim().Equals(string.Empty))
            {
                return(false);
            }

            if (model.SampleNum == null)
            {
                return(false);
            }
            else if (model.SampleNum.Trim().Equals(string.Empty))
            {
                return(false);
            }

            if (model.Name == null)
            {
                return(false);
            }
            else if (model.Name.Trim().Equals(string.Empty))
            {
                return(false);
            }

            if (model.ItemDes == null)
            {
                return(false);
            }
            else if (model.ItemDes.Trim().Equals(string.Empty))
            {
                return(false);
            }

            if (model.StandardValue == null)
            {
                return(false);
            }
            else if (model.StandardValue.Trim().Equals(string.Empty))
            {
                return(false);
            }

            if (model.Demarcate == null)
            {
                return(false);
            }
            else if (model.Demarcate.Trim().Equals(string.Empty))
            {
                return(false);
            }

            if (model.Unit == null)
            {
                return(false);
            }
            else if (model.Unit.Trim().Equals(string.Empty))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// 保存样品
        /// </summary>
        private void Save()
        {
            clsttStandardDecide model = new clsttStandardDecide();
            string err     = string.Empty;
            bool   request = true;

            if (CheckSave())
            {
                try
                {
                    if (_decide != null && _decide.ID > 0)
                    {
                        btnSave.Content = "修改";
                        model.ID        = _decide.ID;
                    }
                    model.FtypeNmae     = textBoxFtypeNmae.Text;
                    model.SampleNum     = DateTime.Now.Millisecond.ToString();
                    model.Name          = textBoxName.Text;
                    model.ItemDes       = textBoxItemDes.Text;
                    model.StandardValue = textBoxStandardValue.Text;
                    model.Demarcate     = textBoxDemarcate.Text;
                    model.Unit          = textBoxUnit.Text;
                    err = string.Empty;
                    _bll.Insert(model, out err);
                }
                catch (Exception exception)
                {
                    request = false;
                    MessageBox.Show("保存失败!\n出现异常:" + exception.ToString());
                }
                finally
                {
                    if (request && btnSave.Content.Equals("保存") && _sampleName.Length == 0)
                    {
                        SettingValues();
                        if (MessageBox.Show("保存成功!\n是否继续添加国家检测标准?", "操作提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                        {
                            textBoxFtypeNmae.Text     = string.Empty;
                            textBoxSampleNum.Text     = string.Empty;
                            textBoxName.Text          = _projectName.Equals(string.Empty) ? string.Empty : _projectName;
                            textBoxItemDes.Text       = string.Empty;
                            textBoxStandardValue.Text = string.Empty;
                            textBoxDemarcate.Text     = string.Empty;
                            textBoxUnit.Text          = string.Empty;
                            btnSave.Content           = "保存";
                            this.Title = "新增国家检测标准";
                            _decide    = new clsttStandardDecide();
                            _isUpdate  = false;
                            _isClose   = false;
                        }
                        else
                        {
                            _isUpdate = false;
                            _isClose  = true;
                            try { this.Close(); }
                            catch (Exception) { }
                        }
                    }
                    else
                    {
                        MessageBox.Show("保存成功!", "操作提示");
                        SettingValues();
                        _isClose = true;
                        try { this.Close(); }
                        catch (Exception) { }
                    }
                }
            }
            else
            {
                _isClose = false;
            }
        }