private bool read_file(string FileName, out string msg) { msg = null; int i = 0; try { string FilePath = Path.Combine(inpath, FileName); string[] arr_lines = File.ReadAllLines(FilePath); // если файл пустой - ошибка if (arr_lines.Length <= 0) { msg = "Empty file."; return(false); } data = new List <STRowAmountPC>(); STRowAmountPC item = new STRowAmountPC(); for (i = 0; i < arr_lines.Length; i++) { item = new STRowAmountPC(); string[] words = arr_lines[i].Split(';'); if (create_row(words[0], words[1], out item, out msg)) { data.Add(item); } else { log.LogLine(string.Format("Erorr row's reading {0}, {1})", i, msg)); } } } catch (Exception ex) { msg = ex.Message; log.LogLine("File wasn't read."); return(false); } return(true); }
private void insert_row(STRowAmountPC item) { try { using (OracleConnection connection = new OracleConnection(config.connectionstring)) { connection.Open(); string query = "INSERT INTO RCD.VALID_AMOUNT_PC ( PDATE, APPCODE, AMOUNT) values (:1, :2, :3)"; OracleCommand command = new OracleCommand(query, connection); command.Parameters.Add(crp(OracleType.DateTime, item.dtime, "1", false)); command.Parameters.Add(crp(OracleType.Int32, item.appcode, "2", false)); command.Parameters.Add(crp(OracleType.Number, Math.Round(item.amount, 2), "3", false)); command.ExecuteNonQuery(); connection.Close(); } } catch (Exception ex) { MessageBox.Show(ex.TargetSite + " " + ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void update_row(STRowAmountPC item) { try { using (OracleConnection connection = new OracleConnection(config.connectionstring)) { connection.Open(); string query = "UPDATE RCD.VALID_AMOUNT_PC SET AMOUNT=:3 WHERE PDATE=:1 and APPCODE=:2"; OracleCommand command = new OracleCommand(query, connection); command.Parameters.Add(crp(OracleType.DateTime, item.dtime, "1", false)); command.Parameters.Add(crp(OracleType.Int32, item.appcode, "2", false)); command.Parameters.Add(crp(OracleType.Number, Math.Round(item.amount, 2), "3", false)); command.ExecuteNonQuery(); connection.Close(); } } catch (Exception ex) { MessageBox.Show(ex.TargetSite + " " + ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private bool create_row(string data, string amount, out STRowAmountPC item, out string msg) { bool ret = true; item = new STRowAmountPC(); item.appcode = 300; msg = null; try { if (!get_datetime(data, out item.dtime, out msg)) { return(false); } if (!double.TryParse(amount, out item.amount)) { return(false); } } catch (Exception ex) { ret = false; msg = ex.Message; } return(ret); }