public static void LoadGoodsComplects(DBModel db, long cm_base_rid) { var cmHdr = new CmHdrProc() { input = new CmHdrProcInputDS() { cm_base_rid = (int)cm_base_rid, date = DateTime.Now } }; cmHdr.Execute(); db.CmHdrAttrs.AddRange(cmHdr.cm_hdr_attr.Select(item => new CmHdrAttrsDB(item, cmHdr.input.cm_base_rid)) .Where(item => !db.CmHdrAttrs.Any(element => item.cm_hdr_rid == element.cm_hdr_rid && item.cm_base_rid == element.cm_base_rid))); db.CmHdrComplects.RemoveRange(db.CmHdrComplects.Where(item => item.cm_base_rid == cmHdr.input.cm_base_rid)); db.CmHdrComplects.AddRange(cmHdr.complects.Select(item => new CmHdrComplectsDB(item, cmHdr.input.cm_base_rid)) .Where(item => !db.CmHdrComplects.Any(element => item.cm_hdr_id == element.cm_hdr_id && item.cm_base_rid == element.cm_base_rid))); db.SaveChanges(); // Рекурсивно подгружаем Goods и их комплекты, если нужно foreach (var cmHdrComplect in db.CmHdrComplects.Where(item => item.cm_base_rid == cmHdr.input.cm_base_rid)) { LoadGoodBase(db, (uint)cmHdrComplect.cm_item_rid); if (cmHdrComplect.cm_item_options == 0) { LoadGoodsComplects(db, cmHdrComplect.cm_base_rid); } } }
public static void LoadCmHdrElements(DBModel db) { foreach (var CmBaseElement in db.CmBase.Where(item => !db.CmHdrAttrs.Any(CmHdrAttr => CmHdrAttr.cm_base_rid == item.cm_base_rid)).ToArray()) { var cmHdr = new CmHdrProc() { input = new CmHdrProcInputDS() { cm_base_rid = (int)CmBaseElement.cm_base_rid, date = DateTime.Now }, Encode = true }; cmHdr.Execute(); db.CmHdrAttrs.AddRange(cmHdr.cm_hdr_attr.Select(item => new CmHdrAttrsDB(item, cmHdr.input.cm_base_rid)) .Where(item => !db.CmHdrAttrs.Any(element => item.cm_hdr_rid == element.cm_hdr_rid && item.cm_base_rid == element.cm_base_rid))); //db.CmHdrComplects.RemoveRange(db.CmHdrComplects.Where(item => item.cm_hdr_id == cmHdr.input.cm_base_rid)); //db.CmHdrComplects.AddRange(cmHdr.complects.Select(item => new CmHdrComplectsDB(item, cmHdr.input.cm_base_rid)) // .Where(item => !db.CmHdrComplects.Any(element => item.cm_hdr_id == element.cm_hdr_id && item.cm_base_rid == element.cm_base_rid))); db.SaveChanges(); cmHdr.Dispose(); } }
public bool ExecuteProcess() { var settings = GetSettings(typeof(Settings.SHCMSettings)) as Settings.SHCMSettings; SHOLE.Execute.SHOLEConnector.CurrentConnector.Init(settings.SHServerAddress, settings.SHServerPort, settings.SHUserName, settings.SHPassword); var connected = SHOLE.Execute.SHOLEConnector.CurrentConnector.Connect(); //if (!connected) //{ // CreateLogRecord($"Can't connect to SH: {SHOLE.Execute.SHOLEConnector.CurrentConnector.LastError()}", System.Diagnostics.EventLogEntryType.Error); // return false; //} Database.SetInitializer(new DropCreateDatabaseIfModelChanges <DBModel>()); CreateLogRecord($"Export started"); var startTime = DateTime.Now; using (var db = new DBModel(settings.ConnectionString)) { if (settings.ReloadGoods) { var goodsTree = new GoodsTreeProc(); var error = goodsTree.Execute(); foreach (var goodsTreeElement in settings.SelectFirst == 0 ? goodsTree.result : goodsTree.result.Take(settings.SelectFirst)) { var goods = new GoodsProc() { input = new GoodsProcInputDS() { goodstree_rid = goodsTreeElement.goodstree_rid } }; goods.Execute(); db.GoodsAttrs.AddRange(goods.goodsAttrsDS.Select(item => new GoodsAttrsDB(item)) .Where(item => !db.GoodsAttrs.Any(element => item.goods_rid == element.goods_rid))); foreach (var good in goods.goodsAttrsDS) { var goodsBase = new GoodsBaseProc() { input = new GoodsBaseInputDS() { goods_rid = (int)good.goods_rid } }; goodsBase.Execute(); db.GoodsBaseAttrs.AddRange(goodsBase.goods_attr.Select(item => new GoodsBaseAttrsDB(item)) .Where(item => !db.GoodsBaseAttrs.Any(element => item.goods_rid == element.goods_rid))); db.GoodsBaseComplects.RemoveRange(db.GoodsBaseComplects.Where(item => item.goods_rid == (int)good.goods_rid)); db.GoodsBaseComplects.AddRange(goodsBase.complects.Select(item => new GoodsBaseComplectsDB(item, (int)good.goods_rid)) .Where(item => !db.GoodsBaseComplects.Any(element => item.cm_base_rid == element.cm_base_rid))); } db.SaveChanges(); } } CreateLogRecord($"GoodsBaseComplects count {db.GoodsBaseAttrs.Count()}"); if (settings.ReloadGoodsBaseComplects) { foreach (var goodsBase in db.GoodsBaseAttrs.Where(goodBase => goodBase.cm_base_rid != 0 && !db.CmHdrAttrs.Any(cmHDR => cmHDR.cm_base_rid == goodBase.cm_base_rid)).ToList()) { var cmHdr = new CmHdrProc() { input = new CmHdrProcInputDS() { cm_base_rid = (int)goodsBase.cm_base_rid, date = DateTime.Now } }; cmHdr.Execute(); db.CmHdrAttrs.AddRange(cmHdr.cm_hdr_attr.Select(item => new CmHdrAttrsDB(item, cmHdr.input.cm_base_rid)) .Where(item => !db.CmHdrAttrs.Any(element => item.cm_hdr_rid == element.cm_hdr_rid && item.cm_base_rid == element.cm_base_rid))); db.CmHdrComplects.RemoveRange(db.CmHdrComplects.Where(item => item.cm_base_rid == cmHdr.input.cm_base_rid)); db.CmHdrComplects.AddRange(cmHdr.complects.Select(item => new CmHdrComplectsDB(item, cmHdr.input.cm_base_rid)) .Where(item => !db.CmHdrComplects.Any(element => item.cm_hdr_id == element.cm_hdr_id && item.cm_base_rid == element.cm_base_rid))); db.SaveChanges(); } } CreateLogRecord($"CmHdrAttrs count {db.CmHdrAttrs.Count()}"); if (settings.ReloadComplectsHDR) { foreach (var CmHdrComplect in db.CmHdrComplects.ToList()) { if (CmHdrComplect.cm_item_options == 0 && !db.CmHdrAttrs.Any(element => element.cm_base_rid == CmHdrComplect.cm_comp_rid)) { var cmHdr = new CmHdrProc() { input = new CmHdrProcInputDS() { cm_base_rid = (int)CmHdrComplect.cm_comp_rid, date = DateTime.Now } }; cmHdr.Execute(); db.CmHdrAttrs.AddRange(cmHdr.cm_hdr_attr.Select(item => new CmHdrAttrsDB(item, cmHdr.input.cm_base_rid)) .Where(item => !db.CmHdrAttrs.Any(element => item.cm_hdr_rid == element.cm_hdr_rid && item.cm_base_rid == element.cm_base_rid))); db.CmHdrComplects.RemoveRange(db.CmHdrComplects.Where(item => item.cm_base_rid == cmHdr.input.cm_base_rid)); db.CmHdrComplects.AddRange(cmHdr.complects.Select(item => new CmHdrComplectsDB(item, cmHdr.input.cm_base_rid)) .Where(item => !db.CmHdrComplects.Any(element => item.cm_hdr_id == element.cm_hdr_id && item.cm_base_rid == element.cm_base_rid))); } } db.SaveChanges(); } CreateLogRecord($"CmHdrAttrs whith out cm list count {db.CmHdrAttrs.Where(cmHdr => !db.CmList.Any(cmList => cmList.cm_comp_rid == cmHdr.cm_base_rid)).Count()}"); if (settings.ReloadComplectsList) { foreach (var treeRid in db.CmHdrAttrs.Where(cmHdr => !db.CmList.Any(cmList => cmList.cm_comp_rid == cmHdr.cm_base_rid)).Select(item => item.cm_tree_parent_rid).Distinct().ToList()) { var cmList = new CmListProc() { input = new CmListProcInputDS() { cm_tree_rid = (int)treeRid, someParam1 = 0, startDate = DateTime.Now } }; cmList.Execute(); db.CmList.AddRange(cmList.output1.Select(item => new CmListDB(item)) .Where(item => !db.CmList.Any(element => item.cm_rid == element.cm_rid) && item.cm_date == 0)); db.SaveChanges(); } } } CreateLogRecord($"Export finished, it takes {(DateTime.Now - startTime).TotalMinutes} min"); SHOLE.Execute.SHOLEConnector.CurrentConnector.Disconnect(); return(true); }
static void Main(string[] args) { // args[0] - server address // args[1] - login // args[2] - password // args[3] - port SHOLEConnector.CurrentConnector.Init(args[0], (uint)Convert.ToInt16(args[3]), args[1], args[2]); SHOLEConnector.CurrentConnector.Connect(); var treeProcDS = new CmTreeProc(); var error = treeProcDS.Execute(); foreach (var element in treeProcDS.result.Take(3)) { Console.WriteLine($"TREE - name:{element.cm_tree_name} rid:{element.cm_tree_rid}"); var cmBaseProcDS = new CmBaseProc() { Input = new CmBaseProcInputDS() { cm_tree_rid = (int)element.cm_tree_rid } }; cmBaseProcDS.Execute(); foreach (var cmBaseElenent in cmBaseProcDS.result) { Console.WriteLine($" BASE - name:{cmBaseElenent.cm_base_name} createdate:{cmBaseElenent.cm_tree_rid} user:{cmBaseElenent.cm_base_createdate}"); Console.WriteLine($" BASE - abbr:{cmBaseElenent.cm_base_abbr} abbrnum:{cmBaseElenent.cm_base_abbrnumber}"); var hdrProcDS = new CmHdrProc() { input = new CmHdrProcInputDS() { cm_base_rid = (int)cmBaseElenent.cm_base_rid, date = DateTime.Now, someParam = 1 } }; hdrProcDS.Execute(); Console.WriteLine(" HDR attr:"); foreach (var cmElenent in hdrProcDS.cm_hdr_attr) { Console.WriteLine($" CMHDR - name:{cmElenent.cm_hdr_name} createdate:{cmElenent.cm_hdr_createdate} user:{cmElenent.cm_hdr_user}"); Console.WriteLine($" CMHDR - abbr_text:{cmElenent.cm_hdr_abbr_text} abbr_num:{cmElenent.cm_hdr_abbr_number}"); } Console.WriteLine(" HDR versions:"); foreach (var cmElenent in hdrProcDS.versions) { Console.WriteLine($" CMVERSION - rid:{cmElenent.cm_version_rid} datefrom:{cmElenent.cm_version_dateFrom} dateto:{cmElenent.cm_version_dateTo}"); } Console.WriteLine(" HDR complects:"); foreach (var cmElenent in hdrProcDS.complects) { Console.WriteLine($" CMCOMP - rid:{cmElenent.cm_comp_rid} name:{cmElenent.cm_comp_name} out:{cmElenent.cm_item_out}"); } } } var goodsTree = new GoodsTreeProc(); goodsTree.Execute(); foreach (var element in goodsTree.result.Take(3)) { Console.WriteLine($"GOODSTREE - name:{element.goodstree_name} rid:{element.goodstree_rid}"); var goods = new GoodsProc() { input = new GoodsProcInputDS() { goodstree_rid = (int)element.goodstree_rid } }; goods.Execute(); foreach (var goodsElement in goods.result) { Console.WriteLine($" GOODS - name:{goodsElement.goods_name} rid:{goodsElement.goods_rid}"); Console.WriteLine($" GOODS - abbr:{goodsElement.goods_abbrtext} abbrnum:{goodsElement.goods_abbrnumber}"); var goodsBase = new GoodsBaseProc() { input = new GoodsBaseInputDS() { goods_rid = (int)goodsElement.goods_rid } }; goodsBase.Execute(); foreach (var goodsBaseElement in goodsBase.complects) { Console.WriteLine($" COMPLECTS - name:{goodsBaseElement.cm_base_name} rid:{goodsBaseElement.cm_base_rid}"); } foreach (var goodsBaseElement in goodsBase.corr) { Console.WriteLine($" CORR - name:{goodsBaseElement.corr_base_name} rid:{goodsBaseElement.corr_base_rid}"); } foreach (var goodsBaseElement in goodsBase.clfr) { Console.WriteLine($" CLFR - name:{goodsBaseElement.clfr_name} rid:{goodsBaseElement.clfrval_rid}"); } foreach (var goodsBaseElement in goodsBase.complects_base) { Console.WriteLine($" COMPLECTSBASE - abbr:{goodsBaseElement.cm_base_abbrttext} rid:{goodsBaseElement.cm_base_rid}"); } foreach (var goodsBaseElement in goodsBase.units) { Console.WriteLine($" UNITS - name:{goodsBaseElement.goods_munit_name} rid:{goodsBaseElement.goods_munit_rid}"); } foreach (var goodsBaseElement in goodsBase.prices) { Console.WriteLine($" PRICES - attr_id:{goodsBaseElement.goods_attr_id} price:{goodsBaseElement.goods_price}"); } foreach (var goodsBaseElement in goodsBase.sunits_corr) { Console.WriteLine($" SUINTSCORR - name:{goodsBaseElement.corr_base_rid} rid:{goodsBaseElement.corr_base_name}"); } } } Console.ReadKey(); SHOLEConnector.CurrentConnector.Disconnect(); }