Exemplo n.º 1
0
        public static string TokenStr()
        {
            var jsonStr = GetHTML("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx7f141ebca00734c2&secret=67178d423e17a75e4c9444d587160027");

            return(StringPlus.GetTwoMiddleFirstStr(jsonStr, "\"access_token\":\"", "\",\"expires_in"));
        }
Exemplo n.º 2
0
 /// <summary>
 /// 控件点击 消息确认提示框
 /// </summary>
 /// <param name="Control"></param>
 /// <param name="msg"></param>
 public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
 {
     //Control.Attributes.Add("onclick", "return confirm('" + StringPlus.JSStringFormat(msg,false) + "');");
     AddJSAttrib(Control, "onclick", "return confirm('" + StringPlus.JSStringFormat(msg, false) + "');");
 }
Exemplo n.º 3
0
 /// <summary>
 /// WebControl(UpdatePanel)中显示一消息
 /// </summary>
 /// <param name="webControl"></param>
 /// <param name="msg"></param>
 public static void ShowAjaxMsg(System.Web.UI.WebControls.WebControl webControl, string msg)
 {
     RegisterAjaxJS(webControl, "alert(\"" + StringPlus.JSStringFormat(msg, false) + "\");", true);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 显示消息提示对话框,页面加载开始后
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg"></param>
        public static void ShowMsg(System.Web.UI.Page page, string msg)
        {
            string script = "<script type='text/javascript' language='javascript'>alert('" + StringPlus.JSStringFormat(msg, false) + "');</script>";

            //page.Response.Write();
            ResponseWriteJS(page, script);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取不会重复的编码
        /// </summary>
        /// <returns></returns>
        public static string GetNowDifString()
        {
            string s = GetString(DateTime.Now);

            return(s + "" + StringPlus.GetRandomNext(5));
        }
Exemplo n.º 6
0
 /// <summary>
 /// 返回当前系统日期的标准格式 yyyy-MM-dd
 /// </summary>
 public static string GetShortDate(object obj)
 {
     return(StringPlus.ConverTValue <DateTime>(obj, DateTime.Now, Convert.ToDateTime).ToString("yyyy-MM-dd"));
 }
Exemplo n.º 7
0
        /// <summary>
        /// 回发验证码图片 [随机字体随机颜色]
        /// </summary>
        /// <param name="context"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="chkStr"></param>
        public static void ResopnseColorImage(System.Web.HttpContext context, int width, int height, string chkStr)
        {
            Bitmap   newMap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            Graphics g      = Graphics.FromImage(newMap);

            g.Clear(Color.LightCyan);

            Random random = new Random();
            int    i;

            for (i = 0; i < 120; i++)//25
            {
                int x = random.Next(newMap.Width);
                int y = random.Next(newMap.Height);
                g.DrawPie(new Pen(Color.LightGray), x, y, 6, 6, 1, 1);
            }

            //输出不同字体和颜色的验证码字符
            for (i = 0; i < chkStr.Length; i++)
            {
                int  cindex  = random.Next(8);
                int  findex  = random.Next(6);
                int  fs      = random.Next(2);
                Font fs_font = new System.Drawing.Font(FontConsts[findex], 12,
                                                       fs == 0 ? System.Drawing.FontStyle.Bold : FontStyle.Italic | FontStyle.Bold);

                int ii = 4;
                if ((i + 1) % 2 == 0)
                {
                    ii = 2;
                }
                string tmpstr = chkStr.Substring(i, 1);

                //Brush b = new System.Drawing.SolidBrush(ColorConsts[cindex]);
                System.Drawing.Drawing2D.LinearGradientBrush b = new LinearGradientBrush(new RectangleF((i * (StringPlus.GetStrByteLength(tmpstr) > 1 ? 20 : 13)), 0, width / 2, height), ColorConsts[cindex], ColorConsts[ii], 1.5F, true);

                g.DrawString(tmpstr, fs_font, b, (i * (StringPlus.GetStrByteLength(tmpstr) > 1 ? 22 : 13)), 0);//
            }

            //画一个边框
            g.DrawRectangle(new Pen(Color.LightGray), 0, 0, newMap.Width - 1, newMap.Height - 1);
            //输出到浏览器
            //System.IO.MemoryStream ms = new System.IO.MemoryStream();
            newMap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);//ms
            //context.Response.ClearContent();
            //context.Response.ContentType = "image/Jpeg";
            //context.Response.BinaryWrite(ms.ToArray());
            g.Dispose();
            newMap.Dispose();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 将内存中的DataTable转成Excel
        /// </summary>
        /// <param name="excelSavePath">Excel保存路径</param>
        /// <param name="sourceTable">内存中的DataTable</param>
        /// <param name="sheetName">在Excel中保存的Sheet名称</param>
        public static void Table2Excel(string excelSavePath, DataTable tb, string tbname)
        {
            FileString.FileDel2(excelSavePath);
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelSavePath + ";" + "Extended Properties=Excel 8.0;";

            using (OleDbConnection connex = new OleDbConnection(strConn))
            {
                connex.Open();
                string ct = "CREATE TABLE " + tbname + " (";                //以下生成一个sql命令向excel中插入一个表
                foreach (DataColumn clmn in tb.Columns)
                {
                    switch (clmn.DataType.Name)                                     //根据不同数据类型分别处理
                    {
                    case "Decimal":
                        ct += clmn.ColumnName + " Decimal,";
                        break;

                    case "Double":
                        ct += clmn.ColumnName + " Double,";
                        break;

                    default:
                        ct += clmn.ColumnName + " NTEXT,";
                        break;
                    }
                }
                ct = ct.Substring(0, ct.Length - 1) + ")";
                OleDbCommand cmd1 = new OleDbCommand(ct, connex);
                cmd1.ExecuteNonQuery();                                                              //向excel中插入一个表

                foreach (DataRow r in tb.Rows)                                                       //下面向excel中一行一行写入数据
                {
                    string fs = "", vs = "";
                    foreach (DataColumn clmn in tb.Columns)
                    {
                        fs += clmn.ColumnName + ",";
                        if (r[clmn.ColumnName] == DBNull.Value)
                        {
                            vs += "null,";
                            continue;
                        }
                        switch (clmn.DataType.Name)                                                   //根据不同数据类型分别处理
                        {
                        case "Decimal":
                            vs += ((decimal)r[clmn.ColumnName]).ToString("0.00") + ",";
                            break;

                        case "Double":
                            vs += ((double)r[clmn.ColumnName]).ToString("0.00") + ",";
                            break;

                        case "DateTime":
                            vs += "'" + ((DateTime)r[clmn.ColumnName]).ToShortDateString() + "',";
                            break;

                        default:
                            vs += "'" + StringPlus.DanYinHao(r[clmn.ColumnName].ToString()) + "',";
                            break;
                        }
                    }
                    string       sqlstr = "insert into [" + tbname + "$] (" + fs.Substring(0, fs.Length - 1) + ") values (" + vs.Substring(0, vs.Length - 1) + ")";
                    OleDbCommand cmd    = new OleDbCommand(sqlstr, connex);
                    cmd.ExecuteNonQuery();                                            //向excel中插入数据
                }
                connex.Close();
            }
        }