using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using PaintDotNet.Base.CommTool; using PaintDotNet.Base.SettingModel; namespace PaintDotNet.ImageCollect.ListOfLocation { public delegate void SaveHandler(string fileName); public class SaveAsDialog : Form { #region /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.txtName = new System.Windows.Forms.TextBox(); this.btnSave = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(61, 82); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(67, 15); this.label1.TabIndex = 0; // // txtName // this.txtName.Location = new System.Drawing.Point(143, 79); this.txtName.MaxLength = 20; this.txtName.Name = "txtName"; this.txtName.Size = new System.Drawing.Size(259, 25); this.txtName.TabIndex = 1; // // btnSave // this.btnSave.Location = new System.Drawing.Point(195, 163); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(88, 35); this.btnSave.TabIndex = 2; this.btnSave.UseVisualStyleBackColor = true; this.btnSave.Click += new System.EventHandler(this.btnSave_Click); // // SaveAsDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(482, 269); this.Controls.Add(this.btnSave); this.Controls.Add(this.txtName); this.Controls.Add(this.label1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "SaveAsDialog"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox txtName; private System.Windows.Forms.Button btnSave; #endregion public event SaveHandler Saved; private LocationModel m_locationModel; private List m_items = new List(); public SaveAsDialog(List items) { m_locationModel = new LocationModel(); m_items = items; InitializeComponent(); this.label1.Text = PdnResources.GetString("Menu.Saveaas.Text") + ":"; this.btnSave.Text = PdnResources.GetString("Menu.File.Save.Text"); this.Text = PdnResources.GetString("Menu.File.Save.Text"); } private void btnSave_Click(object sender, EventArgs e) { if(txtName.Text.Trim().Length == 0) { MessageBox.Show(PdnResources.GetString("Menu.Savenamecannobeempty.Text")); return; } string name = txtName.Text.Trim(); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Location\\"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } else { List files = FileOperationHelper.GetFileList(filePath); foreach (string fileName in files) { if (fileName.Equals(name) || fileName.Equals(name + ".xml")) { MessageBox.Show(PdnResources.GetString("Menu.Namealreadyexists.text")); return; } } } m_locationModel.items = m_items; string stageModelXml = XmlSerializeHelper.XmlSerialize(m_locationModel); filePath = filePath + name + ".xml"; if (!FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create)) { MessageBox.Show(PdnResources.GetString("Menu.Savefailed.text")); } else { if(Saved != null) { Saved(name); } } this.Close(); } } }