/// <summary>
        /// 审核单据
        /// </summary>
        /// <param name="afterService">数据集</param>
        /// <param name="listInfo">明细表</param>
        /// <param name="error">错误信息</param>
        /// <returns>成功返回True,失败返回False</returns>
        public bool VerifyBill(Out_AfterServicePartsApplyBill afterService, DataTable listInfo, out string error)
        {
            error = null;

            DepotManagementDataContext dataContext = CommentParameter.DepotDataContext;

            dataContext.Connection.Open();
            dataContext.Transaction = dataContext.Connection.BeginTransaction();

            try
            {
                var varData = from a in dataContext.Out_AfterServicePartsApplyBill
                              where a.Bill_ID == afterService.Bill_ID
                              select a;

                if (varData.Count() != 1)
                {
                    error = "数据不唯一或者为空";
                    throw new Exception(error);
                }
                else
                {
                    Out_AfterServicePartsApplyBill lnqBill = varData.Single();

                    lnqBill.BillStatus = "已完成";
                    lnqBill.Verify     = BasicInfo.LoginName;
                    lnqBill.VerifyTime = ServerTime.Time;

                    if (!DeleteListInfo(dataContext, lnqBill.Bill_ID, out error))
                    {
                        throw new Exception(error);
                    }

                    if (!InsertListInfo(dataContext, lnqBill.Bill_ID, listInfo, out error))
                    {
                        throw new Exception(error);
                    }

                    if (!CreateManeuver(dataContext, lnqBill, listInfo, out error))
                    {
                        throw new Exception(error);
                    }
                }

                dataContext.SubmitChanges();

                dataContext.Transaction.Commit();

                return(true);
            }
            catch (Exception ex)
            {
                dataContext.Transaction.Rollback();
                error = ex.Message;
                return(false);
            }
        }
        /// <summary>
        /// 创建调运单
        /// </summary>
        /// <param name="dataContext">数据上下文</param>
        /// <param name="afterService">数据集</param>
        /// <param name="listInfo">明细信息</param>
        /// <param name="error">错误信息</param>
        /// <returns>成功返回True,失败返回False</returns>
        bool CreateManeuver(DepotManagementDataContext dataContext, Out_AfterServicePartsApplyBill afterService, DataTable listInfo, out string error)
        {
            error = null;

            try
            {
                Out_ManeuverBill lnqBill = new Out_ManeuverBill();

                lnqBill.AssociatedBillNo = afterService.Bill_ID;
                lnqBill.Bill_ID          = "由系统自动生成";
                lnqBill.BillStatus       = "等待出库";
                lnqBill.InStorageID      = afterService.InStorageID;
                lnqBill.OutStorageID     = afterService.OutStorageID;
                lnqBill.Proposer         = afterService.Proposer;
                lnqBill.ProposerTime     = afterService.ProposerTime;
                lnqBill.Remark           = afterService.Remark;

                listInfo.Columns.Add("收货数量");
                listInfo.Columns.Add("发货数量");

                for (int i = 0; i < listInfo.Rows.Count; i++)
                {
                    listInfo.Rows[i]["申请数量"] = Convert.ToDecimal(listInfo.Rows[i]["审核数量"]);
                }

                if (!m_serverManeuver.InsertBill(lnqBill, listInfo, out error))
                {
                    return(false);
                }

                if (!m_serverManeuver.OperationInfo(lnqBill, listInfo, out error))
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
        public 售后配件申请明细(string billID, AuthorityFlag authFlag)
        {
            InitializeComponent();

            FaceAuthoritySetting.SetEnable(this.Controls, authFlag);
            FaceAuthoritySetting.SetVisibly(this.toolStrip, authFlag);

            m_billNoControl = new BillNumberControl(CE_BillTypeEnum.售后配件申请单, m_serverAfterService);

            this.toolStrip.Visible = true;

            if (billID == "")
            {
                txtBill_ID.Text   = "系统自动生成";
                lbBillStatus.Text = "新建单据";
            }
            else
            {
                m_lnqAfterService = m_serverAfterService.GetBillInfo(billID);

                txtBill_ID.Text     = m_lnqAfterService.Bill_ID;
                lbBillStatus.Text   = m_lnqAfterService.BillStatus;
                txtReceiving.Tag    = m_lnqAfterService.InStorageID;
                txtShipments.Tag    = m_lnqAfterService.OutStorageID;
                txtReceiving.Text   = UniversalFunction.GetStorageName(m_lnqAfterService.InStorageID);
                txtShipments.Text   = UniversalFunction.GetStorageName(m_lnqAfterService.OutStorageID);
                txtBillRemark.Text  = m_lnqAfterService.Remark;
                txt4SLinkMan.Text   = m_lnqAfterService._4SLinkMan;
                txt4SPhone.Text     = m_lnqAfterService._4SPhone;
                txtAddress.Text     = m_lnqAfterService.Address;
                txtApplyState.Text  = m_lnqAfterService.ApplyState;
                txtCVTType.Text     = m_lnqAfterService.CVTType;
                txtServiceErea.Text = m_lnqAfterService.ServiceErea;
                txtProductCode.Text = m_lnqAfterService.ProductCode;
            }

            dataGridView1.DataSource = m_serverAfterService.GetListInfo(billID);
            dataGridView1.Columns["物品ID"].Visible    = false;
            dataGridView1.Columns["Bill_ID"].Visible = false;
        }
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="afterService">数据集</param>
        /// <param name="listInfo">明细表</param>
        /// <param name="error">错误信息</param>
        /// <returns>成功返回True,失败返回False</returns>
        public bool InsertBill(Out_AfterServicePartsApplyBill afterService, DataTable listInfo, out string error)
        {
            error = null;

            try
            {
                DepotManagementDataContext dataContext = CommentParameter.DepotDataContext;

                var varData = from a in dataContext.Out_AfterServicePartsApplyBill
                              where a.Bill_ID == afterService.Bill_ID
                              select a;
                if (varData.Count() == 0)
                {
                    afterService.Bill_ID      = m_serverBillNo.AssignNewNo(this, "售后配件申请单");
                    afterService.BillStatus   = "等待主管审核";
                    afterService.Proposer     = BasicInfo.LoginName;
                    afterService.ProposerTime = ServerTime.Time;

                    if (!InsertListInfo(dataContext, afterService.Bill_ID, listInfo, out error))
                    {
                        return(false);
                    }

                    dataContext.Out_AfterServicePartsApplyBill.InsertOnSubmit(afterService);

                    m_billMessageServer.DestroyMessage(afterService.Bill_ID);
                    m_billMessageServer.SendNewFlowMessage(afterService.Bill_ID,
                                                           string.Format("{0}号售后配件申请单已提交,请营销主管审核", afterService.Bill_ID), CE_RoleEnum.营销主管);
                }
                else if (varData.Count() == 1)
                {
                    Out_AfterServicePartsApplyBill lnqBill = varData.Single();

                    lnqBill._4SLinkMan   = afterService._4SLinkMan;
                    lnqBill._4SPhone     = afterService._4SPhone;
                    lnqBill.Address      = afterService.Address;
                    lnqBill.ApplyState   = afterService.ApplyState;
                    lnqBill.CVTType      = afterService.CVTType;
                    lnqBill.InStorageID  = afterService.InStorageID;
                    lnqBill.OutStorageID = afterService.OutStorageID;
                    lnqBill.ProductCode  = afterService.ProductCode;
                    lnqBill.Proposer     = BasicInfo.LoginName;
                    lnqBill.ProposerTime = ServerTime.Time;
                    lnqBill.Remark       = afterService.Remark;
                    lnqBill.ServiceErea  = afterService.ServiceErea;

                    if (!DeleteListInfo(dataContext, lnqBill.Bill_ID, out error))
                    {
                        return(false);
                    }

                    if (!InsertListInfo(dataContext, lnqBill.Bill_ID, listInfo, out error))
                    {
                        return(false);
                    }


                    m_billMessageServer.DestroyMessage(afterService.Bill_ID);
                    m_billMessageServer.SendNewFlowMessage(afterService.Bill_ID,
                                                           string.Format("{0}号售后配件申请单已提交,请营销主管审核", afterService.Bill_ID), CE_RoleEnum.营销主管);
                }
                else
                {
                    error = "数据重复";
                    return(false);
                }

                dataContext.SubmitChanges();

                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }