public void PostStyleToPo(int iserial, int salesOrder, bool postPo, int tblAuthUser, out decimal?tempprice, out float?tempCost) { tempprice = 0; tempCost = 0; using (var context = new WorkFlowManagerDBEntities()) { var poiserial = 0; var style = context.TblStyles.Include("TblStyleCategory1") .Include("TblLkpBrandSection1.TblLkpBrandSectionLinks") .Include("TblLkpSeason1") .Include("TblStyleStatu") .Include("TblSizeGroup1.TblSizes") .Include("tbl_lkp_FabricDesignes1") .Include("TblLkpDirection1") .Include("TblSupplierFabric1") .Include("TblFamily1") .Include("TblSubFamily1") .FirstOrDefault(x => x.Iserial == iserial); var brandSectionLink = context.TblLkpBrandSectionLinks.FirstOrDefault( x => x.TblBrand == style.Brand && x.TblLkpBrandSection == style.TblLkpBrandSection); var SalesOrder = context.TblSalesOrders.Include("TblSalesOrderColors.Tblcolor1") .Include("TblSalesOrderColors.TblSalesOrderColorTheme1").Include("TblSalesOrderColors.TblSalesOrderSizeRatios") .FirstOrDefault(x => x.Iserial == salesOrder); var group5 = FindOrCreate("TblGroup5", new GenericTable { Iserial = 0, Aname = style.TblLkpDirection1.Aname, Code = style.TblLkpDirection1.Code, Ename = style.TblLkpDirection1.Ename }); var fabricAtt = context.tbl_FabricAttriputes.FirstOrDefault(x => x.Iserial == style.tbl_FabricAttriputes); var group2 = FindOrCreate("TblGroup2", new GenericTable { Iserial = 0, Aname = fabricAtt.FabricID, Code = fabricAtt.FabricID, Ename = fabricAtt.FabricID }); var group3 = FindOrCreate("TblGroup3", new GenericTable { Iserial = 0, Aname = style.tbl_lkp_FabricDesignes1.Aname, Code = style.tbl_lkp_FabricDesignes1.Code, Ename = style.tbl_lkp_FabricDesignes1.Ename }); var group4 = FindOrCreate("TblGroup4", new GenericTable { Iserial = 0, Aname = style.TblLkpSeason1.Aname, Code = style.TblLkpSeason1.Code, Ename = style.TblLkpSeason1.Ename }); var group8 = 0; if (style.TblStyleCategory1 != null) { group8 = FindOrCreate("TblGroup8", new GenericTable { Iserial = 0, Aname = style.TblStyleCategory1.Aname, Code = style.TblStyleCategory1.Code, Ename = style.TblStyleCategory1.Ename }); } var brand = context.Brands.FirstOrDefault(x => x.Brand_Code == style.Brand); var class4 = CreateClasses(brand, style.TblLkpBrandSection1, style.TblFamily1, style.TblSubFamily1); var sizeGroup = FindOrCreate("tblsizegroup", new GenericTable { Iserial = 0, Aname = style.TblSizeGroup1.Aname, Code = style.TblSizeGroup1.Code, Ename = style.TblSizeGroup1.Ename }); using (var ccnewcontext = new ccnewEntities()) { foreach (var color in SalesOrder.TblSalesOrderColors) { try { var retailcolor = FindOrCreate("tblcolor", new GenericTable { Iserial = 0, Aname = color.TblColor1.Aname, Code = color.TblColor1.Code, Ename = color.TblColor1.Ename }); var tblitemdownloadDef = ccnewcontext.TblItemDownLoadDefs.FirstOrDefault( x => x.Code == brandSectionLink.TblItemDownLoadDef); var tblstylecolorgroup1 = ccnewcontext.TblStyleColorGroup1.FirstOrDefault( x => x.ISERIAL == color.TblSalesOrderColorTheme); if (tblstylecolorgroup1 == null) { tblstylecolorgroup1 = new TblStyleColorGroup1 { ISERIAL = color.TblSalesOrderColorTheme1.Iserial, CODE = color.TblSalesOrderColorTheme1.Code, ANAME = color.TblSalesOrderColorTheme1.Aname, ENAME = color.TblSalesOrderColorTheme1.Ename, TblGroup4 = group4, TblItemDownloadDef = tblitemdownloadDef.iserial, }; ccnewcontext.TblStyleColorGroup1.AddObject(tblstylecolorgroup1); ccnewcontext.SaveChanges(); } else { tblstylecolorgroup1.CODE = color.TblSalesOrderColorTheme1.Code; tblstylecolorgroup1.ANAME = color.TblSalesOrderColorTheme1.Aname; tblstylecolorgroup1.ENAME = color.TblSalesOrderColorTheme1.Ename; ccnewcontext.SaveChanges(); } var tblStyleColorGroupLinks = ccnewcontext.TblStyleColorGroupLinks.FirstOrDefault(x => x.Style == style.RefStyleCode && x.TblColor == retailcolor); if (tblStyleColorGroupLinks == null) { tblStyleColorGroupLinks = new TblStyleColorGroupLink { Style = style.RefStyleCode, TblColor = retailcolor, TblStyleColorGroup1 = tblstylecolorgroup1.ISERIAL, Notes = color.Notes }; ccnewcontext.TblStyleColorGroupLinks.AddObject(tblStyleColorGroupLinks); ccnewcontext.SaveChanges(); } else { tblStyleColorGroupLinks.TblStyleColorGroup1 = tblstylecolorgroup1.ISERIAL; ccnewcontext.SaveChanges(); } } catch (Exception ex) { throw new Exception(ex.Message); } } var subSeasonRow = ccnewcontext.TblSubSeasons.FirstOrDefault(x => x.Code == style.TblLkpSeason1.Code); var seasonRow = ccnewcontext.TblSeasons.FirstOrDefault(x => x.Code == style.TblLkpSeason1.ShortCode); if (subSeasonRow == null) { subSeasonRow = new TblSubSeason { Iserial = GetMaxIserial("TblSubSeason"), Code = style.TblLkpSeason1.Code, Ename = style.TblLkpSeason1.Ename, Aname = style.TblLkpSeason1.Aname, TblSeason = seasonRow.ISerial, }; ccnewcontext.TblSubSeasons.AddObject(subSeasonRow); ccnewcontext.SaveChanges(); } var retailbrand = ccnewcontext.TblItemDownLoadDefs.FirstOrDefault( x => x.Code == brandSectionLink.TblItemDownLoadDef); if (postPo) { poiserial = PostRetailPo(SalesOrder, (int)brandSectionLink.RetailWarehouse); } var dserial = 0; foreach (var size in style.TblSizeGroup1.TblSizes.OrderBy(x => x.Id)) { var Size = FindOrCreate("tblsize", new GenericTable { Iserial = 0, Aname = size.SizeCode, Code = size.SizeCode, Ename = size.SizeCode }); var sizeLink = ccnewcontext.TblSizeLinks.FirstOrDefault( x => x.TblSize1.Code == size.SizeCode && x.TblSizeGroup == sizeGroup); if (sizeLink == null) { sizeLink = new TblSizeLink { TblSize = Size, TblSizeGroup = sizeGroup, iserial = size.Id }; ccnewcontext.TblSizeLinks.AddObject(sizeLink); ccnewcontext.SaveChanges(); } foreach (var color in SalesOrder.TblSalesOrderColors) { var transactionexist = false; dserial++; var retailcolor = ccnewcontext.TblColorTests.FirstOrDefault(q => q.Code == color.TblColor1.Code); var styleIserial = CreateRetailStyle(tblAuthUser, style, size, color.TblColor1, group2, group3, group4, group5, group8, class4, (int)SalesOrder.TblSupplier, retailcolor.ISERIAL, sizeLink.TblSize, sizeLink.TblSizeGroup, seasonRow.ISerial, retailbrand.iserial, subSeasonRow.Iserial.ToString(), postPo, color, out tempprice, out tempCost, out transactionexist); var salesOrderSize = color.TblSalesOrderSizeRatios.FirstOrDefault(x => x.Size == size.SizeCode); if (postPo) { if (salesOrderSize != null) { PostRetailPoDetail(style, SalesOrder, retailbrand.iserial, styleIserial, salesOrderSize, poiserial, dserial, color.DeliveryDate, color); } } } } } if (postPo) { using (var ccnewcontext = new ccnewEntities()) { var testingSelect = ccnewcontext.TBLITEMprices.FirstOrDefault(x => x.Style == style.StyleCode); if (testingSelect == null) { throw new FaultException("Something Wrong Please Contact The Administrator"); } var poheaderRow = ccnewcontext.TblPO1Header.FirstOrDefault(x => x.glserial == poiserial); poheaderRow.creationdate = DateTime.Now; ccnewcontext.SaveChanges(); var body = "Order Code :" + SalesOrder.SalesOrderCode; var subject = SalesOrder.SalesOrderCode; try { SendMailReportPo("Po", subject, body, tblAuthUser, SalesOrder); } catch (Exception) { } } } context.SaveChanges(); } }
private TblSalesOrderColor UpdateOrInsertTblSalesOrderColor(TblSalesOrderColor newRow, bool save, int index, out int outindex) { outindex = index; using (var context = new WorkFlowManagerDBEntities()) { if (save) { context.TblSalesOrderColors.AddObject(newRow); // var SalesOrder= context.TblSalesOrders.FirstOrDefault(x => x.Iserial == newRow.TblSalesOrder); // var PaymentScheduleDetail = context.TblPaymentScheduleDetails.Where(x => x.tbl.TblPaymentSchedule == SalesOrder.TblPaymentSchedule); } else { var oldRow = (from e in context.TblSalesOrderColors.Include("TblColor1").Include("TblSalesOrder1").Include("TblSalesOrder1.TblStyle1.TblLkpSeason1") where e.Iserial == newRow.Iserial select e).SingleOrDefault(); if (oldRow != null) { GenericUpdate(oldRow, newRow, context); foreach (var row in newRow.TblSalesOrderSizeRatios.ToList()) { var oldColorRow = (from e in context.TblSalesOrderSizeRatios where e.Iserial == row.Iserial || (e.Size == row.Size && e.TblSalesOrderColor == row.TblSalesOrderColor) select e).SingleOrDefault(); if (oldColorRow != null) { row.TblSalesOrderColor = newRow.Iserial; row.TblSalesOrderColor1 = null; GenericUpdate(oldColorRow, row, context); if (oldRow.TblSalesOrder1.Status == 1 && oldRow.TblSalesOrder1.SalesOrderType == 1) { var group4 = FindOrCreate("TblGroup4", new GenericTable { Iserial = 0, Aname = oldRow.TblSalesOrder1.TblStyle1.TblLkpSeason1.Aname, Code = oldRow.TblSalesOrder1.TblStyle1.TblLkpSeason1.Code, Ename = oldRow.TblSalesOrder1.TblStyle1.TblLkpSeason1.Ename }); using (var ccnewcontext = new ccnewEntities()) { var brandSectionLink = context.TblLkpBrandSectionLinks.FirstOrDefault(x => x.TblBrand == oldRow.TblSalesOrder1.TblStyle1.Brand && x.TblLkpBrandSection == oldRow.TblSalesOrder1.TblStyle1.TblLkpBrandSection); var tblitemdownloadDef = ccnewcontext.TblItemDownLoadDefs.FirstOrDefault( x => x.Code == brandSectionLink.TblItemDownLoadDef); var salesordertheme = context.TblSalesOrderColorThemes.FirstOrDefault( x => x.Iserial == newRow.TblSalesOrderColorTheme); var tblstylecolorgroup1 = ccnewcontext.TblStyleColorGroup1.FirstOrDefault( x => x.CODE == salesordertheme.Code && x.TblGroup4 == group4 && tblitemdownloadDef.iserial == x.TblItemDownloadDef); if (tblstylecolorgroup1 == null) { tblstylecolorgroup1 = new TblStyleColorGroup1 { ISERIAL = salesordertheme.Iserial, CODE = salesordertheme.Code, ANAME = salesordertheme.Aname, ENAME = salesordertheme.Ename, TblGroup4 = group4, TblItemDownloadDef = tblitemdownloadDef.iserial, }; ccnewcontext.TblStyleColorGroup1.AddObject(tblstylecolorgroup1); ccnewcontext.SaveChanges(); } var retailcolor = FindOrCreate("tblcolor", new GenericTable { Iserial = 0, Aname = oldRow.TblColor1.Aname, Code = oldRow.TblColor1.Code, Ename = oldRow.TblColor1.Ename }); var tblStyleColorGroupLinks = ccnewcontext.TblStyleColorGroupLinks.FirstOrDefault(x => x.Style == oldRow.TblSalesOrder1.TblStyle1.RefStyleCode && x.TblColor == retailcolor); if (tblStyleColorGroupLinks == null) { tblStyleColorGroupLinks = new TblStyleColorGroupLink { Style = oldRow.TblSalesOrder1.TblStyle1.RefStyleCode, TblColor = retailcolor, TblStyleColorGroup1 = tblstylecolorgroup1.ISERIAL, Notes = newRow.Notes }; ccnewcontext.TblStyleColorGroupLinks.AddObject(tblStyleColorGroupLinks); ccnewcontext.SaveChanges(); } else { tblStyleColorGroupLinks.TblStyleColorGroup1 = tblstylecolorgroup1.ISERIAL; tblStyleColorGroupLinks.Notes = newRow.Notes; } ccnewcontext.SaveChanges(); } } } else { row.TblSalesOrderColor = newRow.Iserial; row.TblSalesOrderColor1 = null; context.TblSalesOrderSizeRatios.AddObject(row); } } } } context.SaveChanges(); return(newRow); } }