コード例 #1
0
        /// <summary>
        /// 自我介紹按鈕滑鼠偵聽事件:處理按下自我介紹按鈕後要做的事情
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void showIntroductionBtn_Click(object sender, EventArgs e)
        {
            IntroductionOBJ introductionOBJ = getIntroductionFromView();
            int             yearOld         = calculateYearOld(introductionOBJ.birthDate);

            string introductionText = string.Format(LanguageResources.Message_IntrouductionText, introductionOBJ.name, introductionOBJ.homeTown, yearOld);

            MessageBox.Show(introductionText);
        }
コード例 #2
0
ファイル: FileHelper.cs プロジェクト: ted59438/2019ITHome
        private static void writeToJson(IntroductionOBJ introductionOBJ)
        {
            JObject introductionJson = new JObject();

            introductionJson.Add("Name", introductionOBJ.name);
            introductionJson.Add("HomeTown", introductionOBJ.homeTown);
            introductionJson.Add("BirthDate", string.Format("{0}-{1}-{2}", introductionOBJ.birthDate.Year,
                                                            introductionOBJ.birthDate.Month,
                                                            introductionOBJ.birthDate.Day));

            File.WriteAllText(jsonPath, JsonConvert.SerializeObject(introductionJson));
        }
コード例 #3
0
 /// <summary>
 /// 按下「保存個人資訊」
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void saveBtn_Click(object sender, EventArgs e)
 {
     try
     {
         IntroductionOBJ introductionOBJ = getIntroductionFromView();
         FileHelper.processSave(introductionOBJ);
         MessageBox.Show("保存完成!", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception error)
     {
         MessageBox.Show(error.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #4
0
ファイル: FileHelper.cs プロジェクト: ted59438/2019ITHome
        /// <summary>
        /// 取得自我介紹資訊
        /// </summary>
        /// <param name="introductionJson"></param>
        /// <returns></returns>
        private static IntroductionOBJ getIntroductionJsonStr(JObject introductionJson)
        {
            IntroductionOBJ introductionOBJ = new IntroductionOBJ();

            introductionOBJ.name     = introductionJson["Name"].ToString();
            introductionOBJ.homeTown = introductionJson["HomeTown"].ToString();

            introductionOBJ.birthDate = new DateTime(int.Parse(introductionJson["BirthDate"].ToString().Split('-')[0]),
                                                     int.Parse(introductionJson["BirthDate"].ToString().Split('-')[1]),
                                                     int.Parse(introductionJson["BirthDate"].ToString().Split('-')[2]));

            return(introductionOBJ);
        }
コード例 #5
0
        /// <summary>
        /// 將自我介紹的資訊顯示到畫面上
        /// </summary>
        private void loadSaveIntroduction()
        {
            IntroductionOBJ introductionOBJ = FileHelper.processRead();

            nameTextBox.Text     = introductionOBJ.name;
            homeTownTextBox.Text = introductionOBJ.homeTown;

            birthdate_YearBox.Text  = introductionOBJ.birthDate.Year.ToString();
            birthdate_MonthBox.Text = introductionOBJ.birthDate.Month.ToString();
            birthdate_DayBox.Text   = introductionOBJ.birthDate.Day.ToString();

            if (introductionOBJ.photo != null)
            {
                photoBox.Image = PhotoHelper.bytesToImage(introductionOBJ.photo);
            }
        }
コード例 #6
0
        /// <summary>
        /// 從畫面上的所有欄位取得自我介紹資訊
        /// </summary>
        /// <returns></returns>
        private IntroductionOBJ getIntroductionFromView()
        {
            try
            {
                checkAllColumnIsNotEmpty();
                checkDateIsValidate();

                IntroductionOBJ introductionOBJ = new IntroductionOBJ();

                introductionOBJ.name      = nameTextBox.Text;
                introductionOBJ.homeTown  = homeTownTextBox.Text;
                introductionOBJ.birthDate = new DateTime(int.Parse(birthdate_YearBox.Text), int.Parse(birthdate_MonthBox.Text), int.Parse(birthdate_DayBox.Text));
                introductionOBJ.photo     = PhotoHelper.ImageToBytes(photoBox.Image);

                return(introductionOBJ);
            }
            catch (Exception error)
            {
                throw new Exception(error.Message);
            }
        }
コード例 #7
0
ファイル: FileHelper.cs プロジェクト: ted59438/2019ITHome
 /// <summary>
 /// 自我介紹 寫檔流程
 /// </summary>
 /// <param name="introductionOBJ"></param>
 public static void processSave(IntroductionOBJ introductionOBJ)
 {
     prepareWrite();
     writeToJson(introductionOBJ);
     saveImageToFile(introductionOBJ.photo);
 }