Пример #1
0
 private void connectBtn_Click(object sender, System.EventArgs e)
 {
     try
     {
         this.Cursor        = System.Windows.Forms.Cursors.WaitCursor;
         connectStatus.Text = "connecting";
         conn = DBConnector.getConnection(this.getDatabaseType(), server.Text, port.Text, userid.Text, password.Text, database.Text);
         connectStatus.Text = "connected to: " + String.Format("server={0};user id={1}; password={2}; port={3}; database={4}; pooling=false",
                                                               server.Text, userid.Text, password.Text, port.Text, database.Text);
         DBConnector.refreshDBTreeView();
         tables.Items.Clear();
         tables.Items.AddRange(DBConnector.getTables());
         if (attributes["databaseType"] == null)
         {
             attributes.Add("databaseType", this.getDatabaseType());
         }
         else
         {
             attributes["databaseType"] = this.getDatabaseType();
         }
         if (attributes["server"] == null)
         {
             attributes.Add("server", this.server.Text);
         }
         else
         {
             attributes["server"] = this.server.Text;
         }
         if (attributes["userid"] == null)
         {
             attributes.Add("userid", this.userid.Text);
         }
         else
         {
             attributes["userid"] = this.userid.Text;
         }
         if (attributes["port"] == null)
         {
             attributes.Add("port", this.port.Text);
         }
         else
         {
             attributes["port"] = this.port.Text;
         }
         if (attributes["password"] == null)
         {
             attributes.Add("password", this.password.Text);
         }
         else
         {
             attributes["password"] = this.password.Text;
         }
         if (attributes["database"] == null)
         {
             attributes.Add("database", this.database.Text);
         }
         else
         {
             attributes["database"] = this.database.Text;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         this.Cursor = System.Windows.Forms.Cursors.Default;
     }
 }
Пример #2
0
 private void tables_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     data = DBConnector.getDataTable("SELECT * FROM " + tables.SelectedItem.ToString());
     dataGrid.DataSource = data;
 }
Пример #3
0
 private void updateBtn_Click(object sender, System.EventArgs e)
 {
     DBConnector.updateDataTable();
 }
Пример #4
0
 private static void toEnd(Hashtable attributes, ArrayList items, Hashtable item, DataTable data, string reportFilePath)
 {
     foreach (Hashtable item1 in items)
     {
         if ("route".Equals(item1["type"]) && ((string)item1["pointX"]).Equals((string)item["guid"]))
         {
             count++;
             DataTable subData;
             if (item1["condition"] != null && !item1["condition"].Equals(""))
             {
                 subData = data.Clone();
                 string item1Condition = ((string)item1["condition"]).Replace("{minValue}", (string)attributes["startTime"]).Replace("{maxValue}", (string)attributes["endTime"]);
                 if (attributes["startTime1"] != null && attributes["endTime1"] != null)
                 {
                     item1Condition = item1Condition.Replace("{minValue1}", (string)attributes["startTime1"]).Replace("{maxValue1}", (string)attributes["endTime1"]);
                 }
                 DataRow[] rows = data.Select(item1Condition);
                 foreach (DataRow row in rows)
                 {
                     subData.ImportRow(row);
                 }
             }
             else
             {
                 subData = data;
             }
             string    pointY = (string)item1["pointY"];
             Hashtable item2  = DBProcessor.getItemByGuid(items, pointY);
             if ("node".Equals(item2["type"]))
             {
                 count++;
                 if (item2["sql"] != null && !item2["sql"].Equals(""))
                 {
                     string item2Sql = ((string)item2["sql"]).Replace("{minValue}", (string)attributes["startTime"]).Replace("{maxValue}", (string)attributes["endTime"]);
                     if (attributes["startTime1"] != null && attributes["endTime1"] != null)
                     {
                         item2Sql = item2Sql.Replace("{minValue1}", (string)attributes["startTime1"]).Replace("{maxValue1}", (string)attributes["endTime1"]);
                     }
                     string newSql = item2Sql;
                     if ((item2Sql).IndexOf("'{previousDataTable.") > -1)
                     {
                         newSql = "";
                         foreach (DataRow subRow in subData.Rows)
                         {
                             string tempSql = item2Sql;
                             int    i       = 0;
                             foreach (DataColumn subColumn in subData.Columns)
                             {
                                 tempSql = tempSql.Replace("{previousDataTable." + subColumn + "}", subRow.ItemArray[i].ToString());
                                 i++;
                             }
                             if (newSql.Length == 0)
                             {
                                 newSql += tempSql;
                             }
                             else
                             {
                                 newSql += " union " + tempSql;
                             }
                         }
                     }
                     DataTable subSubData = DBConnector.getDataTable(newSql);
                     if (item2["condition"] != null && !item2["condition"].Equals(""))
                     {
                         string item2Condition = ((string)item2["condition"]).Replace("{minValue}", (string)attributes["startTime"]).Replace("{maxValue}", (string)attributes["endTime"]);
                         if (attributes["startTime1"] != null && attributes["endTime1"] != null)
                         {
                             item2Condition = item2Condition.Replace("{minValue1}", (string)attributes["startTime1"]).Replace("{maxValue1}", (string)attributes["endTime1"]);
                         }
                         DataTable subSubSubData;
                         if ((item2Condition).IndexOf("'{previousDataTable.") > -1)
                         {
                             string[] conditions      = System.Text.RegularExpressions.Regex.Split(item2Condition, " and ");
                             string[] previousColumns = new string[conditions.Length];
                             string[] thisColumns     = new string[conditions.Length];
                             int      i = 0;
                             foreach (string condition in conditions)
                             {
                                 string[] columns = condition.Split('=');
                                 if (columns.Length == 2)
                                 {
                                     previousColumns[i] = columns[1].Replace("'{previousDataTable.", "").Replace("}'", "").Trim();
                                     thisColumns[i]     = columns[0].Trim();
                                 }
                                 else
                                 {
                                     throw new Exception("ɸѡÓï¾ä³ö´í");
                                 }
                                 i++;
                             }
                             subSubSubData = Functions.Join(subData, subSubData, previousColumns, thisColumns);
                         }
                         else
                         {
                             subSubSubData = subSubData.Clone();
                             DataRow[] subSubRows = subSubData.Select(item2Condition);
                             foreach (DataRow subSubRow in subSubRows)
                             {
                                 subSubSubData.ImportRow(subSubRow);
                             }
                         }
                         toEnd(attributes, items, item2, subSubSubData, reportFilePath);
                     }
                     else
                     {
                         toEnd(attributes, items, item2, subSubData, reportFilePath);
                     }
                 }
             }
             else if ("end".Equals(item2["type"]))
             {
                 count++;
                 string timeString = Functions.FormatString(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                 Functions.DataTableToFile(subData, reportFilePath + timeString + ".csv");
                 ResultForm resultForm = new ResultForm(reportFilePath, subData);
                 resultForm.Show();
             }
         }
     }
 }