private void RestoreToList(TruckInfo entry) { ListViewItem lvi = new ListViewItem(); lvi.Text = 1.ToString(); ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.nrAuto; lvi.SubItems.Add(lvsi); lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.payload; lvi.SubItems.Add(lvsi); lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.dateRegistered.ToString("HH:mm:ss dd.MM.yyyy"); lvi.SubItems.Add(lvsi); if (entry.dateReturn != null && entry.dateReturn > DateTime.MinValue) { lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.dateReturn.ToString("HH:mm:ss dd.MM.yyyy"); lvi.SubItems.Add(lvsi); } lstTruckOrder.Items.Insert(0, lvi); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("EntryData")); }
private void AddSkipToFile(TruckInfo entry) { using (FixedObjectFileStream fos = new FixedObjectFileStream(skipFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, true)) { entry.nrCrt = fos.NumberOfObjects + 1; fos.Add(entry); } }
private void AddToList(TruckInfo entry) { ListViewItem lvi = new ListViewItem(); lvi.Text = entry.nrCrt.ToString(); ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.nrAuto; lvi.SubItems.Add(lvsi); lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.payload; lvi.SubItems.Add(lvsi); lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.dateRegistered.ToString("HH:mm:ss dd.MM.yyyy"); lvi.SubItems.Add(lvsi); if (entry.dateReturn != null && entry.dateReturn > DateTime.MinValue) { lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.dateReturn.ToString("HH:mm:ss dd.MM.yyyy"); lvi.SubItems.Add(lvsi); } lstTruckOrder.Items.Add(lvi); }
public static bool TryParse(Stream s, out TruckInfo result) { result = new TruckInfo(); try { result.ReadObject(s); return(true); } catch (Exception ex) { return(false); } }
private void LoadList(IList <TruckInfo> list, string filePath, Action <TruckInfo> callback) { if (File.Exists(filePath)) { using (FixedObjectFileStream stream = new FixedObjectFileStream(filePath, FileMode.Open, FileAccess.ReadWrite)) { for (int i = 0; i < stream.Length; i++) { TruckInfo ti = stream[i]; list.Add(ti); callback?.Invoke(ti); } } } }
private void AddEntryToCompleted(TruckInfo entry) { if (!File.Exists(completedFile)) { Stream s = File.Create(completedFile); s.Write(BitConverter.GetBytes(0), 0, 4); s.Close(); } using (FixedObjectFileStream stream = new FixedObjectFileStream(completedFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, true)) { entry.nrCrt = stream.NumberOfObjects + 1; stream.Add(entry); } }
private int Read(TruckInfo[] entries, int offset, int count) { int actualCount = offset; Seek(offset, SeekOrigin.Current); while (base.Position < base.Length && actualCount < count + offset) { byte[] buffer = new byte[TruckInfo.sizeInBytes]; base.Read(buffer, 0, TruckInfo.sizeInBytes); MemoryStream ms = new MemoryStream(buffer); entries[actualCount++] = new TruckInfo(ms); } return(actualCount - offset); }
private void AddToSkipList(TruckInfo entry) { ListViewItem lvi = new ListViewItem(); lvi.Text = entry.nrCrt.ToString(); ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.nrAuto; lvi.SubItems.Add(lvsi); lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.comments; lvi.SubItems.Add(lvsi); lstSkip.Items.Add(lvi); }
public static bool TryParse(string s, out TruckInfo result) { result = null; var itemProps = s.Split('|'); if (itemProps.Length == 4 || itemProps.Length == 5) { TruckInfo ti = new TruckInfo(); int nrcrt; if (int.TryParse(itemProps[0], out nrcrt)) { ti.nrCrt = nrcrt; } else { return(false); } ti.nrAuto = itemProps[1]; ti.payload = itemProps[2]; DateTime time; if (DateTime.TryParseExact(itemProps[3], "HH:mm:ss dd.MM.yyyy", new CultureInfo("ro-RO"), DateTimeStyles.None, out time)) { ti.dateRegistered = time; } else { return(false); } if (itemProps.Length == 5) { if (DateTime.TryParseExact(itemProps[4], "HH:mm:ss dd.MM.yyyy", new CultureInfo("ro-RO"), DateTimeStyles.None, out time)) { ti.dateEntry = time; } else { return(false); } } result = ti; return(true); } return(false); }
private void AddToList(TruckInfo entry) { ListViewItem lvi = new ListViewItem(); lvi.Text = entry.nrCrt.ToString(); ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.nrAuto; lvi.SubItems.Add(lvsi); lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.payload; lvi.SubItems.Add(lvsi); lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.dateRegistered.ToString("HH:mm dd.MM.yyyy"); lvi.SubItems.Add(lvsi); lstTruckOrder.Items.Add(lvi); }
private void AddEntryToFile(TruckInfo entry, bool first = false) { using (FixedObjectFileStream fos = new FixedObjectFileStream(dataFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, true)) { if (first) { fos.Insert(0, entry); for (int i = 1; i < fos.NumberOfObjects; i++) { var e = fos[i]; e.nrCrt++; fos[i] = e; } } else { fos.Add(entry); } } }
private void AddToSkipList(TruckInfo entry) { ListViewItem lvi = new ListViewItem(); lvi.Text = entry.nrCrt.ToString(); ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.nrAuto; lvi.SubItems.Add(lvsi); lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.comments; lvi.SubItems.Add(lvsi); if (entry.dateSkip != null && entry.dateSkip > DateTime.MinValue) { lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = entry.dateSkip.ToString("HH:mm:ss dd.MM.yyyy"); lvi.SubItems.Add(lvsi); } lstSkip.Items.Add(lvi); }
private void cmdAdd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtNrAuto.Text)) { MessageBox.Show("Numarul masinii nu poate fii gol!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtPayload.Text)) { MessageBox.Show("Va rugam alegeti marfa transportata!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } TruckInfo ti = new TruckInfo(); ti.nrCrt = AutoIncrementNrCrt; try { ti.nrAuto = txtNrAuto.Text; } catch (ArgumentException ex) { MessageBox.Show("Numarul masinii nu este in formatul corect!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } ti.payload = txtPayload.Text; ti.dateRegistered = dateRegister.Value; AddEntryToFile(ti); EntryData.Add(ti); AddToList(ti); AutoIncrementNrCrt++; txtNrAuto.Text = ""; txtNrAuto.Focus(); if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("EntryData")); } }
public void RemoveAt(int position) { int len; Seek(position + 1, SeekOrigin.Begin); TruckInfo[] buffer = new TruckInfo[10]; while ((len = Read(buffer, 0, 10)) > 0) { for (int i = 0; i < len; i++) { buffer[i].nrCrt--; } Seek(-len - 1, SeekOrigin.Current); Write(buffer, 0, len); Seek(1, SeekOrigin.Current); } SetLength(Length - 1); long pos = base.Position; base.Seek(0, SeekOrigin.Begin); base.Write(BitConverter.GetBytes(--numberOfObjects), 0, 4); base.Position = pos; }
public TruckInfo this[int pos] { get { if (pos >= Length) { throw new IndexOutOfRangeException(); } TruckInfo[] ret = new TruckInfo[1]; ret[0] = new TruckInfo(); Seek(pos, SeekOrigin.Begin); Read(ret, 0, 1); return(ret[0]); } set { TruckInfo[] set = new TruckInfo[1]; set[0] = value; if (pos > Length) { throw new ArgumentOutOfRangeException("You can only write to the first position after the end of file."); } Seek(pos, SeekOrigin.Begin); Write(set, 0, 1); if (pos == Length) { long poss = base.Position; base.Seek(0, SeekOrigin.Begin); base.Write(BitConverter.GetBytes(++numberOfObjects), 0, 4); base.Position = poss; } } }
public void Insert(int index, TruckInfo[] entries) { if (index > Length) { throw new IndexOutOfRangeException(); } var pos = base.Position; Seek(index, SeekOrigin.Begin); var cnt = (int)(Length - index); TruckInfo[] tis = new TruckInfo[cnt]; Read(tis, 0, cnt); Seek(index, SeekOrigin.Begin); Write(entries, 0, entries.Length); Write(tis, 0, cnt); base.Seek(0, SeekOrigin.Begin); numberOfObjects += entries.Length; base.Write(BitConverter.GetBytes(numberOfObjects), 0, 4); base.Position = pos; }
private void CreateRaport(DateTime rDate, string file) { if (!File.Exists(completedFile)) { MessageBox.Show("Fisierul in care se stocheaza istoricul intrarilor nu a fost gasit.\nDaca este prima folosire a aplicatiei si nu s-a folosit niciodata functia Urmatorul, totul este in regula.\nIn caz contrar anuntati administratorul.", "Nu s-a putut crea raportul", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } string dataRaport = rDate.ToString("dd.MM.yyyy"); FileInfo fileInfo = new FileInfo(file); fileInfo.Directory.Create(); Microsoft.Office.Interop.Excel.Application excelApp = null; _Workbook excelWb = null; try { excelApp = new Microsoft.Office.Interop.Excel.Application(); excelApp.DisplayAlerts = false; excelApp.Visible = false; excelApp.UserControl = false; excelWb = excelApp.Workbooks.Add(""); _Worksheet excelWs = excelWb.ActiveSheet; excelWs.Range[excelWs.Cells[1, 1], excelWs.Cells[1, 5]].Merge(); excelWs.Cells[1, 1] = "Raport pentru ziua: " + dataRaport; excelWs.Cells[3, 1] = "Nr. Crt."; AddBorder(excelWs.Cells[3, 1], XlBorderWeight.xlThick); excelWs.Cells[3, 2] = "Nr. Auto"; AddBorder(excelWs.Cells[3, 2], XlBorderWeight.xlThick); excelWs.Cells[3, 3] = "Marfa"; AddBorder(excelWs.Cells[3, 3], XlBorderWeight.xlThick); excelWs.Cells[3, 4] = "Data Inregistrare"; AddBorder(excelWs.Cells[3, 4], XlBorderWeight.xlThick); excelWs.Cells[3, 5] = "Data Intrare"; AddBorder(excelWs.Cells[3, 5], XlBorderWeight.xlThick); excelWs.Cells[3, 6] = "Data Sarit"; AddBorder(excelWs.Cells[3, 6], XlBorderWeight.xlThick); excelWs.Cells[3, 7] = "Data Intoarcere"; AddBorder(excelWs.Cells[3, 7], XlBorderWeight.xlThick); excelWs.Cells[3, 8] = "Comentarii"; AddBorder(excelWs.Cells[3, 8], XlBorderWeight.xlThick); int i = 1; using (FixedObjectFileStream stream = new FixedObjectFileStream(completedFile, FileMode.Open, FileAccess.ReadWrite)) { for (int j = 0; j < stream.Length; j++) { TruckInfo ti = stream[j]; if (ti.dateRegistered.ToString("dd.MM.yyyy") != dataRaport) { continue; } excelWs.Cells[3 + i, 1] = i; excelWs.Cells[3 + i, 2] = ti.nrAuto; excelWs.Cells[3 + i, 3] = ti.payload; excelWs.Cells[3 + i, 4] = ti.dateRegistered; excelWs.Cells[3 + i, 5] = ti.dateEntry; excelWs.Cells[3 + i, 6] = ti.dateSkip == DateTime.MinValue ? "" : ti.dateSkip.ToString("HH:mm:ss dd.MM.yyyy"); excelWs.Cells[3 + i, 7] = ti.dateReturn == DateTime.MinValue ? "" : ti.dateReturn.ToString("HH:mm:ss dd.MM.yyyy"); excelWs.Cells[3 + i, 8] = ti.comments; i++; } } if (i != 1) { AddBorder(excelWs.get_Range("A4", "H" + (i + 2)), XlBorderWeight.xlThin, true, true); } else { // Nu avem nimic de raportat. ABORT MessageBox.Show("Raportul pe data " + dataRaport + " este gol. Raportul nu a fost salvat.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); excelWb.Close(false, Type.Missing, Type.Missing); excelApp.Quit(); return; } Range r = excelWs.Range[excelWs.Cells[1, 1], excelWs.Cells[1, 6]]; r.EntireColumn.AutoFit(); r.HorizontalAlignment = XlHAlign.xlHAlignCenter; foreach (Range rr in r.Columns) { rr.ColumnWidth = rr.ColumnWidth + 2; } r = excelWs.get_Range("A3", "H" + (i + 2)); r.HorizontalAlignment = XlHAlign.xlHAlignCenter; excelWb.SaveAs(file, XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, false, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing); excelWb.Close(false, Type.Missing, Type.Missing); excelApp.Quit(); } catch (Exception ex) { MessageBox.Show("Salvarea raportului a esuat!\nMessage: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (excelWb != null) { excelWb.Close(false, Type.Missing, Type.Missing); } if (excelApp != null) { excelApp.Quit(); } } }
private void AddEntryToFile(TruckInfo entry, bool first = false) { using (FixedObjectFileStream fos = new FixedObjectFileStream(dataFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, true)) { if (first) { fos.Insert(0, entry); for (int i = 1; i < fos.NumberOfObjects; i++) { var e = fos[i]; e.nrCrt++; fos[i] = e; } } else fos.Add(entry); } }
public void Add(TruckInfo entry) => Add(new TruckInfo[] { entry });
private int Read(TruckInfo[] entries, int offset, int count) { int actualCount = offset; Seek(offset, SeekOrigin.Current); while (base.Position < base.Length && actualCount < count + offset) { byte[] buffer = new byte[TruckInfo.sizeInBytes]; base.Read(buffer, 0, TruckInfo.sizeInBytes); MemoryStream ms = new MemoryStream(buffer); entries[actualCount++] = new TruckInfo(ms); } return actualCount - offset; }
public static bool TryParse(string s, out TruckInfo result) { result = null; var itemProps = s.Split('|'); if (itemProps.Length == 4 || itemProps.Length == 5) { TruckInfo ti = new TruckInfo(); int nrcrt; if (int.TryParse(itemProps[0], out nrcrt)) { ti.nrCrt = nrcrt; } else { return false; } ti.nrAuto = itemProps[1]; ti.payload = itemProps[2]; DateTime time; if (DateTime.TryParseExact(itemProps[3], "HH:mm:ss dd.MM.yyyy", new CultureInfo("ro-RO"), DateTimeStyles.None, out time)) { ti.dateRegistered = time; } else { return false; } if (itemProps.Length == 5) { if (DateTime.TryParseExact(itemProps[4], "HH:mm:ss dd.MM.yyyy", new CultureInfo("ro-RO"), DateTimeStyles.None, out time)) { ti.dateEntry = time; } else { return false; } } result = ti; return true; } return false; }
public static bool TryParse(Stream s, out TruckInfo result) { result = new TruckInfo(); try { result.ReadObject(s); return true; } catch (Exception ex) { return false; } }
public TruckInfo this[int pos] { get { if (pos >= Length) throw new IndexOutOfRangeException(); TruckInfo[] ret = new TruckInfo[1]; ret[0] = new TruckInfo(); Seek(pos, SeekOrigin.Begin); Read(ret, 0, 1); return ret[0]; } set { TruckInfo[] set = new TruckInfo[1]; set[0] = value; if (pos > Length) throw new ArgumentOutOfRangeException("You can only write to the first position after the end of file."); Seek(pos, SeekOrigin.Begin); Write(set, 0, 1); if (pos == Length) { long poss = base.Position; base.Seek(0, SeekOrigin.Begin); base.Write(BitConverter.GetBytes(++numberOfObjects), 0, 4); base.Position = poss; } } }
public void Insert(int index, TruckInfo entry) => Insert(index, new[] { entry });
public void Insert(int index, TruckInfo[] entries) { if (index > Length) throw new IndexOutOfRangeException(); var pos = base.Position; Seek(index, SeekOrigin.Begin); var cnt = (int)(Length - index); TruckInfo[] tis = new TruckInfo[cnt]; Read(tis, 0, cnt); Seek(index, SeekOrigin.Begin); Write(entries, 0, entries.Length); Write(tis, 0, cnt); base.Seek(0, SeekOrigin.Begin); numberOfObjects += entries.Length; base.Write(BitConverter.GetBytes(numberOfObjects), 0, 4); base.Position = pos; }
public void Add(TruckInfo[] entries) { base.Seek(0, SeekOrigin.End); Write(entries, 0, entries.Length); long pos = base.Position; base.Seek(0, SeekOrigin.Begin); base.Write(BitConverter.GetBytes(numberOfObjects += entries.Length), 0, 4); base.Position = pos; }
private void Write(TruckInfo[] entries, int offset, int count) { int actualOffset = offset; byte[] buffer = new byte[TruckInfo.sizeInBytes]; MemoryStream ms = new MemoryStream(buffer); while (actualOffset < count + offset) { ms.Seek(0, SeekOrigin.Begin); entries[actualOffset++].WriteObject(ms); base.Write(buffer, 0, TruckInfo.sizeInBytes); } }