private void AddingButton_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(AddName.Text) && !string.IsNullOrWhiteSpace(AddDescription.Text) && !string.IsNullOrWhiteSpace(AddPrice.Text) && !string.IsNullOrWhiteSpace(AddQuantity.Text))
     {
         try
         {
             string InsertQuery = "insert into items(ITEM_NAME,ITEM_PRICE,ITEM_DESCRIPTION,ITEM_QUANTATY) VALUES('" + AddName.Text + "','" + int.Parse(AddPrice.Text) + "','" + AddDescription.Text + "'," + int.Parse(AddQuantity.Text) + ")";
             connection.Open();
             MySqlCommand cmd = new MySqlCommand(InsertQuery, connection);
             cmd.ExecuteNonQuery();
         }
         catch (MySqlException ex)
         {
             MessageBox.Show(ex.ToString());
         }
         finally
         {
             connection.Close();
             MessageBox.Show("Successfully Added", "Success");
             AddName.Clear();
             AddDescription.Clear();
             AddPrice.Clear();
             AddQuantity.Clear();
         }
     }
     else
     {
         MessageBox.Show("incorrect input", "ERROR");
     }
 }
 private async void AddPeople(object obj)
 {
     if (AddDateOfBirth == null || AddDateOfBirth.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddDateOfBirth");
     }
     else if (AddName == null || AddName.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddName");
     }
     else if (AddLastName == null || AddLastName.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddLastName");
     }
     else if (AddSurName == null || AddSurName.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddSurName");
     }
     else if (AddCity == null || AddCity.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddCity");
     }
     else if (AddCountry == null || AddCountry.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddCoutry");
     }
     else
     {
         using (IRepository <People> Repository = new PeopleRepository())
             PeopleCollection = await Repository.CreateObject(new People(DateTime.Parse(AddDateOfBirth).Date, AddName, AddLastName, AddSurName, AddCity, AddCountry));
         ClearAddedPeople();
     }
 }
Example #3
0
        public void SholuldRerurnName()
        {
            //given
            string name         = "Artur";
            string expectedName = "Pan Artur";
            var    doStuff      = new  AddName();

            //when
            string actualName = doStuff.GetName(name);

            //then
            Assert.Equal(expectedName, actualName);
        }
        static void Main(string[] args)
        {
            Program p = new Program();

            // create instance of delegates
            AddDelegate ad = new AddDelegate(Program.Add);
            AddName     an = new AddName(p.Name);
            AddJob      aj = new AddJob(Program.Job);// normal call also applicable , keeping Class Name by calling is optional

            // in case of static methods

            // now call the delegate , by pass the value so that the method which is bound with delegate internally should execute
            ad(100, 200);
            ad.Invoke(2000, 20200);
            an.Invoke("laxman");
            an("shukla");
            string s1 = aj("ved");
            string s  = aj.Invoke("praksh");

            Console.WriteLine(s1);
            Console.WriteLine(s);
            Console.WriteLine("Complete");
            Console.Read();
        }
        private void GameOver()
        {
            timer.Stop();
            stopwatch.Stop();

            //Show name input dialog
            AddName ad = new AddName();

            ad.ShowDialog();

            string name;

            //Check if any string entered
            if (ad.ResponseText.Length > 0)
            {
                name = ad.ResponseText.Trim();
            }
            else
            {
                name = "No name";
            }
            //Write to file
            highScoreIO.writeHighScore(new HighScore(name, score, (float)stopwatch.Elapsed.TotalSeconds));

            MessageBoxResult dialogResult = MessageBox.Show("You Lose! Score: " + score.ToString() + "\nTime: " + stopwatch.Elapsed.TotalSeconds.ToString("n2") + " secs" + "\nPlay again?", "Game Over", MessageBoxButton.YesNo, MessageBoxImage.Hand);

            //Check if want to continue
            if (dialogResult == MessageBoxResult.Yes)
            {
                Restart();
            }
            else if (dialogResult == MessageBoxResult.No)
            {
                this.Close();
            }
        }
Example #6
0
        private void RefreshEverything()
        {
            // ----- Refresh most of the fields on the three main tabs.
            string        sqlText;
            SqlConnection linkToDB;
            SqlDataReader stateReader;

            // ----- Initialize.
            ActiveStateID = -1L;

            // ----- Open a database connection.
            linkToDB = General.OpenConnection();
            if (linkToDB == null)
            {
                return;
            }

            // ----- See if a custom state already exists.
            sqlText     = "SELECT * FROM StateRegion WHERE RegionType = 99";
            stateReader = General.OpenReader(sqlText, linkToDB);
            if ((stateReader != null) && (stateReader.HasRows == true))
            {
                // ----- Existing custom state record.
                stateReader.Read();
                ActiveStateID = (long)(int)stateReader["ID"];

                AddName.Text         = (string)stateReader["FullName"];
                AddAbbreviation.Text = (string)stateReader["Abbreviation"];
            }
            else
            {
                // ----- No custom state record.
                AddName.Clear();
                AddAbbreviation.Clear();
            }
            if (stateReader != null)
            {
                stateReader.Close();
            }

            // ----- Adjust the display.
            if (ActiveStateID == -1L)
            {
                // ----- Set up the display for a new entry.
                AddName.Enabled         = true;
                AddAbbreviation.Enabled = true;
                ActAdd.Enabled          = true;

                EditID.Text = "N/A";
                EditName.Clear();
                EditAbbreviation.Clear();
                EditName.Enabled         = false;
                EditAbbreviation.Enabled = false;
                ActEdit.Enabled          = false;

                DeleteID.Text           = "N/A";
                DeleteName.Text         = "N/A";
                DeleteAbbreviation.Text = "N/A";
                ActDelete.Enabled       = false;
            }
            else
            {
                // ----- Set up the display for an existing item.
                AddName.Enabled         = false;
                AddAbbreviation.Enabled = false;
                ActAdd.Enabled          = false;

                EditID.Text              = ActiveStateID.ToString();
                EditName.Text            = AddName.Text;
                EditAbbreviation.Text    = AddAbbreviation.Text;
                EditName.Enabled         = true;
                EditAbbreviation.Enabled = true;
                ActEdit.Enabled          = true;

                DeleteID.Text           = ActiveStateID.ToString();
                DeleteName.Text         = AddName.Text;
                DeleteAbbreviation.Text = AddAbbreviation.Text;
                ActDelete.Enabled       = true;
            }

            // ----- Refresh the SQL statement previews.
            RefreshAddPreview();
            RefreshEditPreview();
            RefreshDeletePreview();
        }
Example #7
0
 private void Window_ContentRendered(object sender, EventArgs e)
 {
     AddName.SelectAll();
     AddName.Focus();
 }
Example #8
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     AddName.Focus();
 }
Example #9
0
        private void Button_Save_Click(object sender, EventArgs e) //변경적용 버튼
        {
            string OldPath;                                        //기존 경로
            string NewPath;                                        //옮길 경로
            string AddName;                                        //바꿀 이름
            int    fail_Count_exist      = 0;                      //변경적용 실패 카운트
            int    fail_Count_file       = 0;
            int    fail_Count_folder     = 0;
            int    fail_Count_Length     = 0;
            int    fail_Count_ZeroLength = 0;
            int    fail_Number_exist;
            int    fail_Number_file;
            int    fail_Number_folder;
            int    fail_Number_Length;
            int    fail_Number_ZeroLength;
            string fail_List_exist      = "";
            string fail_List_file       = "";
            string fail_List_folder     = "";
            string fail_List_Length     = "";
            string fail_List_ZeroLength = "";
            int    error_count          = 0;

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                ListViewItem item = listView1.Items[i];
                if (listView1.Items[i].SubItems[0].Text != listView1.Items[i].SubItems[1].Text)   //기존 파일명과 변경할 이름이 달라야 적용
                {
                    AddName = item.SubItems[1].Text;                                              //변경할 이름
                    OldPath = item.SubItems[2].Text;                                              //기존 경로
                    NewPath = (OldPath.Substring(0, OldPath.LastIndexOf("\\") + 1));
                    NewPath = NewPath + AddName;                                                  //변경할 경로(파일명 변경)

                    if (FileExistsCheck(OldPath) == false && FolderExistsCheck(OldPath) == false) //파일이 해당 경로에 없는 경우 에러 카운트
                    {
                        fail_Count_exist++;                                                       //해당 경로에 없는 목록 개수 기록
                        fail_Number_exist = i + 1;
                        if (fail_Count_exist > 1)                                                 //해당 경로에 없는 목록 순서 기록
                        {
                            fail_List_exist = fail_List_exist + ", " + fail_Number_exist.ToString();
                        }
                        else if (fail_Count_exist == 1)
                        {
                            fail_List_exist = fail_Number_exist.ToString();
                        }
                        else
                        {
                            error_count++;
                        }
                    }
                    else if (FileExistsCheck(NewPath) == true)//이미 해당 이름을 가진 파일이 존재할 경우
                    {
                        fail_Count_file++;
                        fail_Number_file = i + 1;
                        if (fail_Count_file > 1)
                        {
                            fail_List_file = fail_List_file + ", " + fail_Number_file.ToString();
                        }
                        else if (fail_Count_exist == 1)
                        {
                            fail_List_file = fail_Number_file.ToString();
                        }
                        else
                        {
                            error_count++;
                        }
                    }
                    else if (FolderExistsCheck(NewPath) == true)//이미 해당 이름을 가진 폴더가 존재할 경우
                    {
                        fail_Count_folder++;
                        fail_Number_folder = i + 1;
                        if (fail_Count_folder > 1)
                        {
                            fail_List_folder = fail_List_folder + ", " + fail_Number_folder.ToString();
                        }
                        else if (fail_Count_folder == 1)
                        {
                            fail_List_folder = fail_Number_folder.ToString();
                        }
                        else
                        {
                            error_count++;
                        }
                    }
                    else if (NewPath.Length >= 260)//이름 길이가 너무 길 경우
                    {
                        fail_Count_Length++;
                        fail_Number_Length = i + 1;
                        if (fail_Count_Length > 1)
                        {
                            fail_List_Length = fail_List_Length + ", " + fail_Number_Length.ToString();
                        }
                        else if (fail_Count_Length == 1)
                        {
                            fail_List_Length = fail_Number_Length.ToString();
                        }
                        else
                        {
                            error_count++;
                        }
                    }
                    //이름 길이가 너무 짧은 경우
                    else if (FolderExistsCheck(OldPath) == true ? AddName.Length == 0 : AddName.Contains(".") ? AddName.Substring(0, AddName.LastIndexOf(".")).Length == 0 : AddName.Length == 0)
                    {
                        fail_Count_ZeroLength++;
                        fail_Number_ZeroLength = i + 1;
                        if (fail_Count_ZeroLength > 1)
                        {
                            fail_List_ZeroLength = fail_List_ZeroLength + ", " + fail_Number_ZeroLength.ToString();
                        }
                        else if (fail_Count_ZeroLength == 1)
                        {
                            fail_List_ZeroLength = fail_Number_ZeroLength.ToString();
                        }
                        else
                        {
                            error_count++;
                        }
                    }
                    else if (FileExistsCheck(OldPath) == true)//파일 이름 변경
                    {
                        System.IO.File.Move(OldPath, NewPath);
                        item.SubItems[0].Text = AddName;
                        item.SubItems[2].Text = NewPath;
                    }
                    else if (FolderExistsCheck(OldPath) == true)//폴더 이름 변경
                    {
                        System.IO.Directory.Move(OldPath, NewPath);
                        item.SubItems[0].Text = AddName;
                        item.SubItems[2].Text = NewPath;
                    }
                    else
                    {
                        error_count += 100000;//예기치 못한 에러 체크
                    }
                }
            }
            if (fail_Count_exist > 0 && fail_Count_file > 0 && fail_Count_folder > 0)//파일명 변경 할 수 없는 목록 개수와 순서 알림
            {
                MessageBox.Show(fail_Count_exist + "개의 파일 또는 폴더가 존재하지 않습니다.\n" + fail_List_exist + "번째 항목이 변경되지 않았습니다.\n"
                                + fail_Count_file + "개의 중복된 파일명이 존재합니다.\n" + fail_List_file + "번째 항목이 변경되지 않았습니다.\n"
                                + fail_Count_folder + "개의 중복된 폴더명이 존재합니다.\n" + fail_List_folder + "번째 항목이 변경되지 않았습니다.");
            }
            else if (fail_Count_exist > 0 && fail_Count_file > 0)
            {
                MessageBox.Show(fail_Count_exist + "개의 파일 또는 폴더가 존재하지 않습니다.\n" + fail_List_exist + "번째 항목이 변경되지 않았습니다.\n"
                                + fail_Count_file + "개의 중복된 파일명이 존재합니다.\n" + fail_List_file + "번째 항목이 변경되지 않았습니다.");
            }
            else if (fail_Count_exist > 0 && fail_Count_folder > 0)
            {
                MessageBox.Show(fail_Count_exist + "개의 파일 또는 폴더가 존재하지 않습니다.\n" + fail_List_exist + "번째 항목이 변경되지 않았습니다.\n"
                                + fail_Count_folder + "개의 중복된 폴더명이 존재합니다.\n" + fail_List_folder + "번째 항목이 변경되지 않았습니다.");
            }
            else if (fail_Count_file > 0 && fail_Count_folder > 0)
            {
                MessageBox.Show(fail_Count_file + "개의 중복된 파일명이 존재합니다.\n" + fail_List_file + "번째 항목이 변경되지 않았습니다.\n"
                                + fail_Count_folder + "개의 중복된 폴더명이 존재합니다.\n" + fail_List_folder + "번째 항목이 변경되지 않았습니다.");
            }
            else if (fail_Count_exist > 0)
            {
                MessageBox.Show(fail_Count_exist + "개의 파일 또는 폴더가 존재하지 않습니다.\n" + fail_List_exist + "번째 항목이 변경되지 않았습니다.\n");
            }
            else if (fail_Count_file > 0)
            {
                MessageBox.Show(fail_Count_file + "개의 중복된 파일명이 존재합니다.\n" + fail_List_file + "번째 항목이 변경되지 않았습니다.\n");
            }
            else if (fail_Count_folder > 0)
            {
                MessageBox.Show(fail_Count_folder + "개의 중복된 폴더명이 존재합니다.\n" + fail_List_folder + "번째 항목이 변경되지 않았습니다.");
            }
            if (fail_Count_Length > 0)
            {
                MessageBox.Show(fail_Count_Length + "개의 항목 이름이 너무 깁니다.\n" + fail_List_Length + "번째 항목이 변경되지 않았습니다.");
            }
            if (fail_Count_ZeroLength > 0)
            {
                MessageBox.Show(fail_Count_ZeroLength + "개의 항목의 변경할 이름이 없습니다.\n" + fail_List_ZeroLength + "번째 항목이 변경되지 않았습니다.");
            }

            width_Resize();//너비 재조정
        }