private void FillDataGrid() { string ConString = MainWindow.GetString(); string CmdString = string.Empty; using (SqlConnection con = new SqlConnection(ConString)) { try { if (radio_sign.IsChecked == true) { // 숫자 검색 // 파싱을 통해 문법 준수 여부 체크 string sign = searchText.Text.Trim(); decimal dd = decimal.Parse(sign, NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent); BigDecimal bf; int exp = 0; int eidx = sign.IndexOf('E'); if (eidx != -1) { // 가수 예외 처리 bf = BigDecimal.Parse(sign.Substring(0, eidx)); if (bf == 0) { throw new Exception("0은 검색할 수 없습니다."); } else if (bf < 1) { throw new Exception("지수가 있는 수의 경우 1 미만은 허용되지 않습니다."); } else if (bf >= 10) { throw new Exception("지수가 있는 수의 경우 10 이상은 허용되지 않습니다."); } else { exp = int.Parse(sign.Substring(eidx + 1)); } } else { // 지수와 가수 분리 작업 bf = BigDecimal.Parse(sign); while (bf > 10 || bf < 1) { if (bf > 10) { bf /= 10; ++exp; } else if (bf < 1) { bf *= 10; --exp; } else { break; } } } sign = bf.ToString(); string msgstr = sign + (exp > 0 ? "E+" : "E") + exp; MessageBox.Show(msgstr + " / " + sign + " / " + exp, "~"); CmdString = "SELECT pr_num, PRNumber = (pr_sign + (case when pr_exp < 0 then 'E' else 'E+' end) + cast(pr_exp as char(12))), pr_exp FROM primetbl where pr_sign = '" + sign + "'"; } else if (radio_number.IsChecked == true) { // 주소 검색 string tmpstr = searchText.Text; CmdString = "SELECT pr_num, PRNumber = (pr_sign + (case when pr_exp < 0 then 'E' else 'E+' end) + cast(pr_exp as char(12))), pr_exp FROM primetbl where pr_num = " + tmpstr; } SqlCommand cmd = new SqlCommand(CmdString, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable("PrimeNumbers"); sda.Fill(dt); if (dt.Rows.Count == 0) { MessageBox.Show("결과가 없습니다.", "알림"); } else { datagrid1.ItemsSource = dt.DefaultView; } } catch (Exception e) { MessageBox.Show(e.Message, "오류"); } // end try-catch } }
private void FillDataGrid() { string ConString = MainWindow.GetString(); string CmdString = string.Empty; using (SqlConnection con = new SqlConnection(ConString)) { try { if (radio_sign.IsChecked == true) { // 숫자 검색 // 파싱을 통해 문법 준수 여부 체크 string sign = searchText.Text.Trim(); decimal dd = decimal.Parse(sign, NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent); BigDecimal bf; int exp = 0; int eidx = sign.IndexOf('E'); if (eidx != -1) { // 가수 예외 처리 bf = BigDecimal.Parse(sign.Substring(0, eidx)); if (bf == 0) { throw new Exception("0은 검색할 수 없습니다."); } else if (bf < 1) { throw new Exception("지수가 있는 수의 경우 1 미만은 허용되지 않습니다."); } else if (bf >= 10) { throw new Exception("지수가 있는 수의 경우 10 이상은 허용되지 않습니다."); } else { exp = int.Parse(sign.Substring(eidx + 1)); } } else { // 지수와 가수 분리 작업 bf = BigDecimal.Parse(sign); while (bf > 10 || bf < 1) { if (bf > 10) { bf /= 10; ++exp; } else if (bf < 1) { bf *= 10; --exp; } else { break; } } } sign = bf.ToString(); string msgstr = sign + (exp > 0 ? "E+" : "E") + exp; // MessageBox.Show(msgstr + " / " + sign + " / " + exp, "~"); CmdString = "SELECT FNumber = (fn_sign + (case when fn_exp < 0 then 'E' else 'E+' end) + cast(fn_exp as char(12))), fn_exp, f_opcode FROM fractiontbl where fn_sign = '" + sign + "'"; // Equal Number SqlCommand cmd = new SqlCommand(CmdString, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable("FractionNumbers_E"); sda.Fill(dt); dg_fn_equal.ItemsSource = dt.DefaultView; txtQuery_E.Text = dt.Rows.Count.ToString(); txtDiff_E.Text = "0"; // Small Number CmdString = "SELECT A.* from (SELECT top 100 FNumber = (fn_sign + (case when fn_exp < 0 then 'E' else 'E+' end) + cast(fn_exp as char(12))), fn_exp, fn_sign as diff, f_opcode FROM fractiontbl where fn_sign < '" + sign + "') A order by A.diff desc"; cmd = new SqlCommand(CmdString, con); sda = new SqlDataAdapter(cmd); dt = new DataTable("FractionNumbers_S"); sda.Fill(dt); DataRow[] drs = dt.Select(); for (int i = 0; i < dt.Rows.Count; ++i) { drs[i].SetField("diff", (bf - BigDecimal.Parse((string)drs[i]["diff"])).ToString()); } txtQuery_S.Text = dt.Rows.Count.ToString(); txtDiff_S.Text = (string)drs[0]["diff"]; dg_fn_small.ItemsSource = dt.DefaultView; // Large Number CmdString = "(SELECT top 100 FNumber = (fn_sign + (case when fn_exp < 0 then 'E' else 'E+' end) + cast(fn_exp as char(12))), fn_exp, fn_sign as diff, f_opcode FROM fractiontbl where fn_sign > '" + sign + "') order by fn_sign asc"; cmd = new SqlCommand(CmdString, con); sda = new SqlDataAdapter(cmd); dt = new DataTable("FractionNumbers_L"); sda.Fill(dt); drs = dt.Select(); for (int i = 0; i < dt.Rows.Count; ++i) { drs[i].SetField("diff", (BigDecimal.Parse((string)drs[i]["diff"]) - bf).ToString()); } txtQuery_L.Text = dt.Rows.Count.ToString(); txtDiff_L.Text = (string)drs[0]["diff"]; dg_fn_large.ItemsSource = dt.DefaultView; } } catch (Exception e) { MessageBox.Show(e.Message, "오류"); } // end try-catch } }
private void Upload_Click(object sender, RoutedEventArgs e) { try { // 사전처리 - 파싱을 통해 문법 준수 여부 체크 string sign = text_mn.Text.Trim(); decimal dd = decimal.Parse(sign, NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent); BigDecimal bf; int exp = 0; int eidx = sign.IndexOf('E'); if (eidx != -1) { // 가수 예외 처리 bf = BigDecimal.Parse(sign.Substring(0, eidx)); if (bf == 0) { throw new Exception("0은 검색할 수 없습니다."); } else if (bf < 1) { throw new Exception("지수가 있는 수의 경우 1 미만은 허용되지 않습니다."); } else if (bf >= 10) { throw new Exception("지수가 있는 수의 경우 10 이상은 허용되지 않습니다."); } else { exp = int.Parse(sign.Substring(eidx + 1)); } } else { // 지수와 가수 분리 작업 bf = BigDecimal.Parse(sign); while (bf > 10 || bf < 1) { if (bf > 10) { bf /= 10; ++exp; } else if (bf < 1) { bf *= 10; --exp; } else { break; } } } sign = bf.ToString(); string msgstr = sign + (exp > 0 ? "E+" : "E") + exp; // 입력 작업 시작 using (WebClient Client = new System.Net.WebClient()) { // 이미지 업로드 Client.Headers.Add("Content-Type", "binary/octet-stream"); if (text_file.Text != string.Empty) { byte[] result = Client.UploadFile("http://192.168.0.12:8000/zerozone_test/imageupload.php", "POST", text_file.Text); string phpmsg = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); } else { MessageBox.Show("이미지 파일의 경로를 확인해주세요.", "오류"); } // Child Number 생성 string urlAddress = "http://192.168.0.12:8000/zerozone_test/zz_calculator.gennum.php"; string num, owner, maa, mab, mac, desc, type; num = text_mn.Text; owner = "YANG"; maa = text_addr.Text; mab = text_addr.Text + ".gif"; mac = string.Empty; desc = string.Empty; type = "base"; NameValueCollection postData = new NameValueCollection() { { "num", num }, //order: {"parameter name", "parameter value"} { "owner", owner }, { "maa", maa }, { "mab", mab }, { "mac", mac }, { "desc", desc }, { "type", type } }; Client.Headers.Clear(); string pagesource = Encoding.UTF8.GetString(Client.UploadValues(urlAddress, postData)); MessageBox.Show(pagesource, "OK"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "오류"); } // end try-catch }
/// <summary> /// Parses the text in the text box into a double datatype and returns it. /// </summary> private BigDecimal getNumber() { return(BigDecimal.Parse(resultBox.Text)); }
private void FillDataGrid() { string ConString = MainWindow.GetString(); string CmdString = string.Empty; using (SqlConnection con = new SqlConnection(ConString)) { try { // 숫자 검색 // 파싱을 통해 문법 준수 여부 체크 string sign = searchText.Text.Trim(); decimal dd = decimal.Parse(sign, NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent); BigDecimal bf; int exp = 0; int eidx = sign.IndexOf('E'); if (eidx != -1) { // 가수 예외 처리 bf = BigDecimal.Parse(sign.Substring(0, eidx)); if (bf == 0) { throw new Exception("0은 검색할 수 없습니다."); } else if (bf < 1) { throw new Exception("지수가 있는 수의 경우 1 미만은 허용되지 않습니다."); } else if (bf >= 10) { throw new Exception("지수가 있는 수의 경우 10 이상은 허용되지 않습니다."); } else { exp = int.Parse(sign.Substring(eidx + 1)); } } else { // 지수와 가수 분리 작업 bf = BigDecimal.Parse(sign); while (bf > 10 || bf < 1) { if (bf > 10) { bf /= 10; ++exp; } else if (bf < 1) { bf *= 10; --exp; } else { break; } } } sign = bf.ToString(); string msgstr = sign + (exp > 0 ? "E+" : "E") + exp; CmdString = "SELECT CNumber = (cn_sign + (case when cn_exp < 0 then 'E' else 'E+' end) + cast(cn_exp as char(12))), child_logic_desc, child_create_date, child_mn_sign as MNumber, child_mn_exp, child_m_addr_a FROM childtbl nolock where cn_sign = '" + sign + ((cn_sign.IsChecked == true) ? "'" : "' and cn_exp = " + exp); // Equal Number SqlCommand cmd = new SqlCommand(CmdString, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable("ChildNumbers_E"); sda.Fill(dt); dg_cn_equal.ItemsSource = dt.DefaultView; // Small Number CmdString = "SELECT top 20 CNumber = (cn_sign + (case when cn_exp < 0 then 'E' else 'E+' end) + cast(cn_exp as char(12))), cn_sign as diff, child_logic_desc, child_create_date, (child_mn_sign + 'E+' + cast(child_mn_exp as char(12))) as MNumber, child_m_addr_a FROM childtbl nolock where cn_sign < '" + sign + ((cn_sign.IsChecked == true) ? "'" : "' and cn_exp <= " + exp); cmd = new SqlCommand(CmdString, con); sda = new SqlDataAdapter(cmd); dt = new DataTable("ChildNumbers_S"); sda.Fill(dt); dt.DefaultView.Sort = "diff asc"; dg_cn_small.ItemsSource = dt.DefaultView; // Large Number CmdString = "SELECT top 20 CNumber = (cn_sign + (case when cn_exp < 0 then 'E' else 'E+' end) + cast(cn_exp as char(12))), cn_sign as diff, child_logic_desc, child_create_date, (child_mn_sign + 'E+' + cast(child_mn_exp as char(12))) as MNumber, child_m_addr_a FROM childtbl nolock where cn_sign > '" + sign + ((cn_sign.IsChecked == true) ? "'" : "' and cn_exp >= " + exp); cmd = new SqlCommand(CmdString, con); sda = new SqlDataAdapter(cmd); dt = new DataTable("ChildNumbers_L"); sda.Fill(dt); dt.DefaultView.Sort = "diff asc"; dg_cn_Large.ItemsSource = dt.DefaultView; } catch (Exception) { MessageBox.Show("입력한 숫자를 확인해주세요.", "오류"); } } }