private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtKey.Text)) { MessageBox.Show("Key is required."); return; } if (CURRENT_VIEW_ID != 0) { Dictionary dict = new Dictionary(); dict.ID = CURRENT_VIEW_ID; dict.KEY = txtKey.Text; dict.KEY_ALT = MegaDict.Utility.App.ConvertToAscii(dict.KEY); dict.CONTENT = txtView.Text; dict.CONTENT_ALT = MegaDict.Utility.App.ConvertToAscii(dict.CONTENT); dict.ATTACH_FILE_PATH = CopyFileToData(txtFilePath.Text); if (DictionaryAccess.Update(dict)) { //copy file to data folder if (!string.IsNullOrEmpty(txtFilePath.Text)) { AllowModify(false); } } else { MessageBox.Show("Insert error."); } } else { DlgCategorySelector dlg = new DlgCategorySelector(); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Dictionary dict = new Dictionary(); dict.CATEGORY_ID = dlg.CategoryID; dict.KEY = txtKey.Text; dict.KEY_ALT = MegaDict.Utility.App.ConvertToAscii(dict.KEY); dict.CONTENT = txtView.Text; dict.CONTENT_ALT = MegaDict.Utility.App.ConvertToAscii(dict.CONTENT); dict.ATTACH_FILE_PATH = CopyFileToData(txtFilePath.Text); if (DictionaryAccess.Insert(dict)) { MessageBox.Show("Save succeed."); //txtView.Text = txtKey.Text = string.Empty; //AllowModify(true); //CURRENT_VIEW_ID = 0; } else { MessageBox.Show("Insert error."); } } } AllowModify(false); }
private void btnImport_Click(object sender, EventArgs e) { DlgCategorySelector dlg = new DlgCategorySelector(); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Cursor = Cursors.WaitCursor; btnImport.Enabled = false; Dictionary dict = new Dictionary(); dict.CATEGORY_ID = dlg.CategoryID; foreach (string item in lsbResult.Items) { string[] data = item.Split(new string[] { "~~" }, StringSplitOptions.RemoveEmptyEntries); if (data.Length == 2) { string key = data[0]; string key_alt = MegaDict.Utility.App.ConvertToAscii(key); string content = data[1]; string content_alt = MegaDict.Utility.App.ConvertToAscii(content); dict.KEY = key; dict.KEY_ALT = key_alt; dict.CONTENT = content.Replace("`", "\r\n"); dict.CONTENT_ALT = content_alt; if (DictionaryAccess.Insert(dict)) { Console.WriteLine(string.Format("Đã thêm: {0}", key)); } else { Console.WriteLine(string.Format("Thêm: {0} thất bại.", key)); } } } Cursor = Cursors.Default; MessageBox.Show("Đã thêm hoàn tất."); btnImport.Enabled = true; } }