/// <summary>
        /// 修改销售清单
        /// </summary>
        /// <param name="marketPartBill">销售清单主表信息</param>
        /// <param name="marketPritList">销售清单子表信息</param>
        /// <param name="role">操作角色</param>
        /// <param name="error">错误信息</param>
        /// <returns>修改成功返回True否则返回False</returns>
        public bool UpdateData(S_MarketingPartBill marketPartBill, List <View_S_MarketintPartList> marketPritList, string role, out string error)
        {
            error = "";

            try
            {
                DataTable dt = m_findSellIn.GetBill(marketPartBill.AssociatedBillNo, 0);

                DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

                var result = from a in dataContxt.S_MarketingPartBill
                             where a.BillNo == marketPartBill.BillNo && a.AssociatedBillNo == marketPartBill.AssociatedBillNo
                             select a;

                error = "判断角色";

                if (result.Count() > 0)
                {
                    S_MarketingPartBill bill = result.Single();

                    switch (role)
                    {
                    case "销售主管":
                        bill.YX_Auditor   = marketPartBill.YX_Auditor;
                        bill.YX_AuditTime = marketPartBill.YX_AuditTime;
                        bill.Status       = marketPartBill.Status;

                        SystemLog_MarketPart YXAuditorlog = new SystemLog_MarketPart();

                        YXAuditorlog.BillNo  = marketPartBill.BillNo;
                        YXAuditorlog.Content = marketPartBill.YX_AuditTime + "销售主管【"
                                               + m_personnerArchiveServer.GetPersonnelInfo(marketPartBill.YX_Auditor).Name + "】审核";
                        YXAuditorlog.Recorder   = marketPartBill.YX_Auditor;
                        YXAuditorlog.RecordTime = Convert.ToDateTime(marketPartBill.YX_AuditTime);

                        dataContxt.SystemLog_MarketPart.InsertOnSubmit(YXAuditorlog);

                        if (dt != null && dt.Rows.Count > 0)
                        {
                            if (m_findSellIn.AuditingBill(Convert.ToInt32(dt.Rows[0]["ID"].ToString()), marketPartBill.Remark, out error))
                            {
                                string storage = dt.Rows[0]["storageID"].ToString();

                                m_billMessageServer.BillType = "营销出库单";
                                m_billMessageServer.PassFlowMessage(marketPartBill.AssociatedBillNo,
                                                                    string.Format("{0} 号营销出库单,请财务审核", marketPartBill.AssociatedBillNo),
                                                                    BillFlowMessage_ReceivedUserType.角色, CE_RoleEnum.会计.ToString());

                                error = error + "/n" + "主管审核成功";
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            error = "找不到营销出库单【" + marketPartBill.AssociatedBillNo + "】";
                            return(false);
                        }

                        break;

                    case "销售":
                        bill.Recorder           = marketPartBill.Recorder;
                        bill.RecordTime         = marketPartBill.RecordTime;
                        bill.Status             = marketPartBill.Status;
                        bill.CiteTerminalClient = marketPartBill.CiteTerminalClient;
                        bill.IsCarLoad          = marketPartBill.IsCarLoad;

                        if (bill.ClientID != marketPartBill.ClientID)
                        {
                            bill.Remark = marketPartBill.Remark;

                            SystemLog_MarketPart log = new SystemLog_MarketPart();

                            log.BillNo  = marketPartBill.BillNo;
                            log.Content = marketPartBill.RecordTime + "销售人员【"
                                          + m_personnerArchiveServer.GetPersonnelInfo(marketPartBill.Recorder).Name + "】修改客户,将"
                                          + m_clientServer.GetClientName(result.Single().ClientID) + "修改为:"
                                          + m_clientServer.GetClientName(bill.ClientID) + "】";
                            log.Recorder   = marketPartBill.Recorder;
                            log.RecordTime = marketPartBill.RecordTime;

                            dataContxt.SystemLog_MarketPart.InsertOnSubmit(log);
                        }
                        else
                        {
                            bill.Remark = marketPartBill.Remark;

                            SystemLog_MarketPart log = new SystemLog_MarketPart();

                            log.BillNo  = marketPartBill.BillNo;
                            log.Content = marketPartBill.RecordTime + "销售人员【"
                                          + m_personnerArchiveServer.GetPersonnelInfo(marketPartBill.Recorder).Name + "】确认";
                            log.Recorder   = marketPartBill.Recorder;
                            log.RecordTime = marketPartBill.RecordTime;

                            dataContxt.SystemLog_MarketPart.InsertOnSubmit(log);
                        }

                        bill.ClientID = marketPartBill.ClientID;
                        dataContxt.SubmitChanges();

                        foreach (View_S_MarketintPartList item in marketPritList)
                        {
                            var resultList = from c in dataContxt.S_MarketintPartList
                                             where c.BillNo == item.单据号 && c.GoodsID == item.GoodsID && c.BatchNo == item.批次号
                                             select c;

                            if (resultList.Count() > 0)
                            {
                                S_MarketintPartList list = resultList.Single();

                                if (list.SellUnitPrice != item.销售单价)
                                {
                                    SystemLog_MarketPart log = new SystemLog_MarketPart();

                                    log.BillNo  = marketPartBill.BillNo;
                                    log.Content = marketPartBill.RecordTime + "销售人员【"
                                                  + m_personnerArchiveServer.GetPersonnelInfo(marketPartBill.Recorder).Name
                                                  + "】修改销售单价,将" + item.物品名称 + "销售单价" + resultList.Single().SellUnitPrice
                                                  + "修改为:" + item.销售单价 + "】";
                                    log.Recorder   = marketPartBill.Recorder;
                                    log.RecordTime = marketPartBill.RecordTime;

                                    dataContxt.SystemLog_MarketPart.InsertOnSubmit(log);
                                    dataContxt.SubmitChanges();
                                }

                                list.Reamrk          = item.备注;
                                list.SellUnitPrice   = item.销售单价;
                                list.UnitPrice       = item.最低定价;
                                list.AssemblyCarCode = item.主机厂代码;
                                list.AssemblyCarName = item.主机厂物品名称;

                                dataContxt.SubmitChanges();
                            }
                        }

                        var resultMarketing = from c in dataContxt.S_MarketingBill
                                              where c.DJH == marketPartBill.AssociatedBillNo
                                              select c;

                        if (resultMarketing.Count() > 0)
                        {
                            S_MarketingBill marketing = resultMarketing.Single();

                            marketing.DJZT_FLAG = "已保存";

                            m_billMessageServer.BillType = "营销出库单";
                            m_billMessageServer.PassFlowMessage(marketPartBill.AssociatedBillNo,
                                                                string.Format("{0} 号营销出库单,请主管审核", marketPartBill.AssociatedBillNo),
                                                                BillFlowMessage_ReceivedUserType.角色, CE_RoleEnum.营销主管.ToString());
                        }
                        else
                        {
                            error = "找不到营销出库单【" + marketPartBill.AssociatedBillNo + "】";
                            return(false);
                        }

                        break;

                    case "财务":
                        bill.CW_Auditor   = marketPartBill.CW_Auditor;
                        bill.CW_AuditTime = marketPartBill.CW_AuditTime;
                        bill.Status       = marketPartBill.Status;

                        if (bill.ClientID != marketPartBill.ClientID)
                        {
                            SystemLog_MarketPart log = new SystemLog_MarketPart();

                            log.BillNo  = marketPartBill.BillNo;
                            log.Content = marketPartBill.CW_AuditTime + "财务人员【"
                                          + m_personnerArchiveServer.GetPersonnelInfo(marketPartBill.CW_Auditor).Name
                                          + "】修改客户,将" + m_clientServer.GetClientName(result.Single().ClientID)
                                          + "修改为:" + m_clientServer.GetClientName(bill.ClientID) + "】";
                            log.Recorder   = marketPartBill.CW_Auditor;
                            log.RecordTime = Convert.ToDateTime(marketPartBill.CW_AuditTime);

                            dataContxt.SystemLog_MarketPart.InsertOnSubmit(log);
                        }
                        else
                        {
                            SystemLog_MarketPart log = new SystemLog_MarketPart();

                            log.BillNo  = marketPartBill.BillNo;
                            log.Content = marketPartBill.CW_AuditTime + "财务人员【"
                                          + m_personnerArchiveServer.GetPersonnelInfo(marketPartBill.CW_Auditor).Name + "】审核";
                            log.Recorder   = marketPartBill.CW_Auditor;
                            log.RecordTime = Convert.ToDateTime(marketPartBill.CW_AuditTime);

                            dataContxt.SystemLog_MarketPart.InsertOnSubmit(log);
                        }

                        bill.ClientID = marketPartBill.ClientID;
                        bill.Remark   = marketPartBill.Remark;

                        foreach (View_S_MarketintPartList item in marketPritList)
                        {
                            var resultList = from c in dataContxt.S_MarketintPartList
                                             where c.BillNo == item.单据号 && c.GoodsID == item.GoodsID && c.BatchNo == item.批次号 &&
                                             c.Provider == item.供应商
                                             select c;

                            if (resultList.Count() > 0)
                            {
                                S_MarketintPartList list = resultList.Single();

                                if (list.SellUnitPrice != item.销售单价)
                                {
                                    SystemLog_MarketPart log = new SystemLog_MarketPart();

                                    log.BillNo  = marketPartBill.BillNo;
                                    log.Content = marketPartBill.CW_AuditTime + "财务人员【"
                                                  + m_personnerArchiveServer.GetPersonnelInfo(marketPartBill.CW_Auditor).Name
                                                  + "】修改销售单价,将销售单价" + resultList.Single().SellUnitPrice + "修改为:"
                                                  + item.销售单价 + "】";
                                    log.Recorder   = marketPartBill.CW_Auditor;
                                    log.RecordTime = Convert.ToDateTime(marketPartBill.CW_AuditTime);

                                    dataContxt.SystemLog_MarketPart.InsertOnSubmit(log);
                                }

                                list.Reamrk        = item.备注;
                                list.SellUnitPrice = item.销售单价;
                            }
                        }

                        if (dt != null && dt.Rows.Count > 0)
                        {
                            if (dt.Rows[0]["DJZT_FLAG"].ToString() == "等待财务审核")
                            {
                                if (m_findSellIn.RetrialBill(marketPartBill.AssociatedBillNo, marketPartBill.Remark, out error))
                                {
                                    string storage = dt.Rows[0]["storageID"].ToString();

                                    m_billMessageServer.BillType = "营销出库单";
                                    m_billMessageServer.PassFlowMessage(marketPartBill.AssociatedBillNo,
                                                                        string.Format("{0} 号营销出库单,请仓管员确认", marketPartBill.AssociatedBillNo),
                                                                        m_billMessageServer.GetRoleStringForStorage(storage).ToString(), true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            error = "找不到营销出库单【" + marketPartBill.AssociatedBillNo + "】";
                            return(false);
                        }

                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    error = "未找到相关单据";
                    return(false);
                }

                dataContxt.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
        /// <summary>
        /// 插入营销出库业务
        /// </summary>
        /// <param name="contxt">数据上下文</param>
        /// <param name="threePacket">三包外售后返修单信息</param>
        /// <param name="dtListOfStorageID">库房信息</param>
        /// <param name="listTable">明细信息</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>插入成功返回True,插入失败返回False</returns>
        bool InsertYXCK(DepotManagementDataContext contxt, YX_ThreePacketsOfTheRepairBill threePacket,
                        DataTable dtListOfStorageID, DataTable listTable, out string error)
        {
            error = null;
            int    intDJID      = 0;
            SellIn serverSellIn = new SellIn();

            try
            {
                if (dtListOfStorageID == null || dtListOfStorageID.Rows.Count == 0)
                {
                    return(true);
                }
                else
                {
                    for (int k = 0; k < dtListOfStorageID.Rows.Count; k++)
                    {
                        string strBillID = m_serverAssignBill.AssignNewNo(serverSellIn, CE_BillTypeEnum.营销出库单.ToString());

                        S_MarketingBill lnqMarketingBill = new S_MarketingBill();

                        lnqMarketingBill.AffirmDate = ServerTime.Time;
                        lnqMarketingBill.Date       = Convert.ToDateTime(threePacket.FoundDate);
                        lnqMarketingBill.DJH        = strBillID;
                        lnqMarketingBill.DJZT_FLAG  = "已确认";
                        lnqMarketingBill.KFRY       = BasicInfo.LoginID;

                        string strDepartment = m_serverDepartment.GetDeptInfoFromPersonnelInfo(threePacket.FoundPersonnel).Rows[0]["DepartmentCode"].ToString();

                        lnqMarketingBill.LRKS       = strDepartment;
                        lnqMarketingBill.LRRY       = UniversalFunction.GetPersonnelCode(threePacket.FoundPersonnel);
                        lnqMarketingBill.SHRY       = m_serverPersonnel.GetFuzzyDeptDirector(strDepartment).ToList()[0].工号.ToString();
                        lnqMarketingBill.ShDate     = ServerTime.Time;
                        lnqMarketingBill.ObjectDept = "QT";
                        lnqMarketingBill.Remark     = "由三包外返修处理单【" + threePacket.Bill_ID + "】自动生成";
                        lnqMarketingBill.StorageID  = dtListOfStorageID.Rows[k][0].ToString();
                        lnqMarketingBill.YWFS       = "三包外返修出库";
                        lnqMarketingBill.YWLX       = "出库";

                        contxt.S_MarketingBill.InsertOnSubmit(lnqMarketingBill);

                        contxt.SubmitChanges();

                        var varID = from a in contxt.S_MarketingBill
                                    where a.DJH == lnqMarketingBill.DJH
                                    select a;

                        if (varID.Count() != 1)
                        {
                            error = "数据不唯一或者为空";
                            return(false);
                        }
                        else
                        {
                            intDJID = varID.Single().ID;
                        }

                        for (int i = 0; i < listTable.Rows.Count; i++)
                        {
                            if (Convert.ToBoolean(listTable.Rows[i]["是否为客户责任"]) &&
                                listTable.Rows[i][13].ToString().Trim() == dtListOfStorageID.Rows[k][0].ToString().Trim())
                            {
                                var varStock = from a in contxt.S_Stock
                                               where a.StorageID == dtListOfStorageID.Rows[k][0].ToString() &&
                                               a.GoodsID == Convert.ToInt32(listTable.Rows[i]["物品ID"]) &&
                                               a.BatchNo == listTable.Rows[i]["批次号"].ToString() &&
                                               a.Provider == listTable.Rows[i][14].ToString()
                                               select a;

                                if (varStock.Count() != 1)
                                {
                                    error = "库存信息不唯一或者为空";
                                    return(false);
                                }
                                else
                                {
                                    if (varStock.Single().GoodsStatus == 3)
                                    {
                                        error = "【" + varStock.Single().GoodsCode + "】 【" + varStock.Single().GoodsName + "】 【"
                                                + varStock.Single().Spec + "】【"
                                                + listTable.Rows[i]["批次号"].ToString()
                                                + "】物品库存状态为“隔离”不允许出库";

                                        return(false);
                                    }
                                }

                                S_MarketingList lnqMarketingList = new S_MarketingList();

                                lnqMarketingList.BatchNo = listTable.Rows[i]["批次号"].ToString();
                                lnqMarketingList.Count   = Convert.ToDecimal(listTable.Rows[i]["领用数量"]);
                                lnqMarketingList.CPID    = listTable.Rows[i]["物品ID"].ToString();
                                lnqMarketingList.DJ_ID   = intDJID;
                                lnqMarketingList.ReMark  = listTable.Rows[i]["备注"].ToString();
                                lnqMarketingList.Price   = Math.Round(Convert.ToDecimal(listTable.Rows[i]["单价"]) *
                                                                      Convert.ToDecimal(listTable.Rows[i]["领用数量"]), 2);
                                lnqMarketingList.Provider  = listTable.Rows[i][14].ToString();
                                lnqMarketingList.UnitPrice = Convert.ToDecimal(listTable.Rows[i]["单价"]);

                                contxt.S_MarketingList.InsertOnSubmit(lnqMarketingList);
                            }
                        }

                        contxt.SubmitChanges();

                        serverSellIn.OperationDetailAndStock_Out(contxt, lnqMarketingBill);
                        contxt.SubmitChanges();
                    }
                }

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