private void SaveNewLayout() { string filename = AppUtilities._fileName; if (string.IsNullOrEmpty(filename)) { return; } DataLayout dl = new DataLayout(); dl.isDefault = AppUtilities._isDefault; dl.layoutDate = DateTime.Now; dl.layoutName = filename; dl.layoutId = AppUtilities._layoutId; dl.filePathList = new List <string>(); try { foreach (var item in flowLayoutPanel1.Controls) { if (item is Button) { Button b = (Button)item; dl.filePathList.Add(b.Tag.ToString()); } } if (!XmlHelper.SaveLayout(dl)) { MessageBox.Show("New layout could not be created.", "New Layout", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Launcher_Load(object sender, EventArgs e) { if (!Directory.Exists(XmlHelper.basePath)) { Directory.CreateDirectory(XmlHelper.basePath); } if (SetDefault.Default.defaultPath != null) { if (File.Exists(SetDefault.Default.defaultPath)) { DataLayout dl = null; FileStream fileStream = new FileStream(SetDefault.Default.defaultPath, FileMode.Open); XmlSerializer xmlSerializer = new XmlSerializer(typeof(DataLayout)); dl = (DataLayout)xmlSerializer.Deserialize(fileStream); fileStream.Close(); currentLayout.Text = dl.layoutName; flowLayoutPanel1.Controls.Clear(); for (int i = 0; i < dl.filePathList.Count; i++) { Button b = new Button(); b.Text = Path.GetFileNameWithoutExtension(dl.filePathList[i]); b.FlatStyle = FlatStyle.Flat; b.FlatAppearance.BorderSize = 0; b.FlatAppearance.BorderColor = Color.FromKnownColor(KnownColor.Control); b.AutoSize = true; b.TextAlign = ContentAlignment.MiddleRight; b.ContextMenuStrip = bms; b.Height = 50; b.Width = 100; b.TextImageRelation = TextImageRelation.ImageBeforeText; b.Image = System.Drawing.Icon.ExtractAssociatedIcon(dl.filePathList[i]).ToBitmap(); b.Tag = dl.filePathList[i].ToString(); b.Click += B_Click; flowLayoutPanel1.Controls.Add(b); } } } }
private void loadLayoutToolStripMenuItem_Click(object sender, EventArgs e) { LayoutLoad ll = new LayoutLoad(); ll.ShowDialog(); if (string.IsNullOrEmpty(AppUtilities._loadName) || string.IsNullOrWhiteSpace(AppUtilities._loadName)) { return; } string filePath = Path.Combine(XmlHelper.basePath, AppUtilities._loadName + ".xml"); DataLayout dl = null; FileStream fileStream = new FileStream(filePath, FileMode.Open); XmlSerializer xmlSerializer = new XmlSerializer(typeof(DataLayout)); dl = (DataLayout)xmlSerializer.Deserialize(fileStream); flowLayoutPanel1.Controls.Clear(); fileStream.Close(); currentLayout.Text = AppUtilities._loadName; for (int i = 0; i < dl.filePathList.Count; i++) { Button b = new Button(); b.Text = Path.GetFileNameWithoutExtension(dl.filePathList[i]); b.FlatStyle = FlatStyle.Flat; b.FlatAppearance.BorderSize = 0; b.FlatAppearance.BorderColor = Color.FromKnownColor(KnownColor.Control); b.AutoSize = true; b.ContextMenuStrip = bms; b.Height = 50; b.Width = 100; b.TextImageRelation = TextImageRelation.ImageBeforeText; b.Image = System.Drawing.Icon.ExtractAssociatedIcon(dl.filePathList[i]).ToBitmap(); b.Tag = dl.filePathList[i].ToString(); b.Click += B_Click; flowLayoutPanel1.Controls.Add(b); } AppUtilities._loadName = string.Empty; }
private void btnSave_Click(object sender, EventArgs e) { List <string> pl = new List <string>(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (!dataGridView1.Rows[i].IsNewRow) { pl.Add(dataGridView1.Rows[i].Cells[1].Value.ToString()); } } DataLayout dd = new DataLayout() { basePath = dl.basePath, layoutId = dl.layoutId, isDefault = cbDefault.Checked, layoutDate = DateTime.Now, layoutName = txtlayoutName.Text, filePathList = pl }; if (XmlHelper.UpdateLayout(dl.layoutName, dd)) { MessageBox.Show("Success", "Updated", MessageBoxButtons.OK, MessageBoxIcon.Information); if (cbDefault.Checked) { SetDefault.Default.defaultPath = Path.Combine(XmlHelper.basePath, $"{txtlayoutName.Text}.xml"); SetDefault.Default.Save(); } (System.Windows.Forms.Application.OpenForms["LayoutDeleteOrUprdate"] as LayoutDeleteOrUprdate).LoadLayoutDatas(); } else { MessageBox.Show("Fail", "Updated", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public LayoutDetail(DataLayout ld) { dl = ld; InitializeComponent(); }