123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- 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
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- 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<LocationModel.Item> m_items = new List<LocationModel.Item>();
- public SaveAsDialog(List<LocationModel.Item> 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<string> 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<LocationModel>(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();
- }
- }
- }
|