Example #1
0
        private void SaveSettingBtn_Click(object sender, EventArgs e)
        {
            string errMsg = string.Empty;

            if (string.IsNullOrWhiteSpace(this.GenSettingNameTxt.Text))
            {
                MessageBox.Show(GenCodeToolResource.Error_NoSettingName, GenCodeToolResource.ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (GenCodeHandler.GenSettingPool.Count(s => this.GenSettingNameTxt.Text.Equals(s.SettingName)) > 0)
            {
                if (MessageBox.Show(GenCodeToolResource.Error_SameSettingName, GenCodeToolResource.ErrorTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            if (!string.IsNullOrEmpty(errMsg))
            {
                MessageBox.Show(GenCodeToolResource.SettingSaveFaild + System.Environment.NewLine + errMsg, GenCodeToolResource.ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            GenSetting genSetting = new GenSetting();
            genSetting.SettingName = this.GenSettingNameTxt.Text;
            genSetting.ConnectionString = this.ConnectionStringTxt.Text;
            genSetting.GenTargetPath = this.GenTargetFolderTxt.Text;
            genSetting.Namespace = this.NamespaceTxt.Text;
            genSetting.IsClearTargetFolder = this.IsClearTargetFolderChk.Checked;
            genSetting.ReferenceRootFolder = this.ReferenceFolderTxt.Text;
            genSetting.TemplatePath = CodeTemplateCbx.SelectedValue.ToString();
            genSetting.DBType = DBInfoGetterCbx.SelectedValue.ToString();
            genSetting.CodeType = CodeInfoGetterCbx.SelectedValue.ToString();

            try
            {
                GenCodeHandler.SaveGenSetting(genSetting);
                MessageBox.Show(GenCodeToolResource.SettingSaveSucc, GenCodeToolResource.InfoTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(GenCodeToolResource.SettingSaveFaild + System.Environment.NewLine + ex.Message, GenCodeToolResource.InfoTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// 保存生成配置
        /// </summary>
        /// <param name="genSetting">需要保存的配置对象</param>
        public static void SaveGenSetting(GenSetting genSetting)
        {
            string genSettingFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Config\");

            if (!Directory.Exists(genSettingFolderPath))
            {
                Directory.CreateDirectory(genSettingFolderPath);
            }

            string genSettingFilePath = Path.Combine(genSettingFolderPath, genSetting.SettingName + ".xml");
            string xmlStr = ObjectFactory.SerializeToXML<GenSetting>(genSetting);
            File.WriteAllText(genSettingFilePath, xmlStr, Encoding.UTF8);
        }
Example #3
0
        /// <summary>
        /// 加载配置信息
        /// </summary>
        /// <param name="genSetting">配置信息对象</param>
        private void LoadGenSetting(GenSetting genSetting)
        {
            if (genSetting == null)
            {
                return;
            }

            this.ConnectionStringTxt.Text = genSetting.ConnectionString;
            this.IsClearTargetFolderChk.Checked = genSetting.IsClearTargetFolder;
            this.NamespaceTxt.Text = genSetting.Namespace;
            this.GenTargetFolderTxt.Text = genSetting.GenTargetPath;
            this.ReferenceFolderTxt.Text = genSetting.ReferenceRootFolder;
            this.CodeTemplateCbx.SelectedItem = genSetting.TemplatePath;

            if (!string.IsNullOrEmpty(genSetting.DBType))
            {
                this.DBInfoGetterCbx.SelectedValue = genSetting.DBType;
            }

            if (!string.IsNullOrEmpty(genSetting.CodeType))
            {
                this.CodeInfoGetterCbx.SelectedValue = genSetting.CodeType;
            }
        }