/**根据传入的原料单位对象获取原料单位对象*/
        public RawUnit CreateRawUnitBean(BaseMaterialBean bean)
        {
            RawUnit beanBack = new RawUnit();

            beanBack.UnitId         = bean.Id;
            beanBack.Name           = bean.Name;
            beanBack.CreateDatetime = bean.CreateDatetime;
            beanBack.CreateBy       = bean.CreateBy;
            beanBack.Deleted        = bean.Deleted;
            beanBack.Status         = bean.Status;
            beanBack.UpdateDatetime = bean.UpdateDatetime;
            beanBack.UpdateBy       = bean.UpdateBy;
            return(beanBack);
        }
        public Raw CreateRaw(BaseMaterialBean bean)
        {
            Raw beanBack = new Raw();

            beanBack.RawId          = bean.Id;
            beanBack.Name           = bean.Name;
            beanBack.ParentRawId    = bean.ParentRawId;
            beanBack.CreateDatetime = bean.CreateDatetime;
            beanBack.CreateBy       = bean.CreateBy;
            beanBack.Deleted        = bean.Deleted;
            beanBack.Status         = bean.Status;
            beanBack.UpdateDatetime = bean.UpdateDatetime;
            beanBack.UpdateBy       = bean.UpdateBy;
            return(beanBack);
        }
 public Raw CreateRaw(BaseMaterialBean bean)
 {
     Raw beanBack= new Raw();
     beanBack.RawId = bean.Id;
     beanBack.Name=bean.Name;
     beanBack.ParentRawId=bean.ParentRawId;
     beanBack.CreateDatetime=bean.CreateDatetime;
     beanBack.CreateBy=bean.CreateBy;
     beanBack.Deleted=bean.Deleted;
     beanBack.Status=bean.Status;
     beanBack.UpdateDatetime=bean.UpdateDatetime;
     beanBack.UpdateBy=bean.UpdateBy;
     return beanBack;
 }
        /**根据传入的原料单位对象获取原料单位对象*/
        public RawUnit CreateRawUnitBean(BaseMaterialBean bean)
        {

            RawUnit beanBack = new RawUnit();
            beanBack.UnitId = bean.Id;
            beanBack.Name = bean.Name;
            beanBack.CreateDatetime = bean.CreateDatetime;
            beanBack.CreateBy = bean.CreateBy;
            beanBack.Deleted = bean.Deleted;
            beanBack.Status = bean.Status;
            beanBack.UpdateDatetime = bean.UpdateDatetime;
            beanBack.UpdateBy = bean.UpdateBy;
            return beanBack;
        }
 //加载原料单位
 private void LoadRawUnit()
 {
     new Task(() =>
     {
         List<RawUnit> units = _RawUnitDataService.FindRawUnitByDeletedStatus();
         DispatcherHelper.CheckBeginInvokeOnUI(() =>
         {
             if (units != null)
             {
                 BaseRawMaterialItems.Clear();
                 foreach (var unit in units)
                 {
                     _BaseMaterialBean = new BaseMaterialBean();
                     _BaseMaterialBean.CreateBaseMaterialBean(unit);
                     _BaseMaterialBean.Code = (BaseRawMaterialItems.Count + 1).ToString();
                     BaseRawMaterialItems.Add(BaseMaterialBean);
                 }
             }
         });
     }).Start();
 }
        //加载大类
        private void LoadBigRaw()
        {
            new Task(() =>
            {
                List<Raw> raws = _MaterialDataService.FindAllBigRawByDeletedStatus();
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    if (raws != null)
                    {
                       
                        BaseRawMaterialItems.Clear();
                        foreach (var raw in raws)
                        {
                            _BaseMaterialBean = new BaseMaterialBean();
                            _BaseMaterialBean.CreateBaseMaterialBean(raw);
                            _BaseMaterialBean.Code = (BaseRawMaterialItems.Count + 1).ToString();
                            BaseRawMaterialItems.Add(BaseMaterialBean);
                        }
                    }
                });
            }).Start();

        }
 //type=0表示新增原料资料,type=1表示新增大类,type=2表示新增小类,type=3表示新增单位
 private void AddData(int type)
 {
     switch (type)
     {
         case 1:   //新增大类
             
             _BaseMaterialBean = new BaseMaterialBean();
             _BaseMaterialBean.Name = "";
             _RawMaterialBean.CreateBy = SubjectUtils.GetAuthenticationId();
             _RawMaterialBean.CreateDatetime = DateTime.Now;
             _BaseMaterialBean.Code = (BaseRawMaterialItems.Count + 1).ToString();
             BaseRawMaterialItems.Add(BaseMaterialBean);
             break;
         case 2:  //小类
             if (SelectedLittleRawNode != null)
             {
                 _LittleRawMaterialBean = new LittleRawMaterialBean();
                 _LittleRawMaterialBean.Name = "";
                 _LittleRawMaterialBean.Code = (LittleMaterialItems.Count + 1).ToString();
                 _LittleRawMaterialBean.ParentRawId = int.Parse(SelectedLittleRawNode.Id);
                 _LittleRawMaterialBean.ParentRaw = SelectedLittleRawNode.Text;
                 _LittleRawMaterialBean.CreateBy = SubjectUtils.GetAuthenticationId();
                 _LittleRawMaterialBean.CreateDatetime = DateTime.Now;
                 LittleMaterialItems.Add(LittleRawMaterialBean);
             }
             break;
         case 3:  //单位
             _BaseMaterialBean = new BaseMaterialBean();
             _BaseMaterialBean.Name = "";
             _BaseMaterialBean.Code = (BaseRawMaterialItems.Count + 1).ToString();
             _RawMaterialBean.CreateBy = SubjectUtils.GetAuthenticationId();
             _RawMaterialBean.CreateDatetime = DateTime.Now;
             BaseRawMaterialItems.Add(BaseMaterialBean);
             break;
         default:  //原料资料
             //把界面上的一下东东隐藏和显示
             if (SelectedRawNode == null || SelectedRawNode.Parent.Equals(RootTreeNode))
             {
                 MessageBox.Show("请选择原料小类");
                 return;
             }
             else
             {
                 //是小类,弹出新增原料页面
                 AddRawMaterialBaseData();
                 RawMaterialXaml = new RawMaterialView();
                 RawMaterialXaml.RecordControll.Visibility = Visibility.Hidden;
                 RawMaterialXaml.Continue.Visibility = Visibility.Visible;
                 RawMaterialXaml.ShowDialog();
             }
             break;
     }
 }