示例#1
0
        /// <summary>
        /// 对BOM表中数据进行变更
        /// </summary>
        /// <param name="datatContxt">数据上下文</param>
        /// <param name="technology">单据信息数据集</param>
        /// <param name="listInfo">变更单信息</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>变更成功返回True,变更失败返回False</returns>
        public bool UpdateBOMDate(DepotManagementDataContext datatContxt,
                                  S_TechnologyAlterationBill technology, DataTable listInfo, out string error)
        {
            error = null;
            DateTime time = ServerTime.Time;

            try
            {
                for (int i = 0; i < listInfo.Rows.Count; i++)
                {
                    F_GoodsPlanCost      lnqGoodsPlan = new F_GoodsPlanCost();
                    BASE_BomStruct       lnqBomStruct = new BASE_BomStruct();
                    BASE_BomPartsLibrary lnqLibrary   = new BASE_BomPartsLibrary();
                    DataRow row = listInfo.Rows[i];

                    if (row["变更模式"].ToString() == "新增")
                    {
                        if (row["NewGoodsID"] != null)
                        {
                            var resultGoods = from a in datatContxt.F_GoodsPlanCost
                                              where a.GoodsCode == row["新零件编码"].ToString() &&
                                              a.GoodsName == row["新零件名称"].ToString() && a.Spec == row["新零件规格"].ToString()
                                              select a;

                            if (resultGoods.Count() == 0)
                            {
                                lnqGoodsPlan.UserCode       = technology.Applicant;
                                lnqGoodsPlan.Date           = time;
                                lnqGoodsPlan.GoodsCode      = row["新零件编码"].ToString();
                                lnqGoodsPlan.GoodsName      = row["新零件名称"].ToString();
                                lnqGoodsPlan.Spec           = row["新零件规格"].ToString();
                                lnqGoodsPlan.GoodsType      = "030101";
                                lnqGoodsPlan.GoodsUnitPrice = 0;
                                lnqGoodsPlan.IsDisable      = false;
                                lnqGoodsPlan.PY             = UniversalFunction.GetPYWBCode(row["新零件名称"].ToString(), "PY");
                                lnqGoodsPlan.WB             = UniversalFunction.GetPYWBCode(row["新零件名称"].ToString(), "WB");
                                lnqGoodsPlan.Remark         = "由技术变更单【" + technology.BillNo + "】新增";
                                lnqGoodsPlan.UnitID         = 1;

                                datatContxt.F_GoodsPlanCost.InsertOnSubmit(lnqGoodsPlan);
                            }

                            var varBomPartsLibrary = from a in datatContxt.BASE_BomPartsLibrary
                                                     where a.GoodsID == Convert.ToInt32(row["NewGoodsID"])
                                                     select a;

                            if (varBomPartsLibrary.Count() == 0)
                            {
                                lnqLibrary.CreateDate      = time;
                                lnqLibrary.CreatePersonnel = technology.Applicant;
                                lnqLibrary.GoodsID         = Convert.ToInt32(row["NewGoodsID"]);
                                lnqLibrary.Material        = "未知";
                                lnqLibrary.PartType        = "产品";
                                lnqLibrary.PivotalPart     = "A";
                                lnqLibrary.Remark          = "由技术变更单【" + technology.BillNo + "】生成";
                                lnqLibrary.Version         = row["新零件版次号"].ToString();

                                datatContxt.BASE_BomPartsLibrary.InsertOnSubmit(lnqLibrary);
                            }
                            else if (varBomPartsLibrary.Count() == 1)
                            {
                                lnqLibrary = varBomPartsLibrary.Single();

                                lnqLibrary.Version         = row["新零件版次号"].ToString() == "" ? varBomPartsLibrary.Single().Version : row["新零件版次号"].ToString();
                                lnqLibrary.CreateDate      = time;
                                lnqLibrary.CreatePersonnel = technology.Applicant;
                            }
                        }

                        if (row["NewParentID"] != null && row["NewGoodsID"] != null)
                        {
                            lnqBomStruct.CreateDate      = time;
                            lnqBomStruct.CreatePersonnel = technology.Applicant;
                            lnqBomStruct.GoodsID         = Convert.ToInt32(row["NewGoodsID"]);
                            lnqBomStruct.ParentID        = Convert.ToInt32(row["NewParentID"]);
                            lnqBomStruct.SysVersion      = 1;
                            lnqBomStruct.Usage           = Convert.ToDecimal(row["新零件基数"]);

                            datatContxt.BASE_BomStruct.InsertOnSubmit(lnqBomStruct);
                        }
                    }
                    else if (row["变更模式"].ToString() == "修改" && row["是否修改零件本身"].ToString() == "否")
                    {
                        if (row["NewGoodsID"] != null)
                        {
                            var varBomPartsLibrary = from a in datatContxt.BASE_BomPartsLibrary
                                                     where a.GoodsID == Convert.ToInt32(row["NewGoodsID"])
                                                     select a;

                            if (varBomPartsLibrary.Count() == 0)
                            {
                                lnqLibrary.CreateDate      = time;
                                lnqLibrary.CreatePersonnel = technology.Applicant;
                                lnqLibrary.GoodsID         = Convert.ToInt32(row["NewGoodsID"]);
                                lnqLibrary.Material        = "未知";
                                lnqLibrary.PartType        = "产品";
                                lnqLibrary.PivotalPart     = "A";
                                lnqLibrary.Remark          = "由技术变更单【" + technology.BillNo + "】生成";
                                lnqLibrary.Version         = row["新零件版次号"].ToString();

                                datatContxt.BASE_BomPartsLibrary.InsertOnSubmit(lnqLibrary);
                            }
                            else
                            {
                                lnqLibrary = varBomPartsLibrary.Single();

                                lnqLibrary.Version = row["新零件版次号"].ToString();
                            }
                        }

                        if (row["OldParentID"] != null && row["NewParentID"] != null &&
                            row["OldGoodsID"] != null && row["NewGoodsID"] != null &&
                            (int)row["OldParentID"] != 0 && (int)row["NewParentID"] != 0)
                        {
                            var varBomStruct = from a in datatContxt.BASE_BomStruct
                                               where a.ParentID == Convert.ToInt32(row["OldParentID"]) &&
                                               a.GoodsID == Convert.ToInt32(row["OldGoodsID"])
                                               select a;

                            if (varBomStruct.Count() < 1)
                            {
                                error = "BOM结构表中不存在此记录";
                                return(false);
                            }
                            else
                            {
                                lnqBomStruct = varBomStruct.Single();

                                lnqBomStruct.CreateDate      = time;
                                lnqBomStruct.CreatePersonnel = technology.Applicant;
                                lnqBomStruct.GoodsID         = Convert.ToInt32(row["NewGoodsID"]);
                                lnqBomStruct.ParentID        = Convert.ToInt32(row["NewParentID"]);
                                lnqBomStruct.SysVersion      = lnqBomStruct.SysVersion + Convert.ToDecimal(0.01);
                                lnqBomStruct.Usage           = Convert.ToDecimal(row["新零件基数"]);

                                var result = from a in datatContxt.BASE_BomStruct
                                             where a.ParentID == Convert.ToInt32(row["OldGoodsID"])
                                             select a;

                                foreach (BASE_BomStruct item in result)
                                {
                                    if (item.ParentID != Convert.ToInt32(row["NewGoodsID"]))
                                    {
                                        BASE_BomStruct baseBom = new BASE_BomStruct();

                                        baseBom.ParentID        = Convert.ToInt32(row["NewGoodsID"]);
                                        baseBom.CreateDate      = time;
                                        baseBom.CreatePersonnel = technology.Applicant;
                                        baseBom.GoodsID         = item.GoodsID;
                                        baseBom.SysVersion      = item.SysVersion;
                                        baseBom.Usage           = item.Usage;

                                        datatContxt.BASE_BomStruct.InsertOnSubmit(baseBom);
                                    }
                                }
                            }
                        }
                        else
                        {
                            var varBomStruct = from a in datatContxt.BASE_BomStruct
                                               where a.GoodsID == Convert.ToInt32(row["OldGoodsID"])
                                               select a;

                            foreach (BASE_BomStruct item in varBomStruct)
                            {
                                item.CreateDate      = ServerTime.Time;
                                item.CreatePersonnel = technology.Applicant;
                                item.GoodsID         = Convert.ToInt32(row["NewGoodsID"]);
                                item.ParentID        = item.ParentID;
                                item.SysVersion      = lnqBomStruct.SysVersion + Convert.ToDecimal(0.01);
                                item.Usage           = Convert.ToDecimal(row["新零件基数"]);
                            }
                        }
                    }
                    else if (row["变更模式"].ToString() == "修改" && row["是否修改零件本身"].ToString() == "是")
                    {
                        if (row["NewGoodsID"] != null && row["OldGoodsID"] != null)
                        {
                            var resultGoods = from a in datatContxt.F_GoodsPlanCost
                                              where a.ID == Convert.ToInt32(row["OldGoodsID"])
                                              select a;

                            if (resultGoods.Count() == 1)
                            {
                                lnqGoodsPlan = resultGoods.Single();

                                lnqGoodsPlan.UserCode  = technology.Applicant;
                                lnqGoodsPlan.Date      = ServerTime.Time;
                                lnqGoodsPlan.GoodsCode = row["新零件编码"].ToString();
                                lnqGoodsPlan.GoodsName = row["新零件名称"].ToString();
                                lnqGoodsPlan.Spec      = row["新零件规格"].ToString();
                                lnqGoodsPlan.PY        = UniversalFunction.GetPYWBCode(row["新零件名称"].ToString(), "PY");
                                lnqGoodsPlan.WB        = UniversalFunction.GetPYWBCode(row["新零件名称"].ToString(), "WB");
                                lnqGoodsPlan.Remark    = "由技术变更单【" + technology.BillNo + "】修改零件";
                            }
                            else
                            {
                                error = row["新零件名称"].ToString() + "修改失败";
                                return(false);
                            }

                            var varBomPartsLibrary = from a in datatContxt.BASE_BomPartsLibrary
                                                     where a.GoodsID == Convert.ToInt32(row["NewGoodsID"])
                                                     select a;

                            if (varBomPartsLibrary.Count() != 1)
                            {
                                error = "新零件在零件库中不存在";
                                return(false);
                            }
                            else
                            {
                                lnqLibrary = varBomPartsLibrary.Single();

                                lnqLibrary.Version = row["新零件版次号"].ToString();
                            }
                        }
                    }
                    else if (row["变更模式"].ToString() == "删除")
                    {
                        if (row["OldParentID"] == null)
                        {
                            var varStruct = from a in datatContxt.BASE_BomStruct
                                            where a.GoodsID == Convert.ToInt32(row["OldGoodsID"])
                                            select a;

                            datatContxt.BASE_BomStruct.DeleteAllOnSubmit(varStruct);

                            var varLibrary = from a in datatContxt.BASE_BomPartsLibrary
                                             where a.GoodsID == Convert.ToInt32(row["OldGoodsID"])
                                             select a;

                            datatContxt.BASE_BomPartsLibrary.DeleteAllOnSubmit(varLibrary);
                        }
                        else
                        {
                            var varStruct = from a in datatContxt.BASE_BomStruct
                                            where a.ParentID == Convert.ToInt32(row["OldParentID"]) &&
                                            a.GoodsID == Convert.ToInt32(row["OldGoodsID"])
                                            select a;

                            if (varStruct.Count() != 1)
                            {
                                error = "BOM结构表中不存在此记录";
                                return(false);
                            }
                            else
                            {
                                lnqBomStruct = varStruct.Single();
                                datatContxt.BASE_BomStruct.DeleteOnSubmit(lnqBomStruct);
                            }
                        }
                    }

                    datatContxt.SubmitChanges();
                }

                #region
                //switch (technology.ChangeMode)
                //{
                //    case "新增":

                //        #region 新增

                //        for (int i = 0; i < listInfo.Rows.Count; i++)
                //        {
                //            DataRow row = listInfo.Rows[i];

                //            if (row["NewGoodsID"] != null)
                //            {
                //                var resultGoods = from a in datatContxt.F_GoodsPlanCost
                //                                  where a.GoodsCode == row["新零件编码"].ToString()
                //                                  && a.GoodsName == row["新零件名称"].ToString() && a.Spec == row["新零件规格"].ToString()
                //                                  select a;

                //                if (resultGoods.Count() == 0)
                //                {
                //                    lnqGoodsPlan.UserCode = technology.Applicant;
                //                    lnqGoodsPlan.Date = ServerTime.Time;
                //                    lnqGoodsPlan.GoodsCode = row["新零件编码"].ToString();
                //                    lnqGoodsPlan.GoodsName = row["新零件名称"].ToString();
                //                    lnqGoodsPlan.Spec = row["新零件规格"].ToString();
                //                    lnqGoodsPlan.GoodsType = "ZZLJJXLFBZ";
                //                    lnqGoodsPlan.GoodsUnitPrice = 0;
                //                    lnqGoodsPlan.IsDisable = false;
                //                    lnqGoodsPlan.IsShelfLife = false;
                //                    lnqGoodsPlan.PY = UniversalFunction.GetPYWBCode(row["新零件名称"].ToString(), "PY");
                //                    lnqGoodsPlan.WB = UniversalFunction.GetPYWBCode(row["新零件名称"].ToString(), "WB");
                //                    lnqGoodsPlan.Remark = "由技术变更单【" + technology.BillNo + "】新增";
                //                    lnqGoodsPlan.UnitID = 1;

                //                    datatContxt.F_GoodsPlanCost.InsertOnSubmit(lnqGoodsPlan);
                //                }

                //                var varBomPartsLibrary = from a in datatContxt.BASE_BomPartsLibrary
                //                                         where a.GoodsID == Convert.ToInt32(row["NewGoodsID"])
                //                                         select a;

                //                if (varBomPartsLibrary.Count() == 0)
                //                {
                //                    lnqLibrary.CreateDate = ServerTime.Time;
                //                    lnqLibrary.CreatePersonnel = technology.Applicant;
                //                    lnqLibrary.GoodsID = Convert.ToInt32(row["NewGoodsID"]);
                //                    lnqLibrary.Material = "未知";
                //                    lnqLibrary.PartType = "产品";
                //                    lnqLibrary.PivotalPart = "A";
                //                    lnqLibrary.Remark = "由技术变更单【" + technology.BillNo + "】生成";
                //                    lnqLibrary.Version = row["新零件版次号"].ToString();

                //                    datatContxt.BASE_BomPartsLibrary.InsertOnSubmit(lnqLibrary);
                //                }
                //                else if (varBomPartsLibrary.Count() == 1)
                //                {
                //                    lnqLibrary = varBomPartsLibrary.Single();

                //                    lnqLibrary.Version = row["新零件版次号"].ToString();
                //                    lnqLibrary.CreateDate = ServerTime.Time;
                //                    lnqLibrary.CreatePersonnel = technology.Applicant;
                //                }
                //            }

                //            if (row["NewParentID"] != null && row["NewGoodsID"] != null)
                //            {
                //                lnqBomStruct.CreateDate = ServerTime.Time;
                //                lnqBomStruct.CreatePersonnel = technology.Applicant;
                //                lnqBomStruct.GoodsID = Convert.ToInt32(row["NewGoodsID"]);
                //                lnqBomStruct.ParentID = Convert.ToInt32(row["NewParentID"]);
                //                lnqBomStruct.SysVersion = 1;
                //                lnqBomStruct.Usage = Convert.ToDecimal(row["新零件基数"]);

                //                datatContxt.BASE_BomStruct.InsertOnSubmit(lnqBomStruct);
                //            }
                //        }
                //        #endregion

                //        break;
                //    case "修改":

                //        #region

                //        for (int i = 0; i < listInfo.Rows.Count; i++)
                //        {
                //            DataRow row = listInfo.Rows[i];

                //            if (row["NewGoodsID"] != null)
                //            {
                //                var varBomPartsLibrary = from a in datatContxt.BASE_BomPartsLibrary
                //                                         where a.GoodsID == Convert.ToInt32(row["NewGoodsID"])
                //                                         select a;

                //                if (varBomPartsLibrary.Count() != 1)
                //                {
                //                    error = "新零件在零件库中不存在";
                //                    return false;
                //                }
                //                else
                //                {
                //                    lnqLibrary = varBomPartsLibrary.Single();

                //                    lnqLibrary.Version = row["新零件版次号"].ToString();
                //                }
                //            }

                //            if (row["OldParentID"] != null && row["NewParentID"] != null
                //                && row["OldGoodsID"] != null && row["NewGoodsID"] != null)
                //            {
                //                var varBomStruct = from a in datatContxt.BASE_BomStruct
                //                                   where a.ParentID == Convert.ToInt32(row["OldParentID"])
                //                                   && a.GoodsID == Convert.ToInt32(row["OldGoodsID"])
                //                                   select a;

                //                if (varBomStruct.Count() != 1)
                //                {
                //                    error = "BOM结构表中不存在此记录";
                //                    return false;
                //                }
                //                else
                //                {
                //                    lnqBomStruct = varBomStruct.Single();

                //                    lnqBomStruct.CreateDate = ServerTime.Time;
                //                    lnqBomStruct.CreatePersonnel = technology.Applicant;
                //                    lnqBomStruct.GoodsID = Convert.ToInt32(row["NewGoodsID"]);
                //                    lnqBomStruct.ParentID = Convert.ToInt32(row["NewParentID"]);
                //                    lnqBomStruct.SysVersion = lnqBomStruct.SysVersion + Convert.ToDecimal(0.01);
                //                    lnqBomStruct.Usage = Convert.ToDecimal(row["新零件基数"]);
                //                }
                //            }
                //        }
                //        #endregion

                //        break;
                //    case "删除":

                //        #region 删除
                //        for (int i = 0; i < listInfo.Rows.Count; i++)
                //        {
                //            DataRow row = listInfo.Rows[i];

                //            if (row["OldParentID"] == null)
                //            {

                //                var varStruct = from a in datatContxt.BASE_BomStruct
                //                                where a.GoodsID == Convert.ToInt32(row["OldGoodsID"])
                //                                select a;

                //                datatContxt.BASE_BomStruct.DeleteAllOnSubmit(varStruct);

                //                var varLibrary = from a in datatContxt.BASE_BomPartsLibrary
                //                                 where a.GoodsID == Convert.ToInt32(row["OldGoodsID"])
                //                                 select a;

                //                datatContxt.BASE_BomPartsLibrary.DeleteAllOnSubmit(varLibrary);
                //            }
                //            else
                //            {
                //                var varStruct = from a in datatContxt.BASE_BomStruct
                //                                where a.ParentID == Convert.ToInt32(row["OldParentID"])
                //                                && a.GoodsID == Convert.ToInt32(row["OldGoodsID"])
                //                                select a;

                //                if (varStruct.Count() != 1)
                //                {
                //                    error = "BOM结构表中不存在此记录";
                //                    return false;
                //                }
                //                else
                //                {
                //                    lnqBomStruct = varStruct.Single();
                //                    datatContxt.BASE_BomStruct.DeleteOnSubmit(lnqBomStruct);
                //                }
                //            }
                //        }
                //        #endregion
                //        break;
                //    case "修改零件本身":

                //        for (int i = 0; i < listInfo.Rows.Count; i++)
                //        {
                //            DataRow row = listInfo.Rows[i];

                //            if (row["NewGoodsID"] != null && row["OldGoodsID"] != null)
                //            {
                //                var resultGoods = from a in datatContxt.F_GoodsPlanCost
                //                                  where a.ID == Convert.ToInt32(row["OldGoodsID"])
                //                                  select a;

                //                if (resultGoods.Count() == 1)
                //                {
                //                    lnqGoodsPlan = resultGoods.Single();

                //                    lnqGoodsPlan.UserCode = technology.Applicant;
                //                    lnqGoodsPlan.Date = ServerTime.Time;
                //                    lnqGoodsPlan.GoodsCode = row["新零件编码"].ToString();
                //                    lnqGoodsPlan.GoodsName = row["新零件名称"].ToString();
                //                    lnqGoodsPlan.Spec = row["新零件规格"].ToString();
                //                    lnqGoodsPlan.PY = UniversalFunction.GetPYWBCode(row["新零件名称"].ToString(), "PY");
                //                    lnqGoodsPlan.WB = UniversalFunction.GetPYWBCode(row["新零件名称"].ToString(), "WB");
                //                    lnqGoodsPlan.Remark = "由技术变更单【" + technology.BillNo + "】修改零件";
                //                }
                //                else
                //                {
                //                    error = row["新零件名称"].ToString() + "修改失败";
                //                    return false;
                //                }

                //                //var varBomPartsLibrary = from a in datatContxt.BASE_BomPartsLibrary
                //                //                         where a.GoodsID == Convert.ToInt32(row["NewGoodsID"])
                //                //                         select a;

                //                //if (varBomPartsLibrary.Count() == 0)
                //                //{
                //                //    lnqLibrary.CreateDate = ServerTime.Time;
                //                //    lnqLibrary.CreatePersonnel = technology.Applicant;
                //                //    lnqLibrary.GoodsID = Convert.ToInt32(row["NewGoodsID"]);
                //                //    lnqLibrary.Material = "未知";
                //                //    lnqLibrary.PartType = "产品";
                //                //    lnqLibrary.PivotalPart = "A";
                //                //    lnqLibrary.Remark = "由技术变更单【" + technology.BillNo + "】生成";
                //                //    lnqLibrary.Version = row["新零件版次号"].ToString();

                //                //    datatContxt.BASE_BomPartsLibrary.InsertOnSubmit(lnqLibrary);
                //                //}
                //                //else if (varBomPartsLibrary.Count() == 1)
                //                //{
                //                //    lnqLibrary = varBomPartsLibrary.Single();

                //                //    lnqLibrary.Version = row["新零件版次号"].ToString();
                //                //    lnqLibrary.CreateDate = ServerTime.Time;
                //                //    lnqLibrary.CreatePersonnel = technology.Applicant;
                //                //}
                //            }

                //            //if (row["OldParentID"] != null && row["NewParentID"] != null
                //            //    && row["OldGoodsID"] != null && row["NewGoodsID"] != null)
                //            //{
                //            //    var varBomStruct = from a in datatContxt.BASE_BomStruct
                //            //                       where a.ParentID == Convert.ToInt32(row["OldParentID"])
                //            //                       && a.GoodsID == Convert.ToInt32(row["OldGoodsID"])
                //            //                       select a;

                //            //    if (varBomStruct.Count() != 1)
                //            //    {
                //            //        error = "BOM结构表中不存在此记录";
                //            //        return false;
                //            //    }
                //            //    else
                //            //    {
                //            //        lnqBomStruct = varBomStruct.Single();

                //            //        lnqBomStruct.CreateDate = ServerTime.Time;
                //            //        lnqBomStruct.CreatePersonnel = technology.Applicant;
                //            //        lnqBomStruct.GoodsID = Convert.ToInt32(row["NewGoodsID"]);
                //            //        lnqBomStruct.ParentID = Convert.ToInt32(row["NewParentID"]);
                //            //        lnqBomStruct.SysVersion = lnqBomStruct.SysVersion + Convert.ToDecimal(0.01);
                //            //        lnqBomStruct.Usage = Convert.ToDecimal(row["新零件基数"]);
                //            //    }
                //            //}
                //        }
                //        break;
                //    default:
                //        break;
                //}
                #endregion

                datatContxt.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
        /// <summary>
        /// 对BOM表中数据进行变更
        /// </summary>
        /// <param name="context">数据上下文</param>
        /// <param name="inBill">变更单信息</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>变更成功返回True,变更失败返回False</returns>
        public bool UpdateBOMDate(DepotManagementDataContext context,
                                  S_TechnologyChangeBill inBill, out string error)
        {
            error = null;

            try
            {
                BASE_BomStruct lnqBomStruct = new BASE_BomStruct();

                BASE_BomPartsLibrary lnqLibrary = new BASE_BomPartsLibrary();

                switch (inBill.ChangeMode)
                {
                case "新增":

                    if (inBill.NewGoodsID != null)
                    {
                        var varBomPartsLibrary = from a in context.BASE_BomPartsLibrary
                                                 where a.GoodsID == Convert.ToInt32(inBill.NewGoodsID)
                                                 select a;

                        if (varBomPartsLibrary.Count() == 0)
                        {
                            lnqLibrary.CreateDate      = ServerTime.Time;
                            lnqLibrary.CreatePersonnel = UniversalFunction.GetPersonnelCode(inBill.SQRY);
                            lnqLibrary.GoodsID         = Convert.ToInt32(inBill.NewGoodsID);
                            lnqLibrary.Material        = "未知";
                            lnqLibrary.PartType        = "产品";
                            lnqLibrary.PivotalPart     = "A";
                            lnqLibrary.Remark          = "由技术变更单【" + inBill.DJH + "】生成";
                            lnqLibrary.Version         = inBill.NewVersion;

                            context.BASE_BomPartsLibrary.InsertOnSubmit(lnqLibrary);
                        }
                        else if (varBomPartsLibrary.Count() == 1)
                        {
                            lnqLibrary = varBomPartsLibrary.Single();

                            lnqLibrary.Version         = inBill.NewVersion;
                            lnqLibrary.CreateDate      = ServerTime.Time;
                            lnqLibrary.CreatePersonnel = UniversalFunction.GetPersonnelCode(inBill.SQRY);
                        }
                    }

                    if (inBill.NewParentID != null && inBill.NewGoodsID != null)
                    {
                        lnqBomStruct.CreateDate      = ServerTime.Time;
                        lnqBomStruct.CreatePersonnel = UniversalFunction.GetPersonnelCode(inBill.SQRY);
                        lnqBomStruct.GoodsID         = Convert.ToInt32(inBill.NewGoodsID);
                        lnqBomStruct.ParentID        = Convert.ToInt32(inBill.NewParentID);
                        lnqBomStruct.SysVersion      = 1;
                        lnqBomStruct.Usage           = Convert.ToDecimal(inBill.NewCounts);

                        context.BASE_BomStruct.InsertOnSubmit(lnqBomStruct);
                    }

                    break;

                case "修改":

                    #region
                    //if (inBill.NewGoodsID != null)
                    //{
                    //    var varBomPartsLibrary = from a in context.BASE_BomPartsLibrary
                    //                             where a.GoodsID == Convert.ToInt32(inBill.NewGoodsID)
                    //                             select a;

                    //    if (varBomPartsLibrary.Count() != 1)
                    //    {
                    //        error = "新零件在零件库中不存在";
                    //        return false;
                    //    }
                    //    else
                    //    {
                    //        lnqLibrary = varBomPartsLibrary.Single();

                    //        lnqLibrary.Version = inBill.NewVersion;
                    //    }
                    //}

                    //if (inBill.OldParentID != null
                    //    && inBill.NewParentID != null
                    //    && inBill.OldGoodsID != null
                    //    && inBill.NewGoodsID != null)
                    //{
                    //    var varBomStruct = from a in context.BASE_BomStruct
                    //                       where a.ParentID == Convert.ToInt32(inBill.OldParentID)
                    //                       && a.GoodsID == Convert.ToInt32(inBill.OldGoodsID)
                    //                       select a;

                    //    if (varBomStruct.Count() != 1)
                    //    {
                    //        error = "BOM结构表中不存在此记录";
                    //        return false;
                    //    }
                    //    else
                    //    {
                    //        lnqBomStruct = varBomStruct.Single();

                    //        lnqBomStruct.CreateDate = ServerTime.Time;
                    //        lnqBomStruct.CreatePersonnel = UniversalFunction.GetPersonnelCode(inBill.SQRY);
                    //        lnqBomStruct.GoodsID = Convert.ToInt32(inBill.NewGoodsID);
                    //        lnqBomStruct.ParentID = Convert.ToInt32(inBill.NewParentID);
                    //        lnqBomStruct.SysVersion = lnqBomStruct.SysVersion + Convert.ToDecimal( 0.01);
                    //        lnqBomStruct.Usage = Convert.ToDecimal(inBill.NewCounts);
                    //    }
                    //}
                    #endregion

                    break;

                case "删除":

                    if (inBill.OldParentID == null)
                    {
                        var varStruct = from a in context.BASE_BomStruct
                                        where a.GoodsID == Convert.ToInt32(inBill.OldGoodsID)
                                        select a;

                        context.BASE_BomStruct.DeleteAllOnSubmit(varStruct);

                        var varLibrary = from a in context.BASE_BomPartsLibrary
                                         where a.GoodsID == Convert.ToInt32(inBill.OldGoodsID)
                                         select a;

                        context.BASE_BomPartsLibrary.DeleteAllOnSubmit(varLibrary);
                    }
                    else
                    {
                        var varStruct = from a in context.BASE_BomStruct
                                        where a.ParentID == Convert.ToInt32(inBill.OldParentID) &&
                                        a.GoodsID == Convert.ToInt32(inBill.OldGoodsID)
                                        select a;

                        if (varStruct.Count() != 1)
                        {
                            error = "BOM结构表中不存在此记录";
                            return(false);
                        }
                        else
                        {
                            lnqBomStruct = varStruct.Single();
                            context.BASE_BomStruct.DeleteOnSubmit(lnqBomStruct);
                        }
                    }

                    break;

                default:
                    break;
                }

                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
        /// <summary>
        /// 操作流程以外的业务
        /// </summary>
        /// <param name="billNo">单据号</param>
        public void OperatarUnFlowBusiness(string billNo)
        {
            IFlowServer serviceFlow = FlowControlService.ServerModuleFactory.GetServerModule <IFlowServer>();

            string billStatus = serviceFlow.GetNextBillStatus(billNo);

            if (billStatus == null)
            {
                throw new Exception("单据状态为空,请重新确认");
            }

            if (billStatus != CE_CommonBillStatus.单据完成.ToString())
            {
                return;
            }

            DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

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

            try
            {
                List <View_Business_Base_BomChange_Struct>       lstStruct  = GetListStructInfo(billNo);
                List <View_Business_Base_BomChange_PartsLibrary> lstLibrary = GetListLibraryInfo(billNo);

                List <Flow_FlowData> tempList = serviceFlow.GetBusinessOperationInfo(billNo, CE_CommonBillStatus.新建单据.ToString());

                if (tempList == null)
                {
                    throw new Exception("获取操作人员失败");
                }

                JudgeAssembly(dataContxt, lstStruct);
                string personnel = tempList[0].OperationPersonnel;

                #region 零件库变更

                foreach (var item2 in lstLibrary)
                {
                    CE_OperatorMode operationMode =
                        GlobalObject.GeneralFunction.StringConvertToEnum <CE_OperatorMode>(item2.操作类型);

                    switch (operationMode)
                    {
                    case CE_OperatorMode.添加:

                        var varTemp4 = from a in dataContxt.BASE_BomPartsLibrary
                                       where a.GoodsID == item2.物品ID
                                       select a;

                        if (varTemp4 != null && varTemp4.Count() == 1)
                        {
                            BASE_BomPartsLibrary library1 = varTemp4.Single();

                            library1.CreateDate      = ServerTime.Time;
                            library1.CreatePersonnel = personnel;
                            library1.Material        = item2.材质;
                            library1.PartType        = item2.零件类型;
                            library1.PivotalPart     = item2.关键件;
                            library1.Remark          = item2.备注;
                            library1.Version         = item2.版次号;
                        }
                        else if (varTemp4.Count() == 0)
                        {
                            BASE_BomPartsLibrary library = new BASE_BomPartsLibrary();

                            library.CreateDate      = ServerTime.Time;
                            library.CreatePersonnel = personnel;
                            library.GoodsID         = item2.物品ID;
                            library.Material        = item2.材质;
                            library.PartType        = item2.零件类型;
                            library.PivotalPart     = item2.关键件;
                            library.Remark          = item2.备注;
                            library.Version         = item2.版次号;

                            dataContxt.BASE_BomPartsLibrary.InsertOnSubmit(library);
                        }

                        break;

                    case CE_OperatorMode.修改:

                        var varTemp2 = from a in dataContxt.BASE_BomPartsLibrary
                                       where a.GoodsID == item2.物品ID
                                       select a;

                        if (varTemp2 != null && varTemp2.Count() == 1)
                        {
                            BASE_BomPartsLibrary library1 = varTemp2.Single();

                            library1.CreateDate      = ServerTime.Time;
                            library1.CreatePersonnel = personnel;
                            library1.Material        = item2.材质;
                            library1.PartType        = item2.零件类型;
                            library1.PivotalPart     = item2.关键件;
                            library1.Remark          = item2.备注;
                            library1.Version         = item2.版次号;
                        }

                        break;

                    case CE_OperatorMode.除:

                        var varTemp3 = from a in dataContxt.BASE_BomPartsLibrary
                                       where a.GoodsID == item2.物品ID
                                       select a;

                        dataContxt.BASE_BomPartsLibrary.DeleteAllOnSubmit(varTemp3);

                        break;

                    default:
                        break;
                    }
                }

                dataContxt.SubmitChanges();

                #endregion

                #region 结构变更
                var varData = (from a in lstStruct
                               select new { a.父级图号, a.父级物品ID }).Distinct();

                foreach (var item in varData)
                {
                    var varTemp = from a in dataContxt.BASE_BomStruct
                                  where a.ParentID == item.父级物品ID
                                  select a;

                    decimal sysVersion = varTemp.Count() == 0 ? 0 : varTemp.Select(r => r.SysVersion).Distinct().ToList()[0];

                    dataContxt.BASE_BomStruct.DeleteAllOnSubmit(varTemp);
                    dataContxt.SubmitChanges();

                    var varTemp1 = from a in lstStruct
                                   where a.父级物品ID == item.父级物品ID
                                   select a;

                    foreach (var item1 in varTemp1)
                    {
                        if (item1.物品ID == null)
                        {
                            break;
                        }

                        BASE_BomStruct tempStruct = new BASE_BomStruct();

                        tempStruct.CreateDate      = ServerTime.Time;
                        tempStruct.CreatePersonnel = personnel;
                        tempStruct.GoodsID         = (int)item1.物品ID;
                        tempStruct.ParentID        = item1.父级物品ID;
                        tempStruct.Usage           = (decimal)item1.基数;
                        tempStruct.SysVersion      = sysVersion + (decimal)0.01;

                        dataContxt.BASE_BomStruct.InsertOnSubmit(tempStruct);
                    }
                }

                dataContxt.SubmitChanges();
                #endregion

                dataContxt.ExecuteCommand("exec BASE_DBOM_SaveSysVersion {0}", billNo);

                dataContxt.Transaction.Commit();
            }
            catch (Exception ex)
            {
                dataContxt.Transaction.Rollback();
                throw new Exception(ex.Message);
            }
        }