예제 #1
0
        private void downloadFile(object objFolder)
        {
            int    BufferLen      = 4096;
            string folder         = objFolder.ToString();
            string file           = string.Empty;
            string fileServiceUrl = string.Empty;

            using (BugTraceEntities zentity = new BugTraceEntities(EntityContextHelper.GetEntityConnString()))
            {
                var currVersion = zentity.SYS_Version.Where(p => p.IsDefault == 1).FirstOrDefault();
                file           = currVersion.FilePath;
                fileServiceUrl = currVersion.FileServiceUrlPort;
            }
            string fileName     = Path.GetFileName(file);
            Stream sourceStream = null;

            try
            {
                EndpointAddress address = new EndpointAddress("http://" + fileServiceUrl + "/JAJ.WinServer/FileService");
                FileTransferSvc.FileServiceClient _client = new FileTransferSvc.FileServiceClient("BasicHttpBinding_IFileService", address);
                sourceStream = _client.DowndloadFile(file);
            }
            catch (Exception ex)
            {
                this.Invoke(new MethodInvoker(() =>
                {
                    WaitForm.Close();
                    MessageBox.Show("下载客户端失败!");
                }));
                MyLog.LogError("下载客户端失败!", ex);
                return;
            }

            FileStream targetStream = null;

            if (!sourceStream.CanRead)
            {
                MyLog.LogError("下载异常", new Exception("Invalid Stream!"));
                throw new Exception("Invalid Stream!");
            }
            string filePath = Path.Combine(folder, fileName);

            using (targetStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                byte[] buffer = new byte[BufferLen];
                int    count  = 0;
                while ((count = sourceStream.Read(buffer, 0, BufferLen)) > 0)
                {
                    targetStream.Write(buffer, 0, count);
                }
                targetStream.Close();
                sourceStream.Close();
            }
            this.Invoke(new MethodInvoker(() =>
            {
                WaitForm.Close();
                MessageBox.Show("下载成功,请使用最新下载的客户端,谢谢!");
                this.Close();
            }));
        }
예제 #2
0
파일: FrmIndex.cs 프로젝트: posjaj/BugTrace
 private void btnSaveProjectInfo_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("您确定要更新当前项目信息吗?", "提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
     {
         using (BugTraceEntities context = new BugTraceEntities(EntityContextHelper.GetEntityConnString()))
         {
             var projectCode = UserInfo.GetInstence().DefaultProjectCode;
             if (!string.IsNullOrWhiteSpace(projectCode))
             {
                 var projectInfo = context.PPM_ProjectInfo.Where(p => p.ProjectCode == projectCode).FirstOrDefault();
                 if (projectInfo != null)
                 {
                     projectInfo.ProjectName   = txtCurrProjectName.Text;
                     projectInfo.SVN           = txtSVN.Text;
                     projectInfo.DevServerInfo = txtDevServerInfo.Text;
                     projectInfo.PubServerInfo = txtPubServerInfo.Text;
                     projectInfo.OtherInfo     = txtOtherInfo.Text;
                     projectInfo.UpdateDate    = DateTime.Now;
                     projectInfo.UpdatePerson  = UserInfo.GetInstence().UserCode;
                     context.SaveChanges();
                     MessageBox.Show("保存项目信息成功!");
                 }
             }
         }
     }
 }
예제 #3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            using (BugTraceEntities context = new BugTraceEntities(EntityContextHelper.GetEntityConnString()))
            {
                #region 动态创建菜单
                var menuList  = context.SYS_Menu.ToList();
                var firstMenu = menuList.Where(p => p.SortGrade == 1);
                foreach (var item in firstMenu.OrderBy(p => p.OrderCode))
                {
                    if (item.HasNext == 0)
                    {
                        ToolStripMenuItem menu = new ToolStripMenuItem();
                        menu.Text   = item.MenuName;
                        menu.Tag    = item.FormModule + "." + item.FormName;
                        menu.Click += menu_Click;
                        this.menuStrip1.Items.Add(menu);
                    }
                    else
                    {
                        ToolStripMenuItem menu2 = new ToolStripMenuItem();
                        menu2.Text = item.MenuName;
                        var secMenu = menuList.Where(p => p.ParentCode == item.MenuCode);
                        foreach (var itemChild in secMenu)
                        {
                            ToolStripMenuItem menu = new ToolStripMenuItem();
                            menu.Text   = itemChild.MenuName;
                            menu.Tag    = itemChild.FormModule + "." + itemChild.FormName;
                            menu.Click += menu_Click;
                            menu2.DropDownItems.Add(menu);
                        }
                        this.menuStrip1.Items.Add(menu2);
                    }
                }
                ToolStripMenuItem menuHelp = new ToolStripMenuItem();
                menuHelp.Text = "帮助(&H)";
                ToolStripMenuItem menuBrief = new ToolStripMenuItem();
                menuBrief.Text   = "简要说明";
                menuBrief.Click += menuBrief_Click;
                menuHelp.DropDownItems.Add(menuBrief);
                ToolStripMenuItem menuAbout = new ToolStripMenuItem();
                menuAbout.Text   = "关于";
                menuAbout.Click += menuAbout_Click;
                menuHelp.DropDownItems.Add(menuAbout);
                this.menuStrip1.Items.Add(menuHelp);
                #endregion
            }

            this.lblCurrentUser.Text = "当前用户:" + UserInfo.GetInstence().UserName;

            //打开问题跟踪
            //openMenu("PPM", "ProjectPlanList");
            //打开首页
            openMenu(null, "FrmIndex");
        }
예제 #4
0
파일: FrmIndex.cs 프로젝트: posjaj/BugTrace
 public void RefreshProjectInfo()
 {
     using (BugTraceEntities context = new BugTraceEntities(EntityContextHelper.GetEntityConnString()))
     {
         var projectCode = UserInfo.GetInstence().DefaultProjectCode;
         if (!string.IsNullOrWhiteSpace(projectCode))
         {
             var projectInfo = context.PPM_ProjectInfo.Where(p => p.ProjectCode == projectCode).FirstOrDefault();
             if (projectInfo != null)
             {
                 txtCurrProjectName.Text = projectInfo.ProjectName;
                 txtSVN.Text             = projectInfo.SVN;
                 txtDevServerInfo.Text   = projectInfo.DevServerInfo;
                 txtPubServerInfo.Text   = projectInfo.PubServerInfo;
                 txtOtherInfo.Text       = projectInfo.OtherInfo;
             }
         }
     }
 }
예제 #5
0
        private bool login(string userCode, ref bool correctVersion)
        {
            string versionNo      = ConfigurationManager.AppSettings["Version"];
            string messageUrlPort = string.Empty;

            using (BugTraceEntities zentity = new BugTraceEntities(EntityContextHelper.GetEntityConnString()))
            {
                var currVersion = zentity.SYS_Version.Where(p => p.IsDefault == 1).FirstOrDefault();
                if (currVersion == null)
                {
                    this.Invoke(new MethodInvoker(() =>
                    {
                        MessageBox.Show("数据库中系统版本不存,在请系统联系管理员!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }));
                    return(false);
                }
                if (versionNo != currVersion.VersionNo)
                {
                    this.Invoke(new MethodInvoker(() =>
                    {
                        MessageBox.Show("版本已经升级,请点击确定后下载最新版客户端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }));
                    correctVersion = false;
                    return(false);
                }
                var user = zentity.SYS_User.Where(p => p.UserCode == userCode).FirstOrDefault();
                if (user == null)
                {
                    this.Invoke(new MethodInvoker(() =>
                    {
                        MessageBox.Show("当前用户不存在,请联系管理员!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }));
                    return(false);
                }
                else
                {
                    UserInfo userInfo = UserInfo.GetInstence();
                    userInfo.UserCode           = user.UserCode;
                    userInfo.UserName           = user.UserName;
                    userInfo.Tel                = user.Tel;
                    userInfo.QQ                 = user.QQ;
                    userInfo.LoginTime          = DateTime.Now;
                    userInfo.DefaultProjectCode = user.DefaultProjectCode;
                    messageUrlPort              = user.UrlPort;
                }
            }
            try
            {
                //urlPort = "localhost:9119";
                var client = new WCFClient();
                client.WcfMessageEvent += client_WcfMessage;
                var             ctx     = new InstanceContext(client);
                EndpointAddress address = new EndpointAddress("net.tcp://" + messageUrlPort + "/JAJ.WinServer");
                System.ServiceModel.Channels.Binding binding = new NetTcpBinding("netTcpExpenseService_ForSupplier");
                var proxy = new WcfSvc.MessageServiceClient(ctx, binding, address);
                proxy.Login(userCode);
            }
            catch (Exception ex)
            {
                this.Invoke(new MethodInvoker(() =>
                {
                    MessageBox.Show("消息服务启动失败!\r\n问题跟踪功能可正常使用,请点击确定后继续使用系统");
                }));
                MyLog.LogError("消息服务启动失败", ex);
            }
            finally
            {
                #region 开启新的线程保持连接
                List <KeyValuePair <string, string> > kList = new List <KeyValuePair <string, string> >();
                kList.Add(new KeyValuePair <string, string>("UserCode", userCode));
                kList.Add(new KeyValuePair <string, string>("UrlPort", messageUrlPort));
                _thread = new Thread(KeepAlive);
                _thread.IsBackground = true;
                _thread.Start(kList);
                #endregion
            }
            return(true);
        }
예제 #6
0
파일: FrmIndex.cs 프로젝트: posjaj/BugTrace
        private void FrmIndex_Load(object sender, EventArgs e)
        {
            this.Top  = 10;
            this.Left = 10;
            using (BugTraceEntities context = new BugTraceEntities(EntityContextHelper.GetEntityConnString()))
            {
                #region 加载当前项目信息
                var projectCode = UserInfo.GetInstence().DefaultProjectCode;
                if (!string.IsNullOrWhiteSpace(projectCode))
                {
                    var projectInfo = context.PPM_ProjectInfo.Where(p => p.ProjectCode == projectCode).FirstOrDefault();
                    if (projectInfo != null)
                    {
                        txtCurrProjectName.Text = projectInfo.ProjectName;
                        txtSVN.Text             = projectInfo.SVN;
                        txtDevServerInfo.Text   = projectInfo.DevServerInfo;
                        txtPubServerInfo.Text   = projectInfo.PubServerInfo;
                        txtOtherInfo.Text       = projectInfo.OtherInfo;
                        var updatePerson = context.SYS_User.Where(p => p.UserCode == projectInfo.UpdatePerson).FirstOrDefault();
                        if (updatePerson != null)
                        {
                            string updatePersonName = updatePerson.UserName;
                            this.lblUpdateInfo.Text = "(最后一次修改人:" + updatePersonName + ",修改时间:" + (projectInfo.UpdateDate == null ? "未记录" : projectInfo.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")) + ")";
                        }
                        else
                        {
                            this.lblUpdateInfo.Text = "";
                        }
                    }
                }
                #endregion
            }

            #region 开启一个新线程,检测未读邮件信息
            this.dgvEmail.AutoGenerateColumns = false;
            this.dgvEmail.AllowUserToAddRows  = false;
            Thread thread = new Thread(new ThreadStart(delegate   ///监听所有客户端连接,并添加到ListBox控件里
            {
                dtblEmail = new DataTable();
                dtblEmail.Columns.Add("Subject", typeof(string));
                dtblEmail.Columns.Add("ReceiveDate", typeof(DateTime));
                dtblEmail.Columns.Add("From", typeof(string));
                while (true)
                {
                    UnReadEmailCount = 0;
                    int netStatus    = GetInternetConStatus.GetNetConStatus();
                    if (netStatus == 2 || netStatus == 3)
                    {
                        dtblEmail.Rows.Clear();
                        try
                        {
                            QueryEmailStatus();
                        }
                        catch (Exception ex)
                        {
                            MyLog.LogError("查询未读邮件异常!", ex);
                        }
                    }
                    Thread.Sleep(1000 * 60 * 10);//每10分钟查看邮件信息
                }
            }));
            thread.IsBackground = true;
            thread.Start();
            #endregion

            #region 获取外网ip及城市信息,及城市的天气信息
            Thread threadWeather = new Thread(new ThreadStart(delegate   //监听所有客户端连接,并添加到ListBox控件里
            {
                try
                {
                    string hostname;
                    System.Net.IPHostEntry localhost;
                    System.Net.IPAddress[] localaddr;
                    hostname  = System.Net.Dns.GetHostName();
                    localhost = System.Net.Dns.GetHostEntry(hostname);
                    localaddr = localhost.AddressList;   //localaddr中就是本机ip地址

                    foreach (IPAddress ipInfo in localaddr)
                    {
                        if (ipInfo.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            this.Invoke(new MethodInvoker(delegate
                            {
                                lblInnerIP.Text = ipInfo.ToString();
                            }));
                        }
                    }
                    cn.com.webxml.www.WeatherWebService client = new cn.com.webxml.www.WeatherWebService();
                    string[] weaInfo = client.getWeatherbyCityName("青岛");
                    this.Invoke(new MethodInvoker(delegate
                    {
                        Label lblDate          = new Label();
                        lblDate.Text           = weaInfo[13];
                        lblDate.Width          = 140;
                        lblDate.Padding        = new System.Windows.Forms.Padding(0, 7, 0, 0);
                        Label lblTemperature   = new Label();
                        lblTemperature.Text    = weaInfo[12];
                        lblTemperature.Padding = new System.Windows.Forms.Padding(0, 7, 0, 0);
                        Label lblWind          = new Label();
                        lblWind.Text           = weaInfo[14];
                        lblWind.Padding        = new System.Windows.Forms.Padding(0, 7, 0, 0);
                        PictureBox pbImage     = new PictureBox();
                        string strPath         = System.Environment.CurrentDirectory + "\\Resource\\weather\\" + weaInfo[15];
                        pbImage.Image          = Image.FromFile(strPath);
                        flowWeather1.Controls.Add(lblDate);
                        flowWeather1.Controls.Add(lblTemperature);
                        flowWeather1.Controls.Add(lblWind);
                        flowWeather1.Controls.Add(pbImage);

                        Label lblDate2          = new Label();
                        lblDate2.Text           = weaInfo[18];
                        lblDate2.Width          = 140;
                        lblDate2.Padding        = new System.Windows.Forms.Padding(0, 7, 0, 0);
                        Label lblTemperature2   = new Label();
                        lblTemperature2.Text    = weaInfo[17];
                        lblTemperature2.Padding = new System.Windows.Forms.Padding(0, 7, 0, 0);
                        Label lblWind2          = new Label();
                        lblWind2.Text           = weaInfo[19];
                        lblWind2.Padding        = new System.Windows.Forms.Padding(0, 7, 0, 0);
                        PictureBox pbImage2     = new PictureBox();
                        string strPath2         = System.Environment.CurrentDirectory + "\\Resource\\weather\\" + weaInfo[20];
                        pbImage2.Image          = Image.FromFile(strPath2);
                        flowWeather2.Controls.Add(lblDate2);
                        flowWeather2.Controls.Add(lblTemperature2);
                        flowWeather2.Controls.Add(lblWind2);
                        flowWeather2.Controls.Add(pbImage2);
                    }));
                }
                catch (Exception ex)
                {
                    MyLog.LogError("获取IP信息失败!", ex);
                }
            }));
            threadWeather.IsBackground = true;
            threadWeather.Start();
            #endregion
        }
예제 #7
0
파일: FrmIndex.cs 프로젝트: posjaj/BugTrace
        //#region 获取当前外网ip地址
        //private string GetIP()
        //{
        //    string strUrl = "http://www.ip138.com/ip2city.asp"; //获得IP的网址了
        //    Uri uri = new Uri(strUrl);
        //    WebRequest wr = WebRequest.Create(uri);
        //    Stream s = wr.GetResponse().GetResponseStream();
        //    StreamReader sr = new StreamReader(s, Encoding.Default);
        //    string all = sr.ReadToEnd(); //读取网站的数据
        //    int i = all.IndexOf("[") + 1;
        //    string tempip = all.Substring(i, 15);
        //    string ip = tempip.Replace("]", "").Replace(" ", "");
        //    return ip;
        //}
        //#endregion


        #region 未读邮件信息

        private void QueryEmailStatus()
        {
            IMAP_Client IMAPServer = new IMAP_Client();

            try
            {
                //连接邮件服务器通过传入邮件服务器地址和用于IMAP协议的端口号
                IMAPServer.Connect(@"imap.exmail.sina.com", 143, false);
                string currUserCode  = UserInfo.GetInstence().UserCode;
                string emailPassword = string.Empty;
                //登陆邮箱,前者帐号后者密码
                using (var context = new BugTraceEntities(EntityContextHelper.GetEntityConnString()))
                {
                    var currUserExt = context.SYS_UserExt.Where(p => p.UserCode == currUserCode).FirstOrDefault();
                    if (currUserExt != null)
                    {
                        emailPassword = Encrypt.TripleDESDecrypting(currUserExt.EmailPassword);
                    }
                }
                if (string.IsNullOrWhiteSpace(emailPassword))
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        this.lblEmailInfo.Text = "邮箱登陆失败!请先在个人设置中设置密码!";
                    }));
                    return;
                }
                IMAPServer.Login(currUserCode + "@ecode.net.cn", emailPassword);

                //选中收件箱
                IMAPServer.SelectFolder("INBOX");

                //取出收件箱
                var folder = IMAPServer.SelectedFolder;

                //收件箱邮件总数
                //folder.MessagesCount.ToString();
                //收件箱未读邮件总数
                //folder.RecentMessagesCount.ToString();



                //以下开始取出邮件
                //首先确定取第x到第n封邮件,"1:*"表示第1封到最后一封
                int msgCount = folder.MessagesCount - 20;
                if (msgCount <= 0)
                {
                    msgCount = 1;
                }
                var seqSet = LumiSoft.Net.IMAP.IMAP_t_SeqSet.Parse(msgCount.ToString() + ":*");
                //根据数组中的成员决定取出邮件的那些信息
                var imap_t_Fetch_i = new IMAP_t_Fetch_i[]
                {   
                  new IMAP_t_Fetch_i_Envelope(),     //邮件的标题、正文等信息
                  new IMAP_t_Fetch_i_Flags(),        //此邮件的标志,应该是已读未读标志
                  new IMAP_t_Fetch_i_InternalDate(), //貌似是收到的日期
                  //new IMAP_t_Fetch_i_Rfc822(),//Rfc822是标准的邮件数据流,可以通过Lumisoft.Net.Mail.Mail_Message对象解析出邮件的所有信息(不确定有没有附件的内容)。
                  new IMAP_t_Fetch_i_Uid()           //返回邮件的UID号,UID号是唯一标识邮件的一个号码
                };
                //创建一个符合lumisoft的回调函数的委托。
                //当调用fetch函数完成时,会自动调用用户自定义的函数,这里是Fetchcallback(我自己起的名字,名字无意义,保证参数是object,LumiSoft . Net . EventArgs<IMAP_r_u> 两个就好
                EventHandler <LumiSoft.Net.EventArgs <IMAP_r_u> > lumisoftHandler = new EventHandler <LumiSoft.Net.EventArgs <IMAP_r_u> >(Fetchcallback);

                //把上边定义好的参数传入fetch函数,就会取出邮件
                //lumisoftHandler指向的函数在每取出一封邮件的时候会被触发一次
                IMAPServer.Fetch(false, seqSet, imap_t_Fetch_i, lumisoftHandler);
                this.Invoke(new MethodInvoker(delegate
                {
                    this.lblEmailInfo.Text     = "";
                    this.linkEmailInfo.Text    = "您当前共有" + UnReadEmailCount + "封未读邮件!<<click me>>(只搜索最近20封邮件)";
                    this.linkEmailInfo.Visible = true;
                    this.dgvEmail.DataSource   = dtblEmail;
                }));
            }
            catch (Exception ex)
            {
                MyLog.LogError("读取未读邮件失败!", ex);
                if (ex.Message.IndexOf("Invalid login credentials") != -1)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        this.lblEmailInfo.Text = "邮箱登陆失败!请先在个人设置中设置密码!";
                    }));
                }
            }
            finally
            {
                IMAPServer.Disconnect();
            }
        }