Click here to Skip to main content
15,881,852 members
Home / Discussions / C#
   

C#

 
SuggestionRe: How to split UTF16 stream Pin
Sascha Lefèvre5-Jun-15 2:57
professionalSascha Lefèvre5-Jun-15 2:57 
GeneralRe: How to split UTF16 stream Pin
Super Lloyd5-Jun-15 5:06
Super Lloyd5-Jun-15 5:06 
QuestionTCP Server Multiple Clients (Server Initiation Connection) Pin
MooKowMyke4-Jun-15 12:48
MooKowMyke4-Jun-15 12:48 
AnswerRe: TCP Server Multiple Clients (Server Initiation Connection) Pin
Richard Andrew x644-Jun-15 13:55
professionalRichard Andrew x644-Jun-15 13:55 
GeneralRe: TCP Server Multiple Clients (Server Initiation Connection) Pin
MooKowMyke9-Jun-15 9:04
MooKowMyke9-Jun-15 9:04 
QuestionHelp using EF with DB2 Pin
USAFHokie804-Jun-15 2:56
USAFHokie804-Jun-15 2:56 
AnswerRe: Help using EF with DB2 Pin
Richard MacCutchan4-Jun-15 4:29
mveRichard MacCutchan4-Jun-15 4:29 
QuestionC# Newbie. Need help on coding a errorcheck Pin
Setasigge4-Jun-15 2:24
Setasigge4-Jun-15 2:24 
So, I recently started working with c# without prior coding backround. I am now trying to write a program wich compiles a pdf of different textboxes that the user provides.

I have managed to code the program to check if the boxes are empty, but I am having a hard time trying to make a "ErrorState" if the box is empty.

So here is how it is supposed to go:

User enters text to fields -> Presses btnSave -> Program calls for a method that checks if textboxes are empty, If empty then put program to a "errorstate" and don't call for the next method that saves the pdf. Reset "errorstate" next time btnSave is pressed and check the textboxes again, if all is ok then continue with program.

My problem is getting the "errorstate" out of the method, I get a error: Use of unassigned local variable errorState with my current code. What am I missing, and how wrong Am I using methods? Big Grin | :-D

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using System.Text.RegularExpressions;

namespace CV_maker
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        //============================================================
        //GUI Handling, cheking that user has entered valid information
        //============================================================

        private bool ErrorCheck(bool errorState)

        //Check if txboxName, txtboxBday, txtboxAddres, txtboxPhone, txtboxEmail are empty
 
        {
            bool isError;

            if(txtboxName.Text.Trim().Length == 0)
            { MessageBox.Show("Anna nimesi!", "Seis!", MessageBoxButton.OK, MessageBoxImage.Error);
            isError = true;
            }

            if (txtboxBday.Text.Trim().Length == 0)
            { MessageBox.Show("Anna Syntymäaikasi", "Seis!", MessageBoxButton.OK, MessageBoxImage.Error);
            isError = true;
            }

            if (txtboxPhone.Text.Trim().Length == 0)
            { MessageBox.Show("Anna Puhelinnumerosi!", "Seis!", MessageBoxButton.OK, MessageBoxImage.Error);
            isError = true;
            }

            if (txtboxAddress.Text.Trim().Length == 0)
            { MessageBox.Show("Anna Osoitteesi", "Seis!", MessageBoxButton.OK, MessageBoxImage.Error);
            isError = true;
            }

            if (txtboxEmail.Text.Trim().Length == 0)
            { MessageBox.Show("Anna S-postisi!", "Seis!", MessageBoxButton.OK, MessageBoxImage.Error);
            isError = true;
            }

            else 
            {
                isError = false;
            }
            return isError;
        }


        //============================================================
        //GUI Handling. Calling up methods
        //============================================================


        //Image Button
        private void btnAddimage_Click(object sender, RoutedEventArgs e)
        {
            addImage();
        }

        //To PDF Button
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            bool ISOK;
            bool errorState;
            ISOK = ErrorCheck(errorState);
            if (ISOK == true)
            {
                MessageBox.Show("ERROR I WILL SHOW YOU THIS MESSAGE BEFORE REAL CODE");
            }

            //savepdf();
        }



        //============================================================
        //METHODS Called by GUI
        //===========================================================


        //ADD IMAGE BUTTON
        void addImage()
        {
            OpenFileDialog op = new OpenFileDialog();
            op.Title = "Select a picture";
            op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
              "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
              "Portable Network Graphic (*.png)|*.png";
            if (op.ShowDialog() == true)
            {
                PictureOmakuva.Source = new BitmapImage(new Uri(op.FileName));
            }
            return;
        }

        //Save PDF BUTTON
        void savepdf()

        {
            
                //VARIABLE DECLARATIONS

                string OwnName;

                //PULLING INFORMATION

                OwnName = txtboxName.Text;

                //SAVING THE PDF FILE
                FileStream fs = new FileStream(OwnName + " Curriculum Vitae.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
                Document doc = new Document();
                PdfWriter writer = PdfWriter.GetInstance(doc, fs);
                doc.Open();
                doc.Add(new iTextSharp.text.Paragraph("Tämä on testi"));
                doc.Close();
            
        }


    }
}

AnswerRe: C# Newbie. Need help on coding a errorcheck Pin
Eddy Vluggen4-Jun-15 2:59
professionalEddy Vluggen4-Jun-15 2:59 
AnswerRe: C# Newbie. Need help on coding a errorcheck Pin
Richard MacCutchan4-Jun-15 4:27
mveRichard MacCutchan4-Jun-15 4:27 
GeneralRe: C# Newbie. Need help on coding a errorcheck Pin
Setasigge4-Jun-15 21:04
Setasigge4-Jun-15 21:04 
GeneralRe: C# Newbie. Need help on coding a errorcheck Pin
Richard MacCutchan4-Jun-15 21:37
mveRichard MacCutchan4-Jun-15 21:37 
GeneralRe: C# Newbie. Need help on coding a errorcheck Pin
Setasigge4-Jun-15 22:01
Setasigge4-Jun-15 22:01 
GeneralRe: C# Newbie. Need help on coding a errorcheck Pin
Richard MacCutchan5-Jun-15 0:27
mveRichard MacCutchan5-Jun-15 0:27 
QuestionImplementing PocketSphinx in C# Pin
Member 105130663-Jun-15 21:14
Member 105130663-Jun-15 21:14 
AnswerREPOST Pin
Richard Deeming3-Jun-15 21:32
mveRichard Deeming3-Jun-15 21:32 
GeneralRe: REPOST Pin
Member 105130663-Jun-15 21:54
Member 105130663-Jun-15 21:54 
SuggestionRe: Implementing PocketSphinx in C# Pin
Richard MacCutchan3-Jun-15 21:35
mveRichard MacCutchan3-Jun-15 21:35 
AnswerRe: Implementing PocketSphinx in C# Pin
Simon_Whale3-Jun-15 22:25
Simon_Whale3-Jun-15 22:25 
AnswerRe: Implementing PocketSphinx in C# Pin
Pete O'Hanlon3-Jun-15 22:31
mvePete O'Hanlon3-Jun-15 22:31 
QuestionFresher problem for getting job in asp.net? Pin
Andyweil223-Jun-15 16:58
Andyweil223-Jun-15 16:58 
AnswerRe: Fresher problem for getting job in asp.net? Pin
Richard MacCutchan3-Jun-15 21:40
mveRichard MacCutchan3-Jun-15 21:40 
AnswerRe: Fresher problem for getting job in asp.net? Pin
OriginalGriff3-Jun-15 22:30
mveOriginalGriff3-Jun-15 22:30 
QuestionHow to not display the a row based on a condition. Pin
Norris Chappell3-Jun-15 14:39
Norris Chappell3-Jun-15 14:39 
AnswerRe: How to not display the a row based on a condition. Pin
PIEBALDconsult3-Jun-15 14:47
mvePIEBALDconsult3-Jun-15 14:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.