public bool OutFile(string fullPath, string content) { bool flag = false; try { this.response.Clear(); this.response.Buffer = true; this.response.Charset = Encoding.Default.BodyName; this.response.ContentEncoding = Encoding.GetEncoding("GB2312"); this.response.AppendHeader("content-Disposition", "attachment;filename=" + fullPath); this.response.ContentType = "application/ms-excel"; this.response.Output.Write(content); this.response.Flush(); flag = true; } catch (Exception exception) { MyControl_MessageBox.Msg(string.Format("输出数据CSV出错:{0}", exception.Message)); flag = false; } finally { HttpContext.Current.Response.Close(); } return(flag); }
internal static DataTable GetModelDataTable(string connStr, string tableName, string fileName, string procName, string whereFieldName, string whereValue, List <EditFieldParam> fieldList) { connStr = (ConfigurationManager.ConnectionStrings[connStr] == null) ? null : ConfigurationManager.ConnectionStrings[connStr].ConnectionString; if ((string.IsNullOrEmpty(procName) && string.IsNullOrEmpty(tableName)) || ((string.IsNullOrEmpty(connStr) || string.IsNullOrEmpty(connStr.Split(new char[] { ';' })[0].Split(new char[] { '=' })[1])) || ((string.IsNullOrEmpty(connStr.Split(new char[] { ';' })[1].Split(new char[] { '=' })[1]) || (fieldList == null)) || (fieldList.Count == 0)))) { return(null); } if (!string.IsNullOrEmpty(whereValue) && ((whereValue.Contains("<") || whereValue.Contains(">")) || whereValue.Contains("'"))) { throw new ArgumentException("包含有特殊符号!", "whereValue"); } if ((HttpContext.Current != null) && !string.IsNullOrEmpty(HttpContext.Current.Request.Form["txtEdit"])) { if (HttpContext.Current.Request.Form["txtEdit"].Equals("edit", StringComparison.OrdinalIgnoreCase) && (UpdateOrInsert(connStr, tableName, procName, fieldList, whereFieldName, whereValue, "edit") > 0)) { MyControl_MessageBox.Msg("修改成功!"); } if (HttpContext.Current.Request.Form["txtEdit"].Equals("add", StringComparison.OrdinalIgnoreCase) && (UpdateOrInsert(connStr, tableName, procName, fieldList, whereFieldName, whereValue, "add") > 0)) { MyControl_MessageBox.Redirect("新增成功!", fileName + "Edit.aspx"); } } if (string.IsNullOrEmpty(whereFieldName) || string.IsNullOrEmpty(whereValue)) { return(null); } return(MyControl_SqlHelper.ExecuteDataset(connStr, CommandType.Text, "SELECT * FROM " + tableName + " WHERE " + whereFieldName + "='" + whereValue + "'", new SqlParameter[0]).Tables[0]); }
// Methods private static void Execute(string delName, string connStr, string tableName, string procName, bool isRealDel, string delFieldName, string delFieldValue, string editWhereField, bool IsCustom, string delUpdateTimeField, string tn) { string str = tableName.ToUpper().Replace("WITH(NOLOCK)", ""); if (!string.IsNullOrEmpty(procName)) { SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@" + editWhereField, HttpContext.Current.Request.Form["txtDel" + tn + editWhereField]) }; if (MyControl_SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, procName, commandParameters) > 0) { MyControl_MessageBox.Msg(delName + "成功!"); } } else if (!isRealDel) { SqlParameter[] parameterArray2 = null; parameterArray2 = new SqlParameter[] { new SqlParameter("@1", delFieldValue), new SqlParameter("@2", HttpContext.Current.Request.Form["txtDel" + tn + editWhereField]) }; if (IsCustom) { parameterArray2 = new SqlParameter[] { new SqlParameter("@1", HttpContext.Current.Request.Form["txtCustom" + tn]), new SqlParameter("@2", HttpContext.Current.Request.Form["txtDel" + tn + editWhereField]) }; } if (MyControl_SqlHelper.ExecuteNonQuery(connStr, CommandType.Text, " update " + str + " set " + delFieldName + "=@1" + (string.IsNullOrEmpty(delUpdateTimeField) ? "" : (", " + delUpdateTimeField + "=getdate()")) + " where " + editWhereField + "=@2", parameterArray2) > 0) { if (IsCustom) { delName = "操作"; } MyControl_MessageBox.Msg(delName + "成功!"); } } else { SqlParameter[] parameterArray3 = new SqlParameter[] { new SqlParameter("@1", HttpContext.Current.Request.Form["txtDel" + tn + editWhereField]) }; if (MyControl_SqlHelper.ExecuteNonQuery(connStr, CommandType.Text, " delete from " + str + " where " + editWhereField + "=@1", parameterArray3) > 0) { MyControl_MessageBox.Msg("彻底删除成功!"); } } }
/// <summary> /// Gets the connection string. /// </summary> /// <param name="zoneName">Name of the zone.</param> /// <param name="strDbType">Type of the db.</param> /// <returns></returns> public string GetConnectionString(string zoneName, string strDbType) { if (string.IsNullOrEmpty(zoneName)) { MyControl_MessageBox.Msg("区名不能为空"); return(""); } string key = BuildKey(zoneName, strDbType); if (_connectionDic.ContainsKey(key)) { return(_connectionDic[key]); } else { //如果没有对应区的连接就获取默认区 key = BuildKey("Share", strDbType); if (_connectionDic.ContainsKey(key)) { return(_connectionDic[key]); } return(string.Empty); } }
private void InitCache(string userName) { _userName = userName; var connstring = ConfigurationManager.ConnectionStrings["Games.NBall.Dal.Properties.Settings.NB_ConfigConnectionString"].ConnectionString; if (string.IsNullOrEmpty(connstring)) { MyControl_MessageBox.Msg("未找到名称为[NB_ConfigConnectionString]的连接串"); return; } _zoneList = new List <StatusList>(); var zoneDataSet = MyControl_SqlHelper.ExecuteDataset(connstring, CommandType.Text, "Select * From All_Zoneinfo"); if (zoneDataSet == null || zoneDataSet.Tables.Count <= 0) { MyControl_MessageBox.Msg("获取区服配置失败"); return; } string userPlatforms = ""; _isAdmin = true; if (!string.IsNullOrEmpty(userName)) { var plat = MyControl_SqlHelper.ExecuteScalar(connstring, CommandType.Text, "Select PlatformString From AUTH_UserPlatform Where UserName='******'"); if (plat != null) { userPlatforms = plat.ToString(); _isAdmin = false; } } _zoneIdDic = new Dictionary <string, int>(); foreach (DataRow row in zoneDataSet.Tables[0].Rows) { if (!string.IsNullOrEmpty(userPlatforms)) { var code = row["PlatformCode"].ToString(); if (!userPlatforms.Contains(code)) { continue; } } _zoneIdDic.Add(row["ZoneName"].ToString().ToLower(), Convert.ToInt32(row["Idx"])); _zoneList.Add(new StatusList(row["ZoneName"].ToString(), row["Name"].ToString())); } //_zoneHtml = GenFieldWhereSelectHtml("SZone",_zoneList); _connectionDic = new Dictionary <string, string>(); var dataset = MyControl_SqlHelper.ExecuteDataset(connstring, CommandType.Text, "Select * From All_Database"); if (dataset == null || dataset.Tables.Count <= 0) { MyControl_MessageBox.Msg("获取数据库配置失败"); return; } foreach (DataRow row in dataset.Tables[0].Rows) { try { string key = BuildKey(row["ZoneName"].ToString(), row["DBType"].ToString()); string connectString = BuildConnectString(row); _connectionDic.Add(key, connectString); } catch (Exception ex) { throw; } } _allZoneList = new List <StatusList>(); _allZoneList.Add(new StatusList("0", "所有区")); foreach (var entity in _zoneList) { _allZoneList.Add(new StatusList(entity.Value, entity.Text)); } }