//读取产品数据
 private void dbGetProduct(string cmdSelect)
 {
     if (string.IsNullOrEmpty(cmdSelect))
     {
         return;
     }
     try
     {
         listProduct.Clear();//清空缓存数据
         DataTable dtProduct = DatabaseUtils.GetDataTable(cmdSelect);
         if (dtProduct != null && dtProduct.Rows.Count > 0)
         {
             foreach (DataRow item in dtProduct.Rows)
             {
                 ProductBindEntity prodEnt = new ProductBindEntity();
                 prodEnt.Id            = Convert.ToInt64(item["Id"]);
                 prodEnt.PrdctNumber   = Convert.ToString(item["PrdctNumber"]);
                 prodEnt.PrdctName     = Convert.ToString(item["PrdctName"]);
                 prodEnt.Industry      = Convert.ToString(item["Industry"]);
                 prodEnt.TreatType     = Convert.ToString(item["TreatType"]);  //处理类型
                 prodEnt.WeDuration    = Convert.ToString(item["WeDuration"]); //白锈时长
                 prodEnt.ReDuration    = Convert.ToString(item["ReDuration"]);
                 prodEnt.Remark        = Convert.ToString(item["Remark"]);
                 prodEnt.UpdatableFlag = true;//允许更改编辑类型
                 listProduct.Add(prodEnt);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error(MethodBase.GetCurrentMethod(), "选择产品筛选异常:" + ex.Message);
     }
 }
        //读取产品数据
        private void dbGetProduct()
        {
            try
            {
                string    sql       = "select Id,PrdctNumber,PrdctName,Industry,TreatType,WeDuration,ReDuration,Remark from ProductData";
                DataTable dtProduct = DatabaseUtils.GetDataTable(sql);
                if (dtProduct != null && dtProduct.Rows.Count > 0)
                {
                    listProduct.Clear();

                    foreach (DataRow item in dtProduct.Rows)
                    {
                        ProductBindEntity prodEnt = new ProductBindEntity();
                        prodEnt.Id            = Convert.ToInt64(item["Id"]);
                        prodEnt.PrdctNumber   = Convert.ToString(item["PrdctNumber"]);
                        prodEnt.PrdctName     = Convert.ToString(item["PrdctName"]);
                        prodEnt.Industry      = Convert.ToString(item["Industry"]);
                        prodEnt.TreatType     = Convert.ToString(item["TreatType"]);  //处理类型
                        prodEnt.WeDuration    = Convert.ToString(item["WeDuration"]); //白锈时长
                        prodEnt.ReDuration    = Convert.ToString(item["ReDuration"]);
                        prodEnt.Remark        = Convert.ToString(item["Remark"]);
                        prodEnt.UpdatableFlag = true;//允许更改编辑类型
                        listProduct.Add(prodEnt);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(MethodBase.GetCurrentMethod(), "保存产品数据异常:" + ex.Message);
            }
        }
 private void btnOk_Click(object sender, RoutedEventArgs e)
 {
     if (this.dgProductData.SelectedItem == null)
     {
         MessageBox.Show("没有选中的项", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
         return;
     }
     this.prdctSelect  = this.dgProductData.SelectedItem as ProductBindEntity;
     this.DialogResult = true;
 }
        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            ProductBindEntity item = new ProductBindEntity();

            item.SerNumber     = ocProduct.Count > 0 ? ocProduct.Max(x => x.SerNumber) + 1 : 1;
            item.UpdatableFlag = true;        //允许更改编辑类型
            item.SetEditState(EditState.New); //设置编辑状态为新增
            this.listProduct.Add(item);       //更新缓存数据
            this.ocProduct.Add(item);         //更新绑定数据源
            //选中新增的行,并滚动到该行
            this.dgProductData.SelectedItem = item;
            this.dgProductData.ScrollIntoView(item);
        }
        //删除选择的项
        private void deleteProductSel()
        {
            if (this.dgProductData.SelectedItem == null)
            {
                MessageBox.Show("请选择要删除的项", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            ProductBindEntity item = this.dgProductData.SelectedItem as ProductBindEntity;

            if (item.EditState == EditState.New)//新增的直接移除
            {
                this.listProduct.Remove(item);
            }
            else
            {
                //更改编辑类型为Deleted
                item.SetEditState(EditState.Deleted);
            }
            this.ocProduct.Remove(item); //从数据源移除
            this.updOcProductBindSn();   //更新行号
        }