/// <summary>
        /// 新增出差申请
        /// </summary>
        /// <param name="onBusiness">出差申请主信息</param>
        /// <param name="personnel">出差人员</param>
        /// <param name="schedule">出差行程安排</param>
        /// <param name="error">错误信息</param>
        /// <returns>成功返回新增的单据编号,失败返回0</returns>
        public int AddOnBusinessBill(HR_OnBusinessBill onBusiness, List <HR_OnBusinessPersonnel> personnel,
                                     List <HR_OnBusinessSchedule> schedule, out string error)
        {
            error = "";
            int billID = -1;
            DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

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

            try
            {
                dataContxt.HR_OnBusinessBill.InsertOnSubmit(onBusiness);
                dataContxt.SubmitChanges();

                var resultList = from a in dataContxt.HR_OnBusinessBill
                                 where a.Applicant == onBusiness.Applicant && a.ApplicantDate.Day == onBusiness.ApplicantDate.Day &&
                                 a.ApplicantDate.Minute == onBusiness.ApplicantDate.Minute
                                 select a;

                if (resultList.Count() == 1)
                {
                    billID = resultList.Single().ID;

                    foreach (var item in personnel)
                    {
                        HR_OnBusinessPersonnel personnleList = item;

                        personnleList.BillID            = billID;
                        personnleList.DeptSignatureDate = ServerTime.Time;

                        new AttendanceAnalysis().DataTimeIsRepeat <HR_OnBusinessBill>(dataContxt, resultList.Single(), personnleList.WorkID);
                        dataContxt.HR_OnBusinessPersonnel.InsertOnSubmit(personnleList);
                    }

                    foreach (var item in schedule)
                    {
                        HR_OnBusinessSchedule scheduleList = item;

                        scheduleList.BillID = billID;
                        dataContxt.HR_OnBusinessSchedule.InsertOnSubmit(scheduleList);
                    }
                }
                else
                {
                    dataContxt.HR_OnBusinessBill.DeleteOnSubmit(onBusiness);
                }

                dataContxt.SubmitChanges();
                dataContxt.Transaction.Commit();
                return(billID);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                dataContxt.Transaction.Rollback();
                return(-1);
            }
        }
        /// <summary>
        /// 修改出差申请
        /// </summary>
        /// <param name="onBusiness">出差申请主信息</param>
        /// <param name="personnel">出差人员</param>
        /// <param name="schedule">出差行程安排</param>
        /// <param name="billID">单据号</param>
        /// <param name="error">错误信息</param>
        /// <returns>成功返回true,失败返回False</returns>
        public bool UpdateOnBusinessBill(HR_OnBusinessBill onBusiness, List <HR_OnBusinessPersonnel> personnel,
                                         List <HR_OnBusinessSchedule> schedule, int billID, out string error)
        {
            error = "";

            try
            {
                DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

                var resultMain = from a in dataContxt.HR_OnBusinessBill
                                 where a.ID == billID
                                 select a;

                if (resultMain.Count() != 1)
                {
                    error = "信息有误,请查证后再操作!";
                    return(false);
                }
                else
                {
                    HR_OnBusinessBill bill = resultMain.Single();

                    bill.BorrowingAmount       = onBusiness.BorrowingAmount;
                    bill.EntertainmentExprense = onBusiness.EntertainmentExprense;
                    bill.ETC           = onBusiness.ETC;
                    bill.ETD           = onBusiness.ETD;
                    bill.IsBorrowing   = onBusiness.IsBorrowing;
                    bill.OtherExprense = onBusiness.OtherExprense;
                    bill.Purpose       = onBusiness.Purpose;
                    bill.Vehicle       = onBusiness.Vehicle;
                    bill.WithinBudget  = onBusiness.WithinBudget;
                    //bill.BillStatus = onBusiness.BillStatus;
                    //bill.Confirmor = "";
                    //bill.DeptPrincipal = "";
                    //bill.GeneralManager = "";
                    //bill.LeaderSignature = "";
                }

                var result = from c in dataContxt.HR_OnBusinessPersonnel
                             where c.BillID == billID
                             select c;

                if (result.Count() > 0)
                {
                    dataContxt.HR_OnBusinessPersonnel.DeleteAllOnSubmit(result);

                    foreach (var item in personnel)
                    {
                        HR_OnBusinessPersonnel personnleList = item;

                        personnleList.BillID            = billID;
                        personnleList.PersonnelType     = item.PersonnelType;
                        personnleList.WorkID            = item.WorkID;
                        personnleList.DeptSignatureDate = ServerTime.Time;

                        dataContxt.HR_OnBusinessPersonnel.InsertOnSubmit(personnleList);
                    }
                }

                var resultSchedule = from e in dataContxt.HR_OnBusinessSchedule
                                     where e.BillID == billID
                                     select e;

                if (resultSchedule.Count() > 0)
                {
                    dataContxt.HR_OnBusinessSchedule.DeleteAllOnSubmit(resultSchedule);

                    foreach (var item in schedule)
                    {
                        HR_OnBusinessSchedule scheduleList = item;

                        scheduleList.BillID      = billID;
                        scheduleList.Contact     = item.Contact;
                        scheduleList.Place       = item.Place;
                        scheduleList.Remark      = item.Remark;
                        scheduleList.StartTime   = item.StartTime;
                        scheduleList.EndTime     = item.EndTime;
                        scheduleList.WorkContent = item.WorkContent;
                        scheduleList.Vehicle     = item.Vehicle;

                        dataContxt.HR_OnBusinessSchedule.InsertOnSubmit(scheduleList);
                    }
                }
                else
                {
                    foreach (var item in schedule)
                    {
                        HR_OnBusinessSchedule scheduleList = item;

                        scheduleList.BillID      = billID;
                        scheduleList.Contact     = item.Contact;
                        scheduleList.Place       = item.Place;
                        scheduleList.Remark      = item.Remark;
                        scheduleList.StartTime   = item.StartTime;
                        scheduleList.EndTime     = item.EndTime;
                        scheduleList.WorkContent = item.WorkContent;
                        scheduleList.Vehicle     = item.Vehicle;

                        dataContxt.HR_OnBusinessSchedule.InsertOnSubmit(scheduleList);
                    }
                }

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