/// <summary>
        /// 根据物品编码加入 入库申请数据{3F8F98B1-44E9-4828-90C4-0931F6DA7B87}
        /// </summary>
        /// <param name="drugNO">物品编码</param>
        /// <param name="outBillNO">出库序号</param>
        /// <returns></returns>
        private int AddDrugData(string drugNO, string outBillNO, decimal applyPrice)
        {
            Neusoft.HISFC.Models.Material.MaterialItem item = itemManager.GetMetItemByMetID(drugNO);

            if (item == null)
            {
                System.Windows.Forms.MessageBox.Show("检索物品基本信息失败");
                return(-1);
            }

            Neusoft.HISFC.Models.Material.Apply apply = new Neusoft.HISFC.Models.Material.Apply();

            apply.Item = item;

            if (this.hsApplyData.Contains(apply.Item.ID))
            {
                System.Windows.Forms.MessageBox.Show("该物品已添加");
                return(0);
            }

            if (outBillNO != null)
            {
                apply.ApplyListNO = outBillNO;
            }

            apply.StockDept  = this.MatApplyManager.DeptInfo;    //库存科室 (目标科室)
            apply.TargetDept = this.MatApplyManager.TargetDept;  //申请科室
            apply.State      = "0";                              //状态 申请
            apply.SystemType = this.MatApplyManager.PrivType.Memo;
            apply.PrivType   = this.MatApplyManager.PrivType.ID;
            //内部入库申请的申请价格应该是零售价 而不是物资目录中的单价 by yuyun {3F8F98B1-44E9-4828-90C4-0931F6DA7B87}
            apply.ApplyPrice = applyPrice;

            if (this.AddDataToTable(apply, "1") == 1)
            {
                this.hsApplyData.Add(apply.Item.ID, apply);

                //				this.SetFormat();

                this.SetFocusSelect();
            }

            return(1);
        }
        /// <summary>
        /// 根据物品编码加入 入库申请数据 --退库申请用
        /// </summary>
        /// <param name="itemCode">物品编码</param>
        /// <param name="outNo">出库流水号</param>
        /// <param name="storeNo">库存序号</param>
        /// <returns></returns>
        private int AddDrugData(string itemCode, string outNo, string storeNo)
        {
            Neusoft.HISFC.Models.Material.MaterialItem item = itemManager.GetMetItemByMetID(itemCode);

            if (item == null)
            {
                System.Windows.Forms.MessageBox.Show("检索物品基本信息失败");
                return(-1);
            }

            Neusoft.HISFC.Models.Material.Apply apply = new Neusoft.HISFC.Models.Material.Apply();

            apply.Item = item;

            if (this.hsApplyData.Contains(apply.Item.ID))
            {
                System.Windows.Forms.MessageBox.Show("该物品已添加");
                return(0);
            }
            apply.OutNo   = outNo;
            apply.StockNO = storeNo;
            //获取对应批号库存信息中的零售价{3F8F98B1-44E9-4828-90C4-0931F6DA7B87}
            List <Neusoft.HISFC.Models.Material.StoreDetail> listStoreBase = this.storeManager.QueryStoreListAll(this.MatApplyManager.TargetDept.ID, itemCode, storeNo, true);

            apply.ApplyPrice = listStoreBase[0].StoreBase.PriceCollection.RetailPrice;
            //----------------------
            apply.StockDept  = this.MatApplyManager.DeptInfo;    //库存科室 (目标科室)
            apply.TargetDept = this.MatApplyManager.TargetDept;  //申请科室
            apply.State      = "0";                              //状态 申请
            apply.SystemType = this.MatApplyManager.PrivType.Memo;
            apply.PrivType   = this.MatApplyManager.PrivType.ID;

            if (this.AddDataToTable(apply, "1") == 1)
            {
                this.hsApplyData.Add(apply.Item.ID, apply);

                //				this.SetFormat();

                this.SetFocusSelect();
            }

            return(1);
        }
        /// <summary>
        /// 根据物品编码加入 入库申请数据 --退库申请用
        /// </summary>
        /// <param name="itemCode">物品编码</param>
        /// <param name="outNo">出库流水号</param>
        /// <param name="storeNo">库存序号</param>
        /// <returns></returns>
        private int AddDrugData(string itemCode, string outNo, string storeNo)
        {
            Neusoft.HISFC.Models.Material.MaterialItem item = itemManager.GetMetItemByMetID(itemCode);

            if (item == null)
            {
                System.Windows.Forms.MessageBox.Show("检索物品基本信息失败");
                return(-1);
            }

            Neusoft.HISFC.Models.Material.Apply apply = new Neusoft.HISFC.Models.Material.Apply();

            apply.Item = item;

            if (this.hsApplyData.Contains(apply.Item.ID))
            {
                System.Windows.Forms.MessageBox.Show("该物品已添加");
                return(0);
            }
            apply.OutNo   = outNo;
            apply.StockNO = storeNo;

            apply.StockDept  = this.MatApplyManager.DeptInfo;    //库存科室 (目标科室)
            apply.TargetDept = this.MatApplyManager.TargetDept;  //申请科室
            apply.State      = "0";                              //状态 申请
            apply.SystemType = this.MatApplyManager.PrivType.Memo;
            apply.PrivType   = this.MatApplyManager.PrivType.ID;

            if (this.AddDataToTable(apply, "1") == 1)
            {
                this.hsApplyData.Add(apply.Item.ID, apply);

                //				this.SetFormat();

                this.SetFocusSelect();
            }

            return(1);
        }
        /// <summary>
        /// 根据物品编码加入 出库申请数据
        /// </summary>
        /// <param name="apply">物品实体</param>
        /// <returns></returns>
        private int AddDrugData(Neusoft.HISFC.Models.Material.Apply apply)
        {
            if (this.hsApplyData.Contains(apply.Item.ID))
            {
                System.Windows.Forms.MessageBox.Show("该物品已添加");
                return(0);
            }

            apply.StockDept  = this.MatApplyManager.DeptInfo;        //库存科室 (目标科室)
            apply.TargetDept = this.MatApplyManager.TargetDept;      //目标科室
            apply.State      = "0";                                  //状态 申请
            apply.SystemType = this.MatApplyManager.PrivType.Memo;
            apply.PrivType   = this.MatApplyManager.PrivType.ID;

            if (this.AddDataToTable(apply, "1") == 1)
            {
                this.hsApplyData.Add(apply.Item.ID, apply);
                this.SetFocusSelect();
            }

            return(1);
        }
        public void Save()
        {
            if (!this.Valid())
            {
                return;
            }

            this.dt.DefaultView.RowFilter = "1=1";
            for (int i = 0; i < this.dt.DefaultView.Count; i++)
            {
                this.dt.DefaultView[i].EndEdit();
            }

            FarPoint.Win.Spread.CellType.NumberCellType numberCellType = new FarPoint.Win.Spread.CellType.NumberCellType();
            numberCellType.DecimalPlaces = 4;
            this.MatApplyManager.FpSheetView.Columns[(int)ColumnSet.ColRetailPrice].CellType = numberCellType;
            this.MatApplyManager.FpSheetView.Columns[(int)ColumnSet.ColApplyCost].CellType   = numberCellType;

            DataTable dtAddMofity = this.dt.GetChanges(DataRowState.Added | DataRowState.Modified);

            if (dtAddMofity == null || dtAddMofity.Rows.Count <= 0)
            {
                return;
            }

            //定义事务

            Neusoft.FrameWork.Management.PublicTrans.BeginTransaction();

            //Neusoft.FrameWork.Management.Transaction t = new Transaction(Neusoft.FrameWork.Management.Connection.Instance);
            //t.BeginTransaction();

            this.storeManager.SetTrans(Neusoft.FrameWork.Management.PublicTrans.Trans);

            //获取系统时间
            DateTime sysTime = this.storeManager.GetDateTimeFromSysDateTime();

            if (this.listNO == "")
            {
                //获取新申请单号
                this.listNO = this.storeManager.GetApplyNO(this.MatApplyManager.DeptInfo.ID);
            }

            foreach (DataRow dr in dtAddMofity.Rows)
            {
                string key = dr["物品编码"].ToString();

                Neusoft.HISFC.Models.Material.Apply apply = this.hsApplyData[key] as Neusoft.HISFC.Models.Material.Apply;

                apply.Operation.ApplyOper.OperTime   = sysTime;
                apply.Operation.Oper.OperTime        = sysTime;
                apply.Operation.ApproveOper.OperTime = sysTime;
                apply.Operation.ApplyOper.ID         = this.MatApplyManager.OperInfo.ID;
                apply.Operation.Oper.ID = this.MatApplyManager.OperInfo.ID;
                apply.TargetDept.ID     = this.MatApplyManager.TargetDept.ID;

                apply.Operation.ApplyQty = NConvert.ToDecimal(dr["申请数量"].ToString());
                apply.ApplyPrice         = NConvert.ToDecimal(dr["单价"].ToString());
                apply.ApplyCost          = NConvert.ToDecimal(dr["申请金额"].ToString());

                apply.Class2Type = this.MatApplyManager.Class2Priv.ID;
                apply.PrivType   = this.MatApplyManager.PrivType.ID;
                apply.SystemType = this.MatApplyManager.PrivType.Memo;
                apply.Extend1    = "0";
                apply.Extend3    = "1";

                apply.Memo = dr["备注"].ToString();

                if (apply.ID == "")
                {
                    apply.ApplyListNO = this.listNO;              //申请单据号

                    serialNO++;

                    apply.SerialNO = serialNO;

                    if (this.storeManager.InsertApply(apply) == -1)
                    {
                        Neusoft.FrameWork.Management.PublicTrans.RollBack();
                        MessageBox.Show(this.storeManager.Err);
                        return;
                    }
                }
                else
                {
                    int parm = this.storeManager.UpdateApply(apply);
                    if (parm == -1)
                    {
                        Neusoft.FrameWork.Management.PublicTrans.RollBack();
                        System.Windows.Forms.MessageBox.Show("对申请数量进行更新失败" + this.storeManager.Err);
                        return;
                    }
                    if (parm == 0)
                    {
                        Neusoft.FrameWork.Management.PublicTrans.RollBack();
                        System.Windows.Forms.MessageBox.Show("该申请单已被审核!无法进行修改!请刷新重试");
                        return;
                    }
                }
            }

            Neusoft.FrameWork.Management.PublicTrans.Commit();

            System.Windows.Forms.MessageBox.Show("保存申请成功");

            this.Clear();
            this.MatApplyManager.FpSheetView.Columns[(int)ColumnSet.ColRetailPrice].CellType = numberCellType;
            this.MatApplyManager.FpSheetView.Columns[(int)ColumnSet.ColApplyCost].CellType   = numberCellType;
        }
        /// <summary>
        /// 根据申请单信息向DataTable内增加数据
        /// </summary>
        /// <param name="apply">申请信息</param>
        /// <param name="dataSource">数据来源 0 原始数据 1 本次添加</param>
        /// <returns></returns>
        protected virtual int AddApplyToTable(Neusoft.HISFC.Models.Material.Apply apply, string dataSource)
        {
            if (this.dt == null)
            {
                this.InitDataTable();
            }

            try
            {
                Neusoft.HISFC.BizLogic.Material.MetItem managerItem = new Neusoft.HISFC.BizLogic.Material.MetItem();
                apply.Item = managerItem.GetMetItemByMetID(apply.Item.ID);

                decimal price = 0;
                decimal qty   = 0;
                decimal cost  = 0;
                string  unit  = "";

                if (this.isMinUnit)
                {
                    qty   = apply.Operation.ApplyQty;
                    cost  = apply.Operation.ApplyQty * apply.Item.UnitPrice;
                    unit  = apply.Item.MinUnit;
                    price = apply.Item.UnitPrice;
                }
                else
                {
                    qty   = apply.Operation.ApplyQty / apply.Item.PackQty;
                    cost  = apply.Operation.ApplyQty / apply.Item.PackQty * apply.Item.PackPrice;
                    unit  = apply.Item.PackUnit;
                    price = apply.Item.PackPrice;
                }
                this.dt.Rows.Add(new object[] {
                    apply.Item.Name,                                                                                                             //商品名称
                    apply.Item.Specs,                                                                                                            //规格
                    price,                                                                                                                       //零售价
                    unit,                                                                                                                        //包装单位
                    qty,                                                                                                                         //申请数量
                    cost,                                                                                                                        //申请金额
                    apply.Memo,                                                                                                                  //备注
                    apply.Item.ID,                                                                                                               //物品编码
                    apply.SerialNO,                                                                                                              //序号
                    dataSource,
                    apply.Item.SpellCode,                                                                                                        //拼音码
                    apply.Item.WBCode,                                                                                                           //五笔码
                    apply.Item.UserCode                                                                                                          //自定义码
                }
                                 );

                this.dt.DefaultView.AllowDelete = true;
                this.dt.DefaultView.AllowEdit   = true;
                this.dt.DefaultView.AllowNew    = true;
            }
            catch (System.Data.DataException e)
            {
                System.Windows.Forms.MessageBox.Show("DataTable内赋值发生错误" + e.Message);

                return(-1);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("DataTable内赋值发生错误" + ex.Message);

                return(-1);
            }

            return(1);
        }
        public int Cancel()
        {
            DialogResult r;

            r = MessageBox.Show("确定要作废该申请吗?操作不可撤销!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
            if (r == DialogResult.No)
            {
                return(1);
            }

            this.dt.DefaultView.RowFilter = "1=1";
            for (int i = 0; i < this.dt.DefaultView.Count; i++)
            {
                this.dt.DefaultView[i].EndEdit();
            }

            if (this.listNO == "")
            {
                MessageBox.Show("该申请单尚未生效!");
                return(0);
            }

            System.Collections.Hashtable hsHave = new Hashtable();

            foreach (DataRow dr in dt.Rows)
            {
                string key = dr["物品编码"].ToString();

                Neusoft.HISFC.Models.Material.Apply apply = this.hsApplyData[key] as Neusoft.HISFC.Models.Material.Apply;

                if (!hsHave.ContainsKey(listNO))
                {
                    //定义事务

                    Neusoft.FrameWork.Management.PublicTrans.BeginTransaction();

                    //Neusoft.FrameWork.Management.Transaction t = new Transaction(Neusoft.FrameWork.Management.Connection.Instance);
                    //t.BeginTransaction();

                    this.storeManager.SetTrans(Neusoft.FrameWork.Management.PublicTrans.Trans);
                    this.myControler.SetTrans(Neusoft.FrameWork.Management.PublicTrans.Trans);


                    //获取系统时间
                    DateTime sysTime = this.storeManager.GetDateTimeFromSysDateTime();

                    hsHave.Add(listNO, apply);

                    int parm = -1;

                    parm = this.storeManager.UpdateApplyCheck(apply.StockDept.ID, apply.ApplyListNO, apply.SerialNO, "U", apply.Operation.Oper.ID, apply.Operation.Oper.OperTime);

                    if (parm == -1)
                    {
                        Neusoft.FrameWork.Management.PublicTrans.RollBack();
                        System.Windows.Forms.MessageBox.Show("作废申请失败!" + this.storeManager.Err);
                        return(-1);
                    }
                    if (parm == 0)
                    {
                        Neusoft.FrameWork.Management.PublicTrans.RollBack();
                        System.Windows.Forms.MessageBox.Show("该申请单状态已近发生改变!");
                        return(-1);
                    }

                    Neusoft.FrameWork.Management.PublicTrans.Commit();

                    System.Windows.Forms.MessageBox.Show("申请单作废成功");
                }
                else
                {
                    continue;
                }
            }

            this.Clear();

            return(1);
        }
        /// <summary>
        /// 向DataTable内增加数据
        /// </summary>
        /// <param name="apply">申请信息</param>
        /// <param name="dataSource">数据来源 0 原始数据 1 本次添加</param>
        /// <returns></returns>
        protected virtual int AddDataToTable(Neusoft.HISFC.Models.Material.Apply apply, string dataSource)
        {
            if (this.dt == null)
            {
                this.InitDataTable();
            }

            try
            {
                decimal price = 0;
                decimal qty   = 0;
                decimal cost  = 0;
                string  unit  = "";

                if (this.isMinUnit)
                {
                    qty = apply.Operation.ApplyQty;
                    //内部入库申请的申请价格应该是零售价 而不是物资目录中的单价 by yuyun {3F8F98B1-44E9-4828-90C4-0931F6DA7B87}
                    //cost = apply.Operation.ApplyQty * apply.Item.UnitPrice;
                    cost = apply.Operation.ApplyQty * apply.ApplyPrice;
                    unit = apply.Item.MinUnit;
                    //price = apply.Item.UnitPrice;
                    price = apply.ApplyPrice;
                }
                else
                {
                    qty = apply.Operation.ApplyQty / apply.Item.PackQty;
                    //内部入库申请的申请价格应该是零售价 而不是物资目录中的单价 by yuyun {3F8F98B1-44E9-4828-90C4-0931F6DA7B87}
                    //cost = apply.Operation.ApplyQty / apply.Item.PackQty * apply.Item.PackPrice;
                    cost = apply.Operation.ApplyQty / apply.Item.PackQty * apply.ApplyPrice;
                    unit = apply.Item.PackUnit;
                    //price = apply.Item.PackPrice;
                    price = apply.ApplyPrice;
                }
                this.dt.Rows.Add(new object[] {
                    apply.Item.Name,                                                                                                                                    //商品名称
                    apply.Item.Specs,                                                                                                                                   //规格
                    price,                                                                                                                                              //零售价
                    unit,                                                                                                                                               //包装单位
                    qty,                                                                                                                                                //申请数量
                    cost,                                                                                                                                               //申请金额
                    apply.Memo,                                                                                                                                         //备注
                    apply.Item.ID,                                                                                                                                      //物品编码
                    apply.SerialNO,                                                                                                                                     //序号
                    dataSource,
                    apply.Item.SpellCode,                                                                                                                               //拼音码
                    apply.Item.WBCode,                                                                                                                                  //五笔码
                    apply.Item.UserCode                                                                                                                                 //自定义码
                }
                                 );

                this.dt.DefaultView.AllowDelete = true;
                this.dt.DefaultView.AllowEdit   = true;
                this.dt.DefaultView.AllowNew    = true;
            }
            catch (System.Data.DataException e)
            {
                System.Windows.Forms.MessageBox.Show("DataTable内赋值发生错误" + e.Message);

                return(-1);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("DataTable内赋值发生错误" + ex.Message);

                return(-1);
            }

            return(1);
        }