public Main() { InitializeComponent(); this.dataGridView1.DataSource = loadData(); dataGridView1.Columns["Id"].Visible = false; dataGridView1.Columns["Password"].Visible = false; dataGridView1.Columns["CreateTime"].Visible = false; LogicHandle lgH = new LogicHandle(); try { ServiceController serviceObject = lgH.GetServiceObject(); string status = serviceObject.Status.ToString(); if (status == "Running") { label1.Text = "服务已启动!"; //Operate(true); } else { label1.Text = "服务已停止!"; }; } catch (Exception ex) { string exMsg = ex.Message; if (exMsg == "在计算机“.”上没有找到服务 LYSendMessage。") { label1.Text = "服务未安装,请先安装服务!"; }; }; }
private void SevUp_Click(object sender, EventArgs e) { LogicHandle lgH = new LogicHandle(); ServiceController serviceObject = lgH.GetServiceObject(); try { lgH.StarService(serviceObject); label1.Text = "服务已启动!"; } catch (Exception ex) { label1.Text = "启动服务失败:" + ex.Message; }; }
internal void setStatus(string _type) { if (dataGridView1.CurrentCell == null) { return; }; int sltRow = dataGridView1.CurrentCell.RowIndex; string strStatus = dataGridView1.Rows[sltRow].Cells["状态"].Value.ToString(); string strId = dataGridView1.Rows[sltRow].Cells["Id"].Value.ToString(); string strWhere = ""; if ((_type == "启用" && strStatus == "已启用") || (_type == "停用" && strStatus == "未启用")) { Msg("请检查数据行状态", "警告信息", "warning"); return; }; LogicHandle lcH = new LogicHandle(); if (_type == "停用") { strWhere = " SendStatus = 0 WHERE Id = '" + strId + "'"; } else if (_type == "启用") { strWhere = " SendStatus = 1 WHERE Id = '" + strId + "'"; } bool bRst = lcH.Update("[dbo].[CFG_Account]", strWhere); if (bRst) { Msg("状态更新成功。", "提示信息", "ok"); dataGridView1.DataSource = null; dataGridView1.DataSource = loadData(); dataGridView1.Columns["Id"].Visible = false; dataGridView1.Columns["Password"].Visible = false; dataGridView1.Columns["CreateTime"].Visible = false; } else { Msg("状态更新失败,请联系信息管理部。", "提示信息", "error"); } }
internal DataTable loadData() { DataTable dt = new DataTable(); string strSQL = @"SELECT [Id] ,[Spid] AS '企业号' ,[ComName] AS '企业名' ,CASE [Aattribute] WHEN 0 THEN '营销' WHEN 1 THEN '行业' END AS '企业通道' ,[LoginName] AS '登陆名' ,[Password] ,[QueryCNT] AS '流量' ,CASE WHEN [SendStatus] = 0 THEN '未启用' WHEN [SendStatus] = 1 THEN '已启用' END AS '状态' ,[CreateTime] FROM [dbo].[CFG_Account]"; LogicHandle LgH = new LogicHandle(); dt = LgH.GetDataView(strSQL); return dt; }
private void SevDown_Click(object sender, EventArgs e) { LogicHandle lgH = new LogicHandle(); ServiceController serviceObject = lgH.GetServiceObject(); try { lgH.StopService(serviceObject); label1.Text = "服务已停止!"; } catch (Exception ex) { label1.Text = "停止服务发生错误:" + ex.Message.ToString(); }; }
//method #region 按钮事件 //保存 private void btnAccSubmit_Click (object sender, EventArgs e) { bool bRst = false; string strSpid = Spid.Text.Trim(); string strCom = Com.Text.Trim(); string strComName = ComName.Text.Trim(); string strLoginName = LoginName.Text.Trim(); string strPassword = Password.Text.Trim(); string strQueryCNT = QueryCNT.Text.Trim(); string strAattribute = (string)Aattribute.SelectedValue; if (strSpid.Length == 0 || strCom.Length == 0 || strComName.Length == 0 ||strLoginName.Length == 0 || strPassword.Length == 0 || strQueryCNT.Length ==0) { Msg("请将注册信息填写完整", "警告信息", "warning"); return; }; List<string> field = new List<string>(); List<string> value = new List<string>(); field.Add("Spid"); field.Add("Com"); field.Add("LoginName"); field.Add("Password"); field.Add("ComName"); field.Add("QueryCNT"); field.Add("Aattribute"); value.Add(strSpid); value.Add(strCom); value.Add(strLoginName); value.Add(strPassword); value.Add(strComName); value.Add(strQueryCNT); value.Add(strAattribute); LogicHandle lgH = new LogicHandle(); string where = " [Id] = '" + this.strId + "' AND [Aattribute] = '" + strAattribute + "'"; //判断是否已有数据 int iCount = lgH.GetCount("[dbo].[CFG_Account]", where); if (this.bItOrUp)//update { if (iCount > 0) { where += " AND Id = " + this.strId; bRst = lgH.UpdateMany("[dbo].[CFG_Account]", field, value, where); } else { Msg("该企业或此通道不存在。", "警告信息", "warning"); return; }; } else //insert { string queryWhere = " [Spid] = '" + strSpid + "' "; int iCheck = lgH.GetCount("[dbo].[CFG_Account]", queryWhere); if (iCheck == 0) { bRst = lgH.Insert("[dbo].[CFG_Account]", field, value); } else { Msg("该企业号或此通道已存在", "警告信息", "warning"); return; }; }; if (bRst) { //将父窗体传过来 Main main = (Main)this.Owner; main.dataGridView1.DataSource = null; main.dataGridView1.DataSource = main.loadData(); main.dataGridView1.Columns["Id"].Visible = false; main.dataGridView1.Columns["Password"].Visible = false; main.dataGridView1.Columns["CreateTime"].Visible = false; Msg("保存成功。", "提示信息", "ok"); this.Close(); } else { Msg("保存失败,请联系信息管理部。", "错误信息", "error"); this.Close(); } }
internal DataTable loadData(string _strId) { DataTable dt = new DataTable(); LogicHandle lgH = new LogicHandle(); string strSQL = @"SELECT [Id] ,[Com] ,[ComName] ,[Spid] ,[LoginName] ,[Password] ,[QueryCNT] ,[Aattribute] FROM [dbo].[CFG_Account] WHERE [Id] = '" + _strId+"'"; dt = lgH.GetDataView(strSQL); return dt; }