在线PDF转换网站集合

Jquery CDN ,

网站加载速度在线监测工具

此实现不是 Windows 平台 FIPS 验证的加密算法的一部分。

17
2015
03

RadGrid 默认多字段分组和选择列

 

 

 

<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI"
                    Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI"
                    Name="Telerik.Web.UI.Common.jQuery.js" />
            </Scripts>
        </telerik:RadScriptManager>

05
2015
03

重构artDialog.prompt方法,让它支持多行文本

 

 

        artDialog.prompt = function (content, yes, value) {
            value = value || '';
            var input;

26
2015
02

C# DataGridView 通过程序对列进行排序

      void SortDatagridview()
        {
            dgvFlux.Columns["State"].HeaderCell.SortGlyphDirection = SortOrder.Ascending;
            dgvFlux.Sort(dgvFlux.Columns["State"], ListSortDirection.Ascending);
        }

26
2015
02

c# winform 鼠标拖动改变控件位置和鼠标拖拽改变空间大小,调用即可



    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    using System.ComponentModel;  
    using System.Data;  
    using System.Drawing;  
    using System.Windows.Forms;  
      
    namespace AllTest  
    {  
        class BarcodeControl  
        {  
            #region private  
      
            private const int MIN_SIZE = 10; //对控件缩放的最小值   
            private const int BOX_SIZE = 7;  //调整大小触模柄方框大小   
      
            public bool _IsCtrlKey = false;  
            private TextBox _textbox;  
            private Control _MControl = null;  
            private bool _IsMouseDown = false;  
            private Point _oPointClicked;  
            private Color BOX_COLOR = Color.White;  
            private Label[] _lbl = new Label[8];  
            private int _startl, _startt, _startw, _starth;  
            private bool _dragging;  
            private Cursor[] _arrArrow = new Cursor[] {Cursors.SizeNWSE, Cursors.SizeNS,   
                                                        Cursors.SizeNESW, Cursors.SizeWE, Cursors.SizeNWSE, Cursors.SizeNS,   
                                                        Cursors.SizeNESW, Cursors.SizeWE};  
     
            #endregion  
     
            #region 构造函数  
      
            /// <summary>   
            /// 构造控件拖动对象   
            /// </summary>   
            /// <param name="moveControl">需要拖动的控件 </param>   
            public BarcodeControl(Control moveControl)  
            {  
                //   
                // TODO: 在此处添加构造函数逻辑   
                //   
                _MControl = moveControl;  
                _MControl.MouseDown += new MouseEventHandler(this.Control_MouseDown);  
                _MControl.MouseUp += new MouseEventHandler(this.Control_MouseUp);  
                _MControl.MouseMove += new MouseEventHandler(this.Control_MouseMove);  
                _MControl.Click += new System.EventHandler(this.Control_Click);  
      
                //构造8个调整大小触模柄   
                for (int i = 0; i < 8; i++)  
                {  
                    _lbl[i] = new Label();  
                    _lbl[i].TabIndex = i;  
                    _lbl[i].FlatStyle = 0;  
                    _lbl[i].BorderStyle = BorderStyle.FixedSingle;  
                    _lbl[i].BackColor = BOX_COLOR;  
                    _lbl[i].Cursor = _arrArrow[i];  
                    _lbl[i].Text = "";  
                    _lbl[i].BringToFront();  
                    _lbl[i].MouseDown += new MouseEventHandler(this.handle_MouseDown);  
                    _lbl[i].MouseMove += new MouseEventHandler(this.handle_MouseMove);  
                    _lbl[i].MouseUp += new MouseEventHandler(this.handle_MouseUp);  
                }  
      
                CreateTextBox();  
                Create();  
      
                //Control_Click((object)sender, (System.EventArgs)e);   
            }  
     
            #endregion  
     
            #region 需拖动控件键盘事件  
      
            private void textBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)  
            {  
                if (e.KeyValue == 37 || e.KeyValue == 38 || e.KeyValue == 39 || e.KeyValue == 40)  
                {  
                    if (e.KeyValue == 37)  
                        _MControl.Left -= 1;  
                    if (e.KeyValue == 38)  
                        _MControl.Top -= 1;  
                    if (e.KeyValue == 39)  
                        _MControl.Left += 1;  
                    if (e.KeyValue == 40)  
                        _MControl.Top += 1;  
                    MoveHandles();  
                    ControlLocality();  
                    _MControl.Visible = true;  
                }  
      
                if (e.KeyValue == 46)  
                {  
                    for (int i = 0; i < 8; i++)  
                    {  
                        _MControl.Parent.Controls.Remove(_lbl[i]);  
                    }  
                    _MControl.Parent.Controls.Remove(_MControl);  
                    _textbox.Parent.Controls.Remove(_textbox);  
                }  
      
                if (e.KeyValue == 17)  
                {  
                    _IsCtrlKey = true;  
                    //MessageBox.Show("a");   
                }  
            }  
     
            #endregion  
     
            #region 需拖动控件鼠标事件  
      
            private void Control_Click(object sender, System.EventArgs e)  
            {  
                _textbox.Focus();  
                _MControl = (sender as Control);  
                MoveHandles();  
      
                if (_IsCtrlKey == false)  
                {  
                    for (int i = 0; i < _MControl.Parent.Controls.Count; i++)  
                    {  
                        if (_MControl.Parent.Controls[i].Text.Trim().Length == 0 && _MControl.Parent.Controls[i] is Label)  
                        {  
                            _MControl.Parent.Controls[i].Visible = false;  
                        }  
                    }  
                }  
            }  
            private void Control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)  
            {  
                _IsMouseDown = true;  
                _oPointClicked = new Point(e.X, e.Y);  
                for (int i = 0; i < 8; i++)  
                {  
                    _MControl.Parent.Controls.Add(_lbl[i]);  
                    _lbl[i].BringToFront();  
                }  
                HideHandles();  
            }  
      
            private void Control_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)  
            {  
                _IsMouseDown = false;  
                MoveHandles();  
                ShowHandles();  
                _MControl.Visible = true;  
            }  
      
            private void Control_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)  
            {  
                if (_IsMouseDown)  
                {  
                    int l = _MControl.Left + (e.X - _oPointClicked.X);  
                    int t = _MControl.Top + (e.Y - _oPointClicked.Y);  
                    int w = _MControl.Width;  
                    int h = _MControl.Height;  
                    l = (l < 0) ? 0 : ((l + w > _MControl.Parent.ClientRectangle.Width) ?  
                        _MControl.Parent.ClientRectangle.Width - w : l);  
                    t = (t < 0) ? 0 : ((t + h > _MControl.Parent.ClientRectangle.Height) ?  
                        _MControl.Parent.ClientRectangle.Height - h : t);  
                    _MControl.Left = l;  
                    _MControl.Top = t;  
                    ControlLocality();  
                }  
                //_MControl.Cursor=Cursors.SizeAll;   
            }  
     
            #endregion  
            #region 调整大小触模柄鼠标事件  
      
            private void handle_MouseDown(object sender, MouseEventArgs e)  
            {  
                _dragging = true;  
                _startl = _MControl.Left;  
                _startt = _MControl.Top;  
                _startw = _MControl.Width;  
                _starth = _MControl.Height;  
                HideHandles();  
            }  
            // 通过触模柄调整控件大小   
            //    0  1  2   
            //  7      3   
            //  6  5  4   
            private void handle_MouseMove(object sender, MouseEventArgs e)  
            {  
                int l = _MControl.Left;  
                int w = _MControl.Width;  
                int t = _MControl.Top;  
                int h = _MControl.Height;  
                if (_dragging)  
                {  
                    switch (((Label)sender).TabIndex)  
                    {  
                        //l算法:控件左边X坐标 + 鼠标在触模柄X坐标 < 控件左边X坐标 + 父控件宽度 - 控件大小 ?控件左边X坐标 + 鼠标在触模柄X坐标 :控件左边X坐标 + 父控件宽度 - 控件大小    
                        //t算法:   
                        //w算法:   
                        //h算法:   
                        case 0: // _dragging top-left sizing box   
                            l = _startl + e.X < _startl + _startw - MIN_SIZE ? _startl + e.X : _startl + _startw - MIN_SIZE;  
                            t = _startt + e.Y < _startt + _starth - MIN_SIZE ? _startt + e.Y : _startt + _starth - MIN_SIZE;  
                            w = _startl + _startw - _MControl.Left;  
                            h = _startt + _starth - _MControl.Top;  
                            break;  
                        case 1: // _dragging top-center sizing box   
                            t = _startt + e.Y < _startt + _starth - MIN_SIZE ? _startt + e.Y : _startt + _starth - MIN_SIZE;  
                            h = _startt + _starth - _MControl.Top;  
                            break;  
                        case 2: // _dragging top-right sizing box   
                            w = _startw + e.X > MIN_SIZE ? _startw + e.X : MIN_SIZE;  
                            t = _startt + e.Y < _startt + _starth - MIN_SIZE ? _startt + e.Y : _startt + _starth - MIN_SIZE;  
                            h = _startt + _starth - _MControl.Top;  
                            break;  
                        case 3: // _dragging right-middle sizing box   
                            w = _startw + e.X > MIN_SIZE ? _startw + e.X : MIN_SIZE;  
                            break;  
                        case 4: // _dragging right-bottom sizing box   
                            w = _startw + e.X > MIN_SIZE ? _startw + e.X : MIN_SIZE;  
                            h = _starth + e.Y > MIN_SIZE ? _starth + e.Y : MIN_SIZE;  
                            break;  
                        case 5: // _dragging center-bottom sizing box   
                            h = _starth + e.Y > MIN_SIZE ? _starth + e.Y : MIN_SIZE;  
                            break;  
                        case 6: // _dragging left-bottom sizing box   
                            l = _startl + e.X < _startl + _startw - MIN_SIZE ? _startl + e.X : _startl + _startw - MIN_SIZE;  
                            w = _startl + _startw - _MControl.Left;  
                            h = _starth + e.Y > MIN_SIZE ? _starth + e.Y : MIN_SIZE;  
                            break;  
                        case 7: // _dragging left-middle sizing box   
                            l = _startl + e.X < _startl + _startw - MIN_SIZE ? _startl + e.X : _startl + _startw - MIN_SIZE;  
                            w = _startl + _startw - _MControl.Left;  
                            break;  
                    }  
                    l = (l < 0) ? 0 : l;  
                    t = (t < 0) ? 0 : t;  
                    _MControl.SetBounds(l, t, w, h);  
                }  
            }  
      
            private void handle_MouseUp(object sender, MouseEventArgs e)  
            {  
                _dragging = false;  
                MoveHandles();  
                ShowHandles();  
            }  
     
            #endregion  
     
            #region private方法  
      
            private void Create()  
            {  
                //_IsMouseDown = true;   
                //_oPointClicked = new Point(e.X,e.Y);   
                for (int i = 0; i < 8; i++)  
                {  
                    _MControl.Parent.Controls.Add(_lbl[i]);  
                    _lbl[i].BringToFront();  
                }  
                HideHandles();  
            }  
      
            private void CreateTextBox()  
            {  
                _textbox = new TextBox();  
                _textbox.CreateControl();  
                _textbox.Parent = _MControl.Parent;  
                _textbox.Width = 0;  
                _textbox.Height = 0;  
                _textbox.TabStop = true;  
                _textbox.KeyDown += new System.Windows.Forms.KeyEventHandler(textBox_KeyDown);  
            }  
      
            private void ControlLocality()  
            {  
                if (_MControl.Location.X < 0)  
                {  
                    _MControl.Visible = false;  
                    _MControl.Left = 0;  
                }  
                if (_MControl.Location.Y < 0)  
                {  
                    _MControl.Visible = false;  
                    _MControl.Top = 0;  
                }  
                if (_MControl.Location.X + _MControl.Width > _MControl.Parent.Width)  
                {  
                    _MControl.Visible = false;  
                    _MControl.Left = _MControl.Parent.Width - _MControl.Width;  
                }  
                if (_MControl.Location.Y + _MControl.Height > _MControl.Parent.Height)  
                {  
                    _MControl.Visible = false;  
                    _MControl.Top = _MControl.Parent.Height - _MControl.Height;  
                }  
            }  
      
            private void HideHandles()  
            {  
                for (int i = 0; i < 8; i++)  
                {  
                    _lbl[i].Visible = false;  
                }  
            }  
      
            private void MoveHandles()  
            {  
                int sX = _MControl.Left - BOX_SIZE;  
                int sY = _MControl.Top - BOX_SIZE;  
                int sW = _MControl.Width + BOX_SIZE;  
                int sH = _MControl.Height + BOX_SIZE;  
                int hB = BOX_SIZE / 2;  
                int[] arrPosX = new int[] {sX+hB, sX + sW / 2, sX + sW-hB, sX + sW-hB,   
                                              sX + sW-hB, sX + sW / 2, sX+hB, sX+hB};  
                int[] arrPosY = new int[] {sY+hB, sY+hB, sY+hB, sY + sH / 2, sY + sH-hB,   
                                              sY + sH-hB, sY + sH-hB, sY + sH / 2};  
                for (int i = 0; i < 8; i++)  
                {  
                    _lbl[i].SetBounds(arrPosX[i], arrPosY[i], BOX_SIZE, BOX_SIZE);  
                }  
            }  
      
            private void ShowHandles()  
            {  
                if (_MControl != null)  
                {  
                    for (int i = 0; i < 8; i++)  
                    {  
                        _lbl[i].Visible = true;  
                    }  
                }  
            }  
     
            #endregion   
        }  
    }  

05
2015
02

C# 检测ftp服务器是否存在目录,不存在就创建ftp目录

 

using System.Net;
using System.Net.Sockets;

        /// <summary>
        /// 检测目录是否存在
        /// </summary>
        /// <param name="ServerIP"></param>
        /// <param name="pFtpUserID"></param>
        /// <param name="pFtpPW"></param>
        /// <param name="FileSource"></param>
        /// <param name="FileCategory"></param>
        /// <returns></returns>
        public static bool checkDirectory(string ServerIP, string pFtpUserID, string pFtpPW, string FileSource, string FileCategory)
        {
            //检测目录是否存在
            Uri uri = new Uri("ftp://" + ServerIP + "/" + FileSource + "/");
            if (!DirectoryIsExist(uri, pFtpUserID, pFtpPW))
            {
                //创建目录
                uri = new Uri("ftp://" + ServerIP + "/" + FileSource);
                if (CreateDirectory(uri, pFtpUserID, pFtpPW))
                {
                    //检测下一级目录是否存在
                    uri = new Uri("ftp://" + ServerIP + "/" + FileSource + "/" + FileCategory + "/");
                    if (!DirectoryIsExist(uri, pFtpUserID, pFtpPW))
                    {
                        //创建目录
                        uri = new Uri("ftp://" + ServerIP + "/" + FileSource + "/" + FileCategory);
                        if (CreateDirectory(uri, pFtpUserID, pFtpPW))
                        {
                            return true;
                        }
                        else { XtraMessageBox.Show("创建目录:{0}失败", FileCategory); return false; }
                    }
                    else
                    {
                        return true;
                    }
                }
                else { XtraMessageBox.Show("创建目录:{0}失败", FileSource); return false; }
            }
            else
            {
                //检测下一级目录是否存在
                uri = new Uri("ftp://" + ServerIP + "/" + FileSource + "/" + FileCategory + "/");
                if (!DirectoryIsExist(uri, pFtpUserID, pFtpPW))
                {
                    //创建目录
                    uri = new Uri("ftp://" + ServerIP + "/" + FileSource + "/" + FileCategory);
                    if (CreateDirectory(uri, pFtpUserID, pFtpPW))
                    {
                        return true;
                    }
                    else { XtraMessageBox.Show("创建目录:{0}失败", FileCategory); return false; }
                }
                else
                {
                    return true;
                }
            }
        }
        /// <summary>
        /// ftp创建目录(创建文件夹)
        /// </summary>
        /// <param name="IP">IP服务地址</param>
        /// <param name="UserName">登陆账号</param>
        /// <param name="UserPass">密码</param>
        /// <param name="FileSource"></param>
        /// <param name="FileCategory"></param>
        /// <returns></returns>
        public static bool CreateDirectory(Uri IP, string UserName, string UserPass)
        {
            try
            {
                FtpWebRequest FTP = (FtpWebRequest)FtpWebRequest.Create(IP);
                FTP.Credentials = new NetworkCredential(UserName, UserPass);
                FTP.Proxy = null;
                FTP.KeepAlive = false;
                FTP.Method = WebRequestMethods.Ftp.MakeDirectory;
                FTP.UseBinary = true;
                FtpWebResponse response = FTP.GetResponse() as FtpWebResponse;
                response.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 检测目录是否存在
        /// </summary>
        /// <param name="pFtpServerIP"></param>
        /// <param name="pFtpUserID"></param>
        /// <param name="pFtpPW"></param>
        /// <returns>false不存在,true存在</returns>
        public static bool DirectoryIsExist(Uri pFtpServerIP, string pFtpUserID, string pFtpPW)
        {
            string[] value = GetFileList(pFtpServerIP, pFtpUserID, pFtpPW);
            if (value == null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public static string[] GetFileList(Uri pFtpServerIP, string pFtpUserID, string pFtpPW)
        {
            StringBuilder result = new StringBuilder();
            try
            {
                FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(pFtpServerIP);
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(pFtpUserID, pFtpPW);
                reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

05
2015
02

C#操作Ftp上传,下载,删除文件,创建目录,删除目录,获得文件列表

 


using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Windows.Forms;

namespace ConvertData
{
    class FtpUpDown
    {
        string ftpServerIP;
        string ftpUserID;
        string ftpPassword;
        FtpWebRequest reqFTP;
        private void Connect(String path)//连接ftp
        {
            // 根据uri创建FtpWebRequest对象
            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(path));
            // 指定数据传输类型
            reqFTP.UseBinary = true;
            // ftp用户名和密码
            reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
        }

21
2015
01

C#循环中使用Random生成随机数有重复问题

 


如果在高并发的情况下,Random类所取到的系统时钟种子接近甚至完全一样,就很有可能出现重复,这里用循环来举例

for (int i = 0; i < 10; i++)
{
    Random rd = new Random();  //无参即为使用系统时钟为种子
    Console.WriteLine(rd.Next().ToString());
}

17
2015
01

Winform的comboBox控件自适应内容宽度

 


    public class MyComboBox : ComboBox
    {
        protected override void OnDropDown(EventArgs e)
        {
            base.OnDropDown(e);
            AdjustComboBoxDropDownListWidth();  //调整comboBox的下拉列表的大小
        }

10
2015
01

VBS脚本直接把值写入Wincc控件的Text

 

 

一: 不使用变量单纯的操作界面
1.操作某个画面中控件的属性 如 Home1.Pdl(总窗体) 下的 画面窗口2(画面窗口)
Sub OnClick(ByVal Item)
Dim objCircle
Dim screenname
Dim pwname
Set objCircle= ScreenItems("圆1" )
objCircle.Radius = 60
Set screenname=HMIRuntime.Screens("Home1") //获取要操作的窗体
Set pwname=screenname.ScreenItems("画面窗口2") //获取要操作的控件,这里填入你要操作的控件名
MsgBox(objCircle.Radius) //输出圆的半径
MsgBox (pwname.Picturename) //输出当前画面窗口2的名字
End Sub

10
2015
01

采用VBS脚本向Wincc变量中写值

 

Wincc6包含了VBS脚本编程,对于我等熟悉VB编程的可谓带来的福音,但是,由于西门子的C脚本编程功能实在太强大,加上要保持以前版本的一致性和用户编程习惯的延伸性,所以对于VBS脚本并没有太多的介绍。

    这里我先来介绍一下Wincc中对于控件引用的一般性论述。Wincc对于控件引用一般都采取定义变量-》使用Set 变量 =对象.(方法或属性)->引用变量来做的。

    在变量读取或写入的过程中,我们要接触到一些属性和方法,例如,Read和Write方法,变量的Value属性,熟练掌握这些属性和方法相当重要。

    下面解释一下Write和Read方法的语法:

Read data   其中data是读取变量的方法,如果data=1,直接从AS系统读取,相当于C脚本中的Get*****wait()函数,如果省略,则从Wincc变量管理器中建立的变量中读取。

Write data,1  其中data是需要写入变量的数值,1代表直接写入AS系统,相当于C脚本中的Set*****wait()函数,1省略,则写入到由Wincc变量管理器建立的变量中去。

实例: 
读取变量的方法:

 Dim objTag
   Set objTag=HMIRunTime.Tags("变量名")
   objTag.Read

 HMIRunTime.Tags("变量名").Read

如果以上例程改成直接读取AS系统变量的话,程序为:

 Dim objTag
   Set objTag=HMIRunTime.Tags("变量名")
   objTag.Read,1

 HMIRunTime.Tags("变量名").Read,1

写变量的方法:
 Dim objTag
   Set objTag=HMIRunTime.Tags("变量名")
   objTag.Write    '向变量写入数值1
  '也可以写为  objTag.Write 10   向变量写入数值10

 HMIRunTime.Tags("变量名").Write 1
  '也可以写为  objTag.Write 10

除了以上方法外,你也可以将一个中间变量的值写入:
  Dim objTag,val
  Set objTag=HMIRunTime.Tags("变量名")
  objTag.Read
  val=objTag.Value  '中间变量val存放了变量的值
  objtag.Write val   '写入变量中去

当然,其余的方法还有很多,这些都需要自己在编程过程中总结和灵活运用。