Exemple #1
0
        public static bool CheckTheRecord(RecordObj record)
        {
            MySqlConnection conn = null;

            try
            {
                conn = GetSqlConnection();
                MySqlCommand cmd = new MySqlCommand("SELECT * FROM cscalculator WHERE Expression = @Expression", conn);
                cmd.Parameters.AddWithValue("@Expression", record.Infix);

                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    return(true);
                }
                return(false);
            }
            catch (MySqlException mse)
            {
                if (mse.Source != null)
                {
                    System.Windows.MessageBox.Show("MySqlException source: {0}", mse.Source);
                }
                throw mse;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
        private void DeleBtn_click(object sender, RoutedEventArgs e)
        {
            RecordObj selectedRecord = (RecordObj)RecordsView.SelectedItem;

            if (selectedRecord == null)
            {
                System.Windows.MessageBox.Show("Please select a record");
            }
            else
            {
                RecordDao.DeleteTheRecord(selectedRecord);
                RefreshTheList();
            }
        }
Exemple #3
0
        public static List <RecordObj> QueryAllRecord()
        {
            List <RecordObj> records = new List <RecordObj>();
            MySqlConnection  conn    = null;

            try
            {
                conn = GetSqlConnection();
                MySqlCommand    cmd    = new MySqlCommand("SELECT * FROM cscalculator", conn);
                MySqlDataReader reader = cmd.ExecuteReader();

                RecordObj record;
                while (reader.Read())
                {
                    record = new RecordObj(
                        reader.GetString("Expression"),
                        reader.GetString("Preorder"),
                        reader.GetString("Postorder"),
                        reader.GetString("Decim"),
                        reader.GetString("Bina")
                        );
                    records.Add(record);
                }
            }
            catch (MySqlException mse)
            {
                if (mse.Source != null)
                {
                    Console.WriteLine("MySqlException source: {0}", mse.Source);
                }
                throw mse;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(records);
        }
Exemple #4
0
        public static void InsertTheRecord(RecordObj record)
        {
            MySqlConnection conn = null;

            try
            {
                string insertSql = "INSERT INTO cscalculator (Expression, Preorder, Postorder, Decim, Bina) VALUES (@Expression, @Preorder, @Postorder, @Decim, @Bina)";
                conn = GetSqlConnection();
                MySqlCommand cmd = new MySqlCommand(insertSql, conn);
                cmd.Parameters.AddWithValue("@Expression", record.Infix);
                cmd.Parameters.AddWithValue("@Preorder", record.Prefix);
                cmd.Parameters.AddWithValue("@Postorder", record.Postfix);
                cmd.Parameters.AddWithValue("@Decim", record.Deci);
                cmd.Parameters.AddWithValue("@Bina", record.Bin);
                int cnt = cmd.ExecuteNonQuery();
                if (cnt > 0)
                {
                    System.Windows.MessageBox.Show("Expression inserts successfully");
                }
                else
                {
                    System.Windows.MessageBox.Show("Fail to insert the expression");
                }
            }
            catch (MySqlException mse)
            {
                if (mse.Source != null)
                {
                    System.Windows.MessageBox.Show("MySqlException source: {0}", mse.Source);
                }
                throw;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
        private void ShowResult()
        {
            string infixStr = TxtExpre.Text;

            if (ConversionAndCalculation.TestExpression(infixStr))
            {
                string   prefixStr  = ConversionAndCalculation.DoTransPre(infixStr);
                string[] postfixArr = ConversionAndCalculation.DoTransPos(infixStr);
                string   postfixStr = String.Concat(postfixArr);
                int      decResult  = ConversionAndCalculation.Calculation(postfixArr);
                string   binResult  = Convert.ToString(decResult, 2);

                currentRecord = new RecordObj(infixStr, prefixStr, postfixStr, decResult.ToString(), binResult);
                TxtPre.Text   = currentRecord.Prefix;
                TxtPos.Text   = currentRecord.Postfix;
                TxtDec.Text   = currentRecord.Deci;
                TxtBin.Text   = currentRecord.Bin;
            }
            else
            {
                TxtExpre.Text = ErrorMsg;
            }
        }