三层架构笔记

1.窗口属性 { IsMdiContainer:True  指定该窗体是否是MDI容器 windowState:Maximized窗口最大化 (4)设置StartPotion:CenterParent  窗口位置居中 (5)Icon:自定义图标 (6)MaximizeBox:False 无最大化选项 (7)FormBorderStyle:FixedSingle  不可改变窗口大小 (8)AcceptButton:btnLogin 按Enter相当于点击登录按钮 (9)CancelButton:btnExit 按Esc相当于点击取消按钮 } 2.窗口登录 { progrom

            FormLogin Flogin = new FormLogin();             if (Flogin.ShowDialog() == DialogResult.OK)             {                 Application.Run(new FormMain());             } } 3.窗体渐渐出现的效果 { timer1控件 Enable;true Interval:100   private void timer1_Tick(object sender, EventArgs e)         {             double i = 0.05;             Opacity += i;         }    } 4.设置mdi窗体 { //1 设置主窗体的ismdicontainer属性 //2 设置要打开的子窗体的mdiparent //3 注意在mdi父窗体中,不能使用showdialog 打开子窗体 //以mdi子窗体的方式打开

在父窗口中 FrmStudent f = FrmStudent.Instance; f.MdiParent = this; f.Show();   //单例模式    当前项目中有且只有该类的一个对象    private static FrmStudent instance;         public static FrmStudent Instance         {             get {    //假如instace没有被创建或者已经被释放,则新建窗口                 if (instance == null || instance.IsDisposed)                 {                     instance = new FrmStudent();                 }                 return instance;             }         }    }      5.清空box中所有的文本框 {             foreach (Control item in gbadd.Controls)             {                 if (item is TextBox)                 {                     TextBox txt = item as TextBox;                     txt.Text = "";                 }             }    } 5.dataGirdView的几个属性 { AutoSizeColunbMode;fill 可见列自动调整大小    AllowUserTOresuzeRows;false不许用户自动调整行的大小 selectionMode:fullRowselect 点中单元格时选择一行 RowHeadersVisible :fasle 取消表头列的显示    }  6.关闭窗口前,提示用户是否真的关闭窗口 {         private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)         {             if (MessageBox.Show("确定退出?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)             {                 e.Cancel = true;             }         } } 7.MD5 {  //计算字符串的md5值         static string GetMd5(string txt)         {             //明文  把字符串转化成字节数组             byte[] buffer = System.Text.Encoding.UTF8.GetBytes(txt);             //计算md5的类             MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();             //加密以后的字节数组             byte[] ctyptBytes=  md5.ComputeHash(buffer);             //把字节数组 转化成 16进制的字符串             string s = "";             for (int i = 0; i < ctyptBytes.Length; i++)             {                 //把每一个字节转化成2位的16进制数                 s += ctyptBytes[i].ToString("x2");             }             return s;         }         //计算文件的md5值         static string GetFileMd5(string path)         {             string s = "";             using (FileStream fs = new FileStream(path,FileMode.Open))             {                 MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();                 byte[] cryptBytes = md5.ComputeHash(fs);

                for (int i = 0; i < cryptBytes.Length; i++)                 {                     s += cryptBytes[i].ToString("x2");                 }             }             return s;         }

} 8.combox {             List<Classes> list = bll.GetAllClasses();             Classes c = new Classes();             c.CName = "请选择";             c.CID = -1;             list.Insert(0,c);  //增加请选择一项

            //如果绑定的泛型集合  要显示的泛型集合中对象的属性             cboSearchClass.DisplayMember = "cName";             cboSearchClass.ValueMember = "cId";             cboSearchClass.DataSource = list; } 9.右键菜单 {         private void resetToolStripMenuItem_Click(object sender, EventArgs e)         {             MessageBox.Show("Test");

                   } } 10.显示地区窗口 {   private void FormChooseArea_Load(object sender, EventArgs e)         {             Stopwatch sw = new Stopwatch();             sw.Start();             LoadParents();             sw.Stop();             MessageBox.Show(sw.ElapsedMilliseconds.ToString());         }         void LoadParents()         {             TreeNode parent = new TreeNode();             parent.Tag = 0;             parent.Text = "全国";             tvAreas.Nodes.Add(parent);             AreasBLL bll = new AreasBLL();             List<Areas> list = bll.GetAllAreas();

            LoadChild(parent,list);             parent.Expand();         }         void LoadChild(TreeNode parent,List<Areas> list)         {             //获取父节点的id             int pid = Convert.ToInt32(parent.Tag);             foreach (Areas item in list)             {                 //找到当前的子节点                 if (item.APid == pid)                 {                     TreeNode tn = new TreeNode();                     tn.Text = item.AName;                     tn.Tag = item.AID;                     parent.Nodes.Add(tn);                     //调用递归方法                     LoadChild(tn, list);                 }             }         }         public string txt = "";         private void btnChoose_Click(object sender, EventArgs e)         {             GetTxt(tvAreas.SelectedNode);

            txt = txt.TrimEnd('-');             if (del != null)             {                 del(txt);                 this.DialogResult = System.Windows.Forms.DialogResult.OK;             }                 }         void GetTxt(TreeNode tn)         {             if (tn.Parent != null)             {                 //递归                 GetTxt(tn.Parent);             }             txt += tn.Text + "-";         }

        private void btnCancel_Click(object sender, EventArgs e)         {             this.Close();         } } 11获得拼音 { static string GetPinYins(string name)         {             string s = "";             //乐文             foreach (char item in name)             {                 if (ChineseChar.IsValidChar(item))                 {                     ChineseChar cc = new ChineseChar(item);                     s += cc.Pinyins[0].TrimEnd('1','2','3','4','5') + " ";                 }                 else                 {                     s += item.ToString();                 }             }             return s;         } }

 

      

posted @ 2012-09-06 22:28  zxp19880910  阅读(150)  评论(0编辑  收藏  举报