// Initiate sorting sequence, duration varies based on list size and min/max inputs WebSecurity.InitializeDatabaseConnection("Viewscape"); minWastage = Request.Form["minWastage"].AsInt(); while (minWastage ?= maxWastage){ listedCount = dbViewscape.QueryValue(""SELECT COUNT (*) FROM CutList"); int remainder = 0; // run first round iterations for single blinds foreach (var uc in dbViewscape.Query("SELECT * FROM LogCut WHERE listed=@0", false)){ bool active = dbViewscape.QueryValue("SELECT active FROM fabrics WHERE fabric=@0", uc.fabric); if(active == true){ int singleBlind = uc.maxFabWidth - minWastage; int cutWidth = blindWidth - deduction; if (cutWidth ? singleBlind){ listCount++; // check which drop this blind fits into foreach (var dv in dbViewscape.Query("SELECT * FROM DropValues")){ if (blindDrop ?= dv.dropValue){ logDrop = dv.dropValue; break; } } remainder = uc.maxFabWidth - cutWidth; // create log to cut dbViewscape.Execute("INSERT INTO LogRolls (fabric, colour, tubeSize, rollType, dropp, tape1, maxWidth, dateAdded) VALUES (@0, @1, @2, @3, @4, @5, @6, @7)", uc.fabric, colour, tubeSize, uc.rollType, logDrop, cutWidth, maxRollLength, DateTime.Now); var logId = dbViewscape.QueryValue("SELECT TOP 1 id FROM LogRolls ORDER BY id DESC"); dbViewscape.Execute("INSERT INTO CutList (id, orderNo, width, dropp, roundedDrop, fabric, colour, tubeSize, grouping, rollType, lineNumber) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10)", uc.id, uc.orderNo, cutWidth, blindDrop, logDrop, fabric, colour, tubeSize, logId, uc.rollType, uc.lineNo); string reportString = fabric + "-" + colour + " (blind width: " + blindWidth + "mm) cut: " + cutWidth + " offcut: " + remainder; } } else{ dbViewscape.Execute("INSERT INTO Logger (info, theTime) VALUES (@0, @1)", uc.fabric + " was skipped (not active on fabric list)", DateTime.Now); } } minWastage += increment; } // match any 2 blinds together ////// foreach (var fp in dbViewscape.Query("SELECT * FROM LogCut WHERE listed=@0", false)){ int upperLogValue = 0; bool usedUpperLog = false; bool active = dbViewscape.QueryValue("SELECT active FROM fabrics WHERE fabric=@0", fp.fabric); if (active){ int cutWidth = blindWidth - deduction; // check if blind is already in cutlist bool blindCheck = false; foreach (var bc in idsTaken){ if (fp.id == bc){ blindCheck = true; break; // skip this loop coz blind is already on cutlist } } if (!blindCheck){ foreach (var sp in dbViewscape.Query("SELECT * FROM LogCut WHERE fabric=@0 AND colour=@1 AND tubeSize=@2 AND listed=@3", fp.fabric, fp.colour, fp.tubeSize, false)){ int blindWidth2 = sp.width; int cutWidth2 = blindWidth2 - deduction; if (sp.id != fp.id){ blindCheck = false; bool reverseCheck = true; if (fp.rollType != sp.rollType & !sp.reversible){ reverseCheck = false; } if (!blindCheck & reverseCheck){ reportString = ""; // see what the drop will fit into with any matching int logDropM = 0; int logDropU = 0; foreach (var dv in dbViewscape.Query("SELECT * FROM DropValues")){ if (sp.dropp ?= dv.dropValue) { logDropM = dv.dropValue; if(logDropM != 2900) { logDropU = dbViewscape.QueryValue("SELECT dropValue FROM DropValues WHERE id=@0", dv.id + 1); } break; } } // get lengths of 2 comparing blinds int bothLengths = cutWidth + cutWidth2; // if both blinds can fit in one log AND drops in same range (matching drops) if (bothLengths < maxRollLength & logDrop == logDropM) { remainder = maxRollLength - bothLengths; if (remainder < minWastage && remainder > 0) { // create a log to cut int tape2 = cutWidth + cutWidth2; dbViewscape.Execute("INSERT INTO LogRolls (fabric, colour, tubeSize, rollType, dropp, tape1, tape2, maxWidth) VALUES (@0, @1, @2, @3, @4, @5, @6, @7)", fabric, fp.colour, fp.tubeSize, fp.rollType, logDropM, cutWidth, tape2, maxRollLength);
