Advertisement
DrAungWinHtut

frmQdesign.cs

Mar 25th, 2022
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace Exam_System
  13. {
  14.     public partial class frmQdesign : Form
  15.     {
  16.         string sFname;
  17.         public frmQdesign()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void frmQdesign_FormClosing(object sender, FormClosingEventArgs e)
  23.         {
  24.             Application.Exit();
  25.         }
  26.  
  27.         private void btnExit_Click(object sender, EventArgs e)
  28.         {
  29.             Application.Exit();
  30.         }
  31.  
  32.         private void btnAdd_Click(object sender, EventArgs e)
  33.         {
  34.             if(txtFname .Text == String.Empty || txtQ .Text == String.Empty|| txtA1 .Text ==String .Empty ||txtA2 .Text ==string.Empty ||txtA3.Text == string.Empty || txtA4.Text ==string.Empty || txtCA .Text ==string.Empty )
  35.             {
  36.                 MessageBox.Show("Please Fill All data before adding ");
  37.                 return;
  38.             }
  39.  
  40.            
  41.             string sQ = txtQ.Text;
  42.             string sA1 = txtA1.Text;
  43.             string sA2 = txtA2.Text;
  44.             string sA3 = txtA3.Text;
  45.             string sA4 = txtA4.Text;
  46.             string sCA = txtCA.Text;
  47.  
  48.             string sQuestion = "N#" + sQ + "#" + sA1 + "#" + sA2 + "#" + sA3 + "#" + sA4 + "#" + sCA;
  49.  
  50.             string sPath = Path.GetDirectoryName(sFname);
  51.             if(!Directory.Exists(sPath))
  52.             {
  53.                 MessageBox.Show("Invalid Directory!");
  54.                 txtFname .SelectAll ();
  55.                 txtFname.Focus();
  56.             }
  57.             else
  58.             {
  59.                 if (!File.Exists(sFname))
  60.                 {
  61.                     File.Create(sFname).Dispose();
  62.                 }
  63.  
  64.                 using (StreamWriter sw = new StreamWriter(sFname, true))
  65.                 {
  66.                     sw.WriteLine(sQuestion);
  67.                 }
  68.                 MessageBox.Show("Adding New Question into the file " + sFname);
  69.                 txtQ.Clear();
  70.                 txtA1.Clear();
  71.                 txtA2.Clear();
  72.                 txtA3.Clear();
  73.                 txtA4.Clear();
  74.                 txtCA.Clear();
  75.                 txtQ.Focus();
  76.  
  77.             }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.         }
  84.  
  85.         private void btnBrowse_Click(object sender, EventArgs e)
  86.         {
  87.             if(sfdFname .ShowDialog() == DialogResult.OK)
  88.             {
  89.                 sFname = sfdFname .FileName;
  90.                 txtFname.Text = sFname;
  91.             }
  92.         }
  93.     }
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement