/// <summary> /// Method to fetch module info for given HRA Id /// </summary> private void FetchModuleInfo() { SQLConnect sql = new SQLConnect(); string query = "Select PageID , Header From Flywheel.dbo.FLY_Page Where HRAID = 89 Order by PageId asc"; sql.OpenConnection(); pageinfo = sql.Execute(query); if (pageinfo.HasRows) { while (pageinfo.Read()) { pages.Add(new string[] { pageinfo[0].ToString(), pageinfo[1].ToString() }); } sql.CloseConnection(); //Console.WriteLine("================= Page Info =================="); //for (int i = 0; i < pages.Count; i++) //{ // Console.WriteLine(pages.ElementAt(i)[0] + " | " + pages.ElementAt(i)[1]); //} } else { Console.WriteLine(this.GetType().Name + ": No module info found"); } }
// Delete Customer public void Delete(string firstName) { connect = new SQLConnect(); string query = "DELETE FROM CustomerDetails WHERE FirstName =" + "'" + firstName + "'"; SqlCommand cmd = new SqlCommand(query, connect.OpenConnection()); cmd.ExecuteNonQuery(); connect.CloseConnection(); }
public void ExecuteDBQuery() { SQLConnect sqlcn = new SQLConnect(); sqlcn.OpenConnection(); string joinservicecycle = "join Onlife..tbl_ServiceCycle sc on sc.ServiceCycleId = scgm.ServiceCycleId and sc.ServiceCycleEndDate > getDate()"; string joingroupid = "join OnlifeEntity..tbl_Group g on g.GroupGuid = scgm.GroupGuid"; string joinpointmatrix = "join Onlife..tbl_PointsMatrixActionCategoryMap pmacm on pmacm.PointsMatrixId = sc.PointsMatrixId"; string joinrulepackage = "join Onlife.dbo.tbl_RulePackage rp on rp.RulePackageID = sc.RulePackageID"; string joinactioncategory = "join Onlife.dbo.LU_ActionCategory ac on pmacm.ActionCategoryID = ac.ActionCategoryID"; string joinpointsfreq = "join onlife..lu_PointsFrequency PF on pf.PointsFrequencyId = pmacm.FrequencyDays"; //string sqlquery = "Select g.GroupId, g.GroupName,sc.ServiceCycleId,sc.PointsMatrixId, pmacm.ActionCategoryId,ac.ActionCategoryInternalName--,acm.ActionId,pmacm.InstancePoints,pmacm.MaxInstances,pmacm.frequencyMaxInstances,pmacm.FrequencyDays, pf.FrequencyDescription From Onlife..ServiceCycleGroupMap scgm"+joinservicecycle+joingroupid+joinpointmatrix+joinrulepackage+joinactioncategory+joinpointsfreq+"Where G.GroupID = 50"; string sqlquery = "Select g.GroupName" + ",pmacm.InstancePoints,pmacm.frequencyMaxInstances, pf.FrequencyDescription,ac.ActionCategoryInternalName" + " From Onlife..ServiceCycleGroupMap scgm" + " join Onlife..tbl_ServiceCycle sc on sc.ServiceCycleId = scgm.ServiceCycleId and sc.ServiceCycleEndDate > getDate()" + " join OnlifeEntity..tbl_Group g on g.GroupGuid = scgm.GroupGuid" + " join Onlife..tbl_PointsMatrixActionCategoryMap pmacm on pmacm.PointsMatrixId = sc.PointsMatrixId" + " join Onlife.dbo.tbl_RulePackage rp on rp.RulePackageID = sc.RulePackageID" + " join Onlife.dbo.LU_ActionCategory ac on pmacm.ActionCategoryID = ac.ActionCategoryID" + " join onlife..lu_PointsFrequency PF on pf.PointsFrequencyId = pmacm.FrequencyDays" + " Where G.GroupName like '%nucor%'"; DataTable responsetbl = sqlcn.Execute1(sqlquery); foreach (DataColumn col in responsetbl.Columns) { Console.Write(col.ColumnName.ToString() + "\t\t"); } Console.WriteLine(); foreach (DataRow row in responsetbl.Rows) { foreach (DataColumn col in responsetbl.Columns) { Console.Write(row[col] + "\t\t\t"); } Console.WriteLine(); } //for (int i=0;i<responsetbl.Rows.Count;i++) //{ // for(int j=0;j<responsetbl.Columns.Count;j++) // { // Console.WriteLine(responsetbl.Rows[i][j]); // } //} }
// Create new Customer public void Create(Customer customer) { // Check Email is valid bool validateEmailAddress = ValidateEmail(customer.Email); if (validateEmailAddress == false) { Console.WriteLine("Email address is invalid"); } // Check if customer already exists connect = new SQLConnect(); string customerExitsQuery = "SELECT FirstName FROM CustomerDetails WHERE FirstName =" + "'" + customer.FirstName + "'"; SqlDataAdapter da = new SqlDataAdapter(customerExitsQuery, connect.OpenConnection()); DataTable table = new DataTable(); da.Fill(table); if (table.Rows.Count >= 1) { Console.WriteLine("Customer already exists"); } // Add new customer to database if (table.Rows.Count == 0 && validateEmailAddress == true) { string query = "INSERT INTO CustomerDetails " + "(FirstName, MiddleName, LastName, PhoneNumber, Address, Email, CreationDate)" + "VALUES (@FirstName, @MiddleName, @LastName, @PhoneNumber, @Address, @Email, @CreationDate)"; SqlCommand cmd = new SqlCommand(query, connect.OpenConnection()); cmd.Parameters.Add("@Firstname", SqlDbType.VarChar).Value = customer.FirstName; cmd.Parameters.Add("@Middlename", SqlDbType.VarChar).Value = customer.MiddleName; cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = customer.LastName; cmd.Parameters.Add("@PhoneNumber", SqlDbType.Int).Value = customer.PhoneNumber; cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = customer.Address; cmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = customer.Email; cmd.Parameters.Add("@CreationDate", SqlDbType.NVarChar).Value = customer.DateCreated; cmd.ExecuteNonQuery(); connect.CloseConnection(); } }
internal string check(dbModel model) { SQLConnect conexion = new SQLConnect(model.username, model.pass, model.server, model.port, model.alias); try { if (conexion.OpenConnection().Equals("Connected")) { return("Connected"); } else { return("Cant- connect"); } } catch (Exception e) { return("Cant- connect"); } }
// Update Customer Details public void Edit(Customer customer) { connect = new SQLConnect(); string query = "UPDATE CustomerDetails SET " + "FirstName =" + "'" + customer.FirstName + "'," + "MiddleName =" + "'" + customer.MiddleName + "'," + "LastName =" + "'" + customer.LastName + "'," + "PhoneNumber =" + "'" + customer.PhoneNumber + "'," + "Address =" + "'" + customer.Address + "'," + "Email =" + "'" + customer.Email + "'," + "CreationDate =" + "'" + customer.DateCreated + "'" + "WHERE FirstName =" + "'" + customer.FirstName + "'" ; SqlCommand cmd = new SqlCommand(query, connect.OpenConnection()); cmd.ExecuteNonQuery(); connect.CloseConnection(); }
// Print Customer table public void PrintCustomers() { connect = new SQLConnect(); string query = "SELECT * FROM CustomerDetails"; SqlCommand cmd = new SqlCommand(query, connect.OpenConnection()); DataTable dataTable = new DataTable(); SqlDataAdapter dap = new SqlDataAdapter(cmd); dap.Fill(dataTable); var table = new ConsoleTable("Id", "Firstname", "Middlename", "Lastname", "PhoneNumber", "Address", "Email", "DateCreated"); foreach (DataRow dataRow in dataTable.Rows) { table.AddRow(dataRow[0], dataRow[1], dataRow[2], dataRow[3], dataRow[4], dataRow[5], dataRow[6], dataRow[7]); } Console.WriteLine(table); connect.CloseConnection(); }
static void Main(string[] args) { DateTime beforeDT = DateTime.Now; //数据库相关信息 string server; //数据库地址 string database; //数据库名称 string user; //数据库用户名 string pwd; //数据库密码 //数据库查询语句 string command1 = null; string command2 = null; string command3 = null; string command4 = null; string time = null; string debug = null; //是否启用日志记录,"LOG":启用日志记录;"NONE":不启用日志记录 string command5 = null; //查询技能高于某个水平的人员位置的SQL语句 string command6 = null; //查询人员位置的SQL语句 //紧急任务相关信息 string taskID = null; string t_positionID = null; //int skillLevel = 0; string position_tableName = ""; //井之间距离的表名 List <string> personID = new List <string>(); List <string> p_positionID = new List <string>(); List <int> p_spendTime = new List <int>(); string choosePersonID = null; #region 输入参数解析 if (args.Length == 0) { server = "DESKTOP-36C9L6T"; database = "lushushu"; user = "******"; pwd = "123"; command1 = "select * from IMS_PATROL_PERSON_ON_DUTY;"; command2 = "select * from IMS_PATROL_TASK_SKILL ORDER BY TASK_PRIORITY ASC;"; command3 = "select * from IMS_PATROL_PERSON_TASK_TIME;"; command4 = "select * from IMS_PATROL_TASK_SPEND_TIME;"; time = "8:30"; debug = "NONE"; command5 = "select PERSON_ID from IMS_PATROL_PERSON_ON_DUTY where SKILL_LEVEL<=2;"; taskID = "TS0015"; t_positionID = ""; } else if (args.Length == 10) //任务调度传递10个参数 { server = args[0]; database = args[1]; user = args[2]; pwd = args[3]; command1 = args[4]; command2 = args[5]; command3 = args[6]; command4 = args[7]; time = args[8]; debug = args[9]; string[] lstr = new string[2] { "7:30", "8:30" }; bool exists = ((IList)lstr).Contains(time); if (!exists) { Console.WriteLine("工作开始时间有误"); return; } } else if (args.Length == 9) //紧急任务处理传递9个参数 { server = args[0]; database = args[1]; user = args[2]; pwd = args[3]; command5 = args[4]; command6 = args[5]; position_tableName = args[6]; taskID = args[7]; t_positionID = args[8]; } else { Console.WriteLine("数据库参数输入格式不正确,共输入了%d个参数", args.Length); return; } #endregion if ((debug == null) && (args.Length == 9)) { SQLConnect scon = new SQLConnect(server, database, user, pwd); personID = scon.GetHighLevelPersonIDFromSQL(command5); //得到可以做此任务的人员ID //TODO:get person position id //... List <string>[] listPersonPosition = scon.GetPersonPositionIDFromSQL(command6); for (int i = 0; i < personID.Count; i++) { for (int j = 0; j < listPersonPosition[0].Count; j++) { if (listPersonPosition[0][j] == personID[i]) { p_positionID.Add(listPersonPosition[1][j]); break; } } } //TODO:get person spend time from person position id to task position id //... p_spendTime = scon.GetPositionSpendTimeFromSQL(position_tableName, p_positionID, t_positionID); //找到到达任务点最快人的ID int minTime = p_spendTime[0]; int index = 0; for (int i = 0; i < p_spendTime.Count; i++) { if (p_spendTime[i] < minTime) { minTime = p_spendTime[i]; index = i; } } choosePersonID = personID[index]; List <string>[] personTaskList = scon.GetPersonTaskListFromSQL(choosePersonID); int t_index = 0; string taskStartTime = null; for (int i = 0; i < personTaskList[0].Count; i++) { DateTime tstart = Convert.ToDateTime(personTaskList[2][i]); DateTime restStartTime = new DateTime(beforeDT.Year, beforeDT.Month, beforeDT.Day, 12, 0, 0); DateTime restEndTime = new DateTime(beforeDT.Year, beforeDT.Month, beforeDT.Day, 14, 0, 0); TimeSpan td = beforeDT.Subtract(tstart); double timeInterval = td.TotalMinutes; if ((timeInterval > 0) && (timeInterval < Convert.ToDouble(personTaskList[1][i]))) { if (beforeDT.AddMinutes(minTime) < restStartTime) { taskStartTime = Convert.ToString(beforeDT); } else { taskStartTime = Convert.ToString(restEndTime); } t_index = i; break; } } int count = personTaskList[0].Count; List <string>[] newPersonTaskList = new List <string>[4] { new List <string>(), new List <string>(), new List <string>(), new List <string>() }; //TASK_ID,SPEND_TIME,START_TIME,END_TIME newPersonTaskList[0].Add(taskID); newPersonTaskList[1].Add(minTime.ToString()); newPersonTaskList[2].Add(taskStartTime); newPersonTaskList[3].Add(AddMinutes(taskStartTime, minTime)); for (int i = 1; i < count - t_index; i++) { newPersonTaskList[0].Add(personTaskList[0][t_index + i]); newPersonTaskList[1].Add(personTaskList[1][t_index + i]); newPersonTaskList[2].Add(newPersonTaskList[3][i - 1]); newPersonTaskList[3].Add(AddMinutes(newPersonTaskList[2][i], Convert.ToInt32(newPersonTaskList[1][i]))); } scon.UpdateTaskTimeToSQL(choosePersonID, newPersonTaskList); } else { //从数据库获取数据 SQLConnect scon = new SQLConnect(server, database, user, pwd); List <string>[] listData = scon.GetDataFromSQL(command1, command2, command3, command4); //设置GAMS运行路径 string workPath = Directory.GetCurrentDirectory() + @"\GAMS_workPath"; Console.WriteLine(workPath); //运行GAMS模型 GAMSModel gModel = new GAMSModel(workPath); //GAMS运行模型的工作区,会在此文件夹生成相关调试过程文件 gModel.Model_N = scon.Model_N; //gModel.Model_N = 16; gModel.Work_Start_Time = time; List <string>[] resultData = gModel.Run(listData); //得到GAMS的运行结果 //将模型运行的最终结果存进数据库 string tableName = scon.SendDataToSQL(resultData, time); Console.WriteLine("求解完毕,求解结果保存在" + tableName); //开启日志记录 if (debug == "LOG") { string fileName = workPath + @"\Log.txt"; Log("-----" + beforeDT.ToString() + "-----", fileName); Log(listData, fileName); Log(resultData, fileName); } } DateTime afterDT = DateTime.Now; TimeSpan ts = afterDT.Subtract(beforeDT); Console.WriteLine("求解总共花费{0:0.0}min.", ts.TotalMinutes); }
public aSQLController(string uid, string pass, string server, int port, string database) { conexion = new SQLConnect(uid, pass, server, port, database); }
public aSQLController() { conexion = new SQLConnect("root", "201143253", "DESKTOP-Q7Q195A", 1433, "master"); }
public aSQLController() { conexion = new SQLConnect("root", "Ard2592allan", "DESKTOP-3ALTQEK", 1433, "master"); }
private void LoadButton_Click(object sender, RoutedEventArgs e) { ResultGrid.ItemsSource = SQLConnect.SQLout(DealTB.Text); }
/// <summary> /// Method to fetch response info for given page Id /// </summary> /// <param name="pageid"></param> public DataTable FetchResponseInfo(string pageid) { SQLConnect sql = new SQLConnect(); DataTable responsetbl = new DataTable("ResponseInfo"); try { string selectstmt = "Select RID,fr.QID,RText,fr.TypeId,frt.Description, fq.isReadOnly, fq.QText From Flywheel.dbo.FLY_Response fr "; string join1 = " Join Flywheel.dbo.LU_FLY_Response_Type frt on frt.TypeId = fr.TypeId"; string join2 = " join Flywheel..FLY_Questions fq on fq.QID = fr.QID"; string wherecond = " Where fr.QID in (Select QID from Flywheel..FLY_Questions Where PageID = " + pageid + ") and fr.TypeID in (1,2)"; string query = selectstmt + join1 + join2 + wherecond; sql.OpenConnection(); responseinfo = sql.Execute(query); DataTable dtSchema = responseinfo.GetSchemaTable(); // You can also use an ArrayList instead of List<> List <DataColumn> listCols = new List <DataColumn>(); if (dtSchema != null) { foreach (DataRow drow in dtSchema.Rows) { string columnName = Convert.ToString(drow["ColumnName"]); DataColumn column = new DataColumn(columnName, (Type)(drow["DataType"])); column.Unique = (bool)drow["IsUnique"]; column.AllowDBNull = (bool)drow["AllowDBNull"]; column.AutoIncrement = (bool)drow["IsAutoIncrement"]; listCols.Add(column); responsetbl.Columns.Add(column); } } // Read rows from DataReader and populate the DataTable while (responseinfo.Read()) { DataRow dataRow = responsetbl.NewRow(); for (int i = 0; i < listCols.Count; i++) { dataRow[((DataColumn)listCols[i])] = responseinfo[i]; } responsetbl.Rows.Add(dataRow); } } catch (SqlException ex) { Console.WriteLine(ex); } finally { sql.CloseConnection(); } Console.WriteLine("Rows Count in Responsetbl: " + responsetbl.Rows.Count); //string expression = "RText = 'Hours' and QText like '%Moderate%'"; //DataRow[] foundRows; //// Use the Select method to find all rows matching the filter. //foundRows = responsetbl.Select(expression); //// Print column 0 of each returned row. //for (int i = 0; i < foundRows.Length; i++) //{ // Console.WriteLine(foundRows[i][0] + " | " + foundRows[i][1] + " | " + foundRows[i][2] + " | " + foundRows[i][3] + " | " + foundRows[i][4] + " | " + foundRows[i][5] + " | " + foundRows[i][6]); //} return(responsetbl); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ObjectUpdatesForm)); this.columnHeader5 = new System.Windows.Forms.ColumnHeader(); this.sqlConnect1 = new SqlSync.SQLConnect(); this.btnChangeScripting = new System.Windows.Forms.Button(); this.pnlSqlConnect = new System.Windows.Forms.Panel(); this.btnCancelChangeSource = new System.Windows.Forms.Button(); this.btnChangeSource = new System.Windows.Forms.Button(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pnlSqlConnect.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // // columnHeader3 // this.columnHeader3.Text = "Source Object Name"; this.columnHeader3.Width = 200; // // btnCancel // this.btnCancel.Location = new System.Drawing.Point(431, 489); this.btnCancel.Size = new System.Drawing.Size(134, 29); // // btnUpdate // this.btnUpdate.Location = new System.Drawing.Point(267, 489); this.btnUpdate.Size = new System.Drawing.Size(154, 29); this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click); // // lstUpdates // this.lstUpdates.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.columnHeader5 }); this.lstUpdates.FullRowSelect = true; this.lstUpdates.Location = new System.Drawing.Point(29, 47); this.lstUpdates.Size = new System.Drawing.Size(775, 430); // // lnkCheck // this.lnkCheck.Location = new System.Drawing.Point(826, 28); this.lnkCheck.Size = new System.Drawing.Size(144, 15); // // columnHeader5 // this.columnHeader5.Text = "Object Type"; this.columnHeader5.Width = 108; // // sqlConnect1 // this.sqlConnect1.DisplayDatabaseDropDown = true; this.sqlConnect1.Location = new System.Drawing.Point(58, 20); this.sqlConnect1.Name = "sqlConnect1"; this.sqlConnect1.Size = new System.Drawing.Size(316, 515); this.sqlConnect1.TabIndex = 6; // // btnChangeScripting // this.btnChangeScripting.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnChangeScripting.Location = new System.Drawing.Point(638, 482); this.btnChangeScripting.Name = "btnChangeScripting"; this.btnChangeScripting.Size = new System.Drawing.Size(166, 27); this.btnChangeScripting.TabIndex = 7; this.btnChangeScripting.Text = "Change Scripting Source"; this.btnChangeScripting.UseVisualStyleBackColor = true; this.btnChangeScripting.Click += new System.EventHandler(this.btnChangeScripting_Click); // // pnlSqlConnect // this.pnlSqlConnect.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.pnlSqlConnect.BackColor = System.Drawing.Color.LightSteelBlue; this.pnlSqlConnect.Controls.Add(this.btnCancelChangeSource); this.pnlSqlConnect.Controls.Add(this.btnChangeSource); this.pnlSqlConnect.Controls.Add(this.sqlConnect1); this.pnlSqlConnect.Location = new System.Drawing.Point(305, 15); this.pnlSqlConnect.Name = "pnlSqlConnect"; this.pnlSqlConnect.Size = new System.Drawing.Size(267, 462); this.pnlSqlConnect.TabIndex = 8; // // btnCancelChangeSource // this.btnCancelChangeSource.Location = new System.Drawing.Point(247, 543); this.btnCancelChangeSource.Name = "btnCancelChangeSource"; this.btnCancelChangeSource.Size = new System.Drawing.Size(90, 28); this.btnCancelChangeSource.TabIndex = 8; this.btnCancelChangeSource.Text = "Cancel"; this.btnCancelChangeSource.UseVisualStyleBackColor = true; this.btnCancelChangeSource.Click += new System.EventHandler(this.btnCancelChangeSource_Click); // // btnChangeSource // this.btnChangeSource.Location = new System.Drawing.Point(101, 543); this.btnChangeSource.Name = "btnChangeSource"; this.btnChangeSource.Size = new System.Drawing.Size(139, 28); this.btnChangeSource.TabIndex = 7; this.btnChangeSource.Text = "Change Source"; this.btnChangeSource.UseVisualStyleBackColor = true; this.btnChangeSource.Click += new System.EventHandler(this.btnChangeSource_Click); // // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.helpToolStripMenuItem }); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(832, 24); this.menuStrip1.TabIndex = 9; this.menuStrip1.Text = "menuStrip1"; // // helpToolStripMenuItem // this.helpToolStripMenuItem.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; this.helpToolStripMenuItem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.helpToolStripMenuItem.Name = "helpToolStripMenuItem"; this.helpToolStripMenuItem.RightToLeft = System.Windows.Forms.RightToLeft.Yes; this.helpToolStripMenuItem.Size = new System.Drawing.Size(12, 20); this.helpToolStripMenuItem.Click += new System.EventHandler(this.helpToolStripMenuItem_Click); // // ObjectUpdatesForm // this.AutoScaleBaseSize = new System.Drawing.Size(6, 16); this.ClientSize = new System.Drawing.Size(832, 526); this.Controls.Add(this.pnlSqlConnect); this.Controls.Add(this.btnChangeScripting); this.Controls.Add(this.menuStrip1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MainMenuStrip = this.menuStrip1; this.Name = "ObjectUpdatesForm"; this.Text = "Object Updates"; this.Load += new System.EventHandler(this.ObjectUpdatesForm_Load); this.Controls.SetChildIndex(this.menuStrip1, 0); this.Controls.SetChildIndex(this.lnkCheck, 0); this.Controls.SetChildIndex(this.lstUpdates, 0); this.Controls.SetChildIndex(this.btnChangeScripting, 0); this.Controls.SetChildIndex(this.btnUpdate, 0); this.Controls.SetChildIndex(this.btnCancel, 0); this.Controls.SetChildIndex(this.pnlSqlConnect, 0); this.pnlSqlConnect.ResumeLayout(false); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); }