}//end:IsGcd /// <summary> /// Calculates statistics for given set of ets, /// which would be printed with given run /// </summary> protected static OutStats GetStatsForRun(Zakaz ets, int run) { OutStats result = new OutStats(); result.Run = run; foreach (Etyketka et in ets) { Etyketka tmpEt = new Etyketka(et); if (et.Run > run) { tmpEt.CountOnSheet = et.Run / run; //ex. 7/3=2 int remainder = et.Run % run; //Get the remainder if (remainder > 0) // "Round up" if there is some remainer { tmpEt.Overprint = run - remainder; tmpEt.CountOnSheet++; } } else { tmpEt.CountOnSheet = 1; tmpEt.Overprint = run - et.Run; } if (tmpEt.Overprint < 0) { throw new ArithmeticException("GetStatsForRun: something is wrong, negative Overprints detected!"); } result.Ets.Add(tmpEt); result.EtsOnSheetCount += tmpEt.CountOnSheet; result.OverprintsSum += tmpEt.Overprint; } //foreach return(result); } //end:GetEtsOnSheetForRun
public Etyketka(Etyketka et) { Id = et.Id; Name = et.Name; Run = et.Run; Overprint = et.Overprint; }
public static Zakaz LoadFile() { OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = "txt"; dlg.Filter = "текстові файли (*.txt)|*.txt|всі файли (*.*)|*.*"; dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (dlg.ShowDialog() == DialogResult.OK) { Zakaz result = new Zakaz(); StreamReader sr = new StreamReader(dlg.OpenFile(), Encoding.GetEncoding(1251)); int idCounter = 0; while (!sr.EndOfStream) { idCounter++; string ts = sr.ReadLine(); string rawRun; string etName; if (ts.Contains("\t") || ts.Contains(" ")) { int delimeter = ts.LastIndexOf("\t"); if (delimeter < ts.LastIndexOf(" ")) { delimeter = ts.LastIndexOf(" "); } rawRun = ts.Substring(delimeter); etName = ts.Substring(0, delimeter); } else { rawRun = ts; etName = "Et_" + ts; } int run = 0; try { run = int.Parse(rawRun); } catch (FormatException) { if (MessageBox.Show("Помилка у наданому текстовому файлі. Не можу прочитати наклад з текстового рядка: \n" + ts + "\nПродовжити читання файлу?", "Помилка", MessageBoxButtons.OKCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) == DialogResult.Cancel) { sr.Close(); return(null); } } Etyketka et = new Etyketka(idCounter, etName, run); result.Add(et); } sr.Close(); if (result.Count < 1) { return(null); } return(result); } return(null); }
}//end:GCD /// <summary> /// Determines if the baseEt is a GCD for the comparedEt /// </summary> protected static bool IsGcd(Etyketka baseEt, Etyketka comparedEt) { return(baseEt.Run <= comparedEt.Run && (comparedEt.Run / baseEt.Run) < Constants.ETS_ON_SHEET && GCD(baseEt.Run, comparedEt.Run) == baseEt.Run); }//end:IsGcd