2015-10-16 191 views
0

我在C#中提出了一个提醒应用程序,现在我想创建它的安装程序以将其安装在其他PC上,但每次使用Flexera安装屏幕创建安装程序时,它创建一个永远不会安装的文件!我确信我正在做的是正确的,正如教程中讲的那样。我的应用程序中包含2个窗体这里是代码:在VS2012中生成可执行安装文件通过installshield生成可执行文件,但每次都失败

首页

public partial class Form1 : Form 
{ 
    RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); 
    private NotifyIcon m_notifyicon; 
    private ContextMenu m_menu; 
    EntryForm ef = new EntryForm(); 

    public Form1() 
    { 
     Text = "TrayIcon test program"; 
     m_menu = new ContextMenu(); 
     m_menu.MenuItems.Add(0, 
      new MenuItem("Show", new System.EventHandler(Show_Click))); 
     m_menu.MenuItems.Add(1, 
      new MenuItem("Hide", new System.EventHandler(Hide_Click))); 
     m_menu.MenuItems.Add(2, 
      new MenuItem("Exit", new System.EventHandler(Exit_Click))); 
     m_notifyicon = new NotifyIcon(); 
     m_notifyicon.Text = "Right click for context menu"; 
     m_notifyicon.Visible = true; 
     //m_notifyicon.Icon = new Icon(GetType(), "Icon1.ico"); 
     m_notifyicon.Icon = new Icon(@"C:\ic.ico"); 
     m_notifyicon.ContextMenu = m_menu; 
     ef.Activate(); 
     reg.SetValue("Reminder_App_Varun", Application.ExecutablePath.ToString()); 
     InitializeComponent(); 
     this.StartPosition = FormStartPosition.Manual; 
     this.Location = new Point(500, 220); 

    } 

    protected void Exit_Click(Object sender, System.EventArgs e) 
    { 
     Close(); 
    } 
    protected void Hide_Click(Object sender, System.EventArgs e) 
    { 
     Hide(); 
    } 
    protected void Show_Click(Object sender, System.EventArgs e) 
    { 
     Show(); 
    } 
    protected override void Dispose(bool disposing) 
    { 
     if (disposing) 
     { 
      this.m_notifyicon.Dispose(); 
     } 
     base.Dispose(disposing); 
    } 

    [STAThread] 
    static void Main1() 
    { 
     Application.Run(new Form1()); 
    } 

第二形态

public partial class EntryForm : Form 
{ 

    public EntryForm() 
    { 
     InitializeComponent(); 
     label9.Hide(); 
     panel2.Hide(); 
     configmail(); 
     cdate(); 
     checkdate();    
     grid_bind(); 
     panel4.Hide(); 
     label14.Text = "No Selection"; 
     this.label11.Click += new System.EventHandler(this.ctrlClick); 
    } 
    private void ctrlClick(System.Object sender, EventArgs e) 
    { 
     Control ctrl = (Control)sender;  
     panel4.Show(); 
    } 

    protected override void WndProc(ref Message m) 
    { 
     base.WndProc(ref m); 
     if (m.Msg == WM_NCHITTEST) 
      m.Result = (IntPtr)(HT_CAPTION); 
    } 

    private const int WM_NCHITTEST = 0x84; 
    private const int HT_CLIENT = 0x1; 
    private const int HT_CAPTION = 0x2; 
    private void button2_Click(object sender, EventArgs e) 
    { 

     checkdate(); 
    } 

    private void checkdate() 
    { 
     DateTime dt = DateTime.Parse(label10.Text); 
     long t = dt.ToFileTime(); 
     DateTime date1 = DateTime.Today;  
     int result = DateTime.Compare(date1, dt); 
     string relationship; 
     if (result > 0) 
     { 
      relationship = "is earlier than";     
     } 
     else if (result == 0) 
     { 
      relationship = "is later than"; 
      SendEmail();    
     } 

     else 
     { 
      relationship = "is later than"; 
      SendEmail();     
     } 
     Console.WriteLine("{0} {1} {2}", date1, relationship, dt); 
    } 
    private void SendEmail() 
    { 
     try 
     { 
      OleDbConnection ncon = new OleDbConnection(); 
      ncon.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\RemindMe Beta 1.0\RemindMe Beta 1.0\sendmail.accdb"; 
      ncon.Open(); 
      OleDbCommand ncmd = new OleDbCommand("SELECT * FROM tb_sendmail WHERE (((remind_date)=#" + label13.Text + "#))", ncon); 
      OleDbDataAdapter da = new OleDbDataAdapter(ncmd); 
      DataTable ndt = new DataTable(); 
      da.Fill(ndt); 
      //...FOR ERROR 5.5.1 SECURE CONNECTION GO TO https://www.google.com/settings/security/lesssecureapps AND TURN ON LESS SECURE APPS CONNECTION...//// 
      SmtpClient client = new SmtpClient("smtp.gmail.com"); 
      client.Port = 587; 
      client.EnableSsl = true; 
      client.Timeout = 100000; 
      client.DeliveryMethod = SmtpDeliveryMethod.Network; 
      client.UseDefaultCredentials = false; 
      client.Credentials = new NetworkCredential("" + label7.Text + "", "" + label9.Text + "");  
      MailMessage msg = new MailMessage(); 
      msg.To.Add("" + ndt.Rows[0][1].ToString() + "");    
      msg.From = new MailAddress("[email protected]");   
      msg.Subject = (""+ndt.Rows[0][2].ToString()+"");   
      msg.Body = ("" + ndt.Rows[0][4].ToString() + "");    
      client.Send(msg); 
      MessageBox.Show("Successfully Sent Message."); 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     this.Hide(); 
    } 

    private void panel1_Paint(object sender, PaintEventArgs e) 
    { 

    } 

    private void panel2_Paint(object sender, PaintEventArgs e) 
    { 




    } 

    private void button3_Click(object sender, EventArgs e)//--------------email send pannel--------------// 
    { 
     OleDbConnection con = new OleDbConnection(); 
     con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\RemindMe Beta 1.0\RemindMe Beta 1.0\sendmail.accdb"; 
     con.Open();    
     OleDbCommand cmd = new OleDbCommand("Insert into tb_sendmail (email_add,subject,remind_date,message) values (@email_add,@subject,@remind_date,@message)", con); 
     if (con.State == ConnectionState.Open)  
     { 
      cmd.Parameters.Add("@email_add", OleDbType.VarChar).Value = textBox1.Text; 
      cmd.Parameters.Add("@subject", OleDbType.VarChar).Value = textBox2.Text; 
      cmd.Parameters.Add("@remind_date", OleDbType.Date).Value = textBox3.Text; 
      cmd.Parameters.Add("@message", OleDbType.VarChar).Value = textBox4.Text; 

      try 
      { 
       cmd.ExecuteNonQuery(); 
       MessageBox.Show("DATA ADDED"); 
       dataGridView1.Refresh(); 

       con.Close(); 
      } 
      catch (OleDbException expe) 
      { 
       MessageBox.Show(expe.Message); 
       con.Close(); 
      } 
     } 
     grid_bind(); 
    } 

    private void grid_bind() 
    { 
     OleDbConnection conn = new OleDbConnection(); 
     conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\RemindMe Beta 1.0\RemindMe Beta 1.0\sendmail.accdb"; 
     conn.Open();      
     OleDbDataAdapter oda; 
     DataTable ndt; 
     oda = new OleDbDataAdapter("SELECT ID,email_add,subject,remind_date,message from tb_sendmail", conn); 
     ndt = new DataTable(); 
     oda.Fill(ndt); 
     dataGridView1.DataSource = ndt; 
    } 

    private void button4_Click(object sender, EventArgs e)//--------------email address details pannel--------------// 
    { 
      OleDbConnection con = new OleDbConnection(); 
      con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\RemindMe Beta 1.0\RemindMe Beta 1.0\sendmail.accdb"; 
      con.Open(); 
      OleDbCommand cmd = new OleDbCommand("Update tb_email set [email protected]_address,[email protected]_password where ID = 1", con); 
      if (con.State == ConnectionState.Open) 
      { 
       cmd.Parameters.Add("@email_address", OleDbType.VarChar).Value = textBox5.Text; 
       cmd.Parameters.Add("@email_password", OleDbType.VarChar).Value = textBox6.Text; 
       try 
       { 
        cmd.ExecuteNonQuery(); 
        MessageBox.Show("Email Address Saved Successfully"); 
        con.Close(); 
        panel2.Hide(); 
        label7.Refresh(); 
        button5.Show(); 
       } 
       catch (OleDbException expe) 
       { 
        MessageBox.Show(expe.Message); 
        con.Close(); 
       } 
      } 
    } 

    private void button5_Click(object sender, EventArgs e) 
    { 
     panel2.Show(); 
     button5.Hide(); 

    }  

    private void cdate() 
    { 
     DateTime dat = DateTime.Now;    
     label13.Text = dat.ToString("MM/dd/yyyy");    
     OleDbConnection ncon = new OleDbConnection(); 
     ncon.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\RemindMe Beta 1.0\RemindMe Beta 1.0\sendmail.accdb"; 
     ncon.Open(); 
     OleDbCommand ncmd = new OleDbCommand("SELECT * FROM tb_sendmail WHERE (((remind_date)=#" + label13.Text + "#))", ncon);    
     OleDbDataAdapter da = new OleDbDataAdapter(ncmd); 
     DataTable ndt = new DataTable(); 
     da.Fill(ndt); 
     if (ndt.Rows.Count == 0) 
     { 
      label10.Text = "01-09-2015"; 
     } 
     else if (ndt.Rows.Count > 0) 
     { 

      MessageBox.Show(" TODAY is "+ label13.Text +", Perform your set action. Reminder has been sent on your Email. !"); 
      label10.Text = ndt.Rows[0][3].ToString();    

      } 

     else 
     { 
     label10.Text = ndt.Rows[0][3].ToString(); 
     } 
    } 
    private void configmail() 
    { 
     OleDbConnection con = new OleDbConnection(); 
     con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\RemindMe Beta 1.0\RemindMe Beta 1.0\sendmail.accdb"; 
     con.Open(); 
     OleDbCommand cmd = new OleDbCommand("Select * from tb_email", con); 
     OleDbDataAdapter da = new OleDbDataAdapter(cmd); 
     DataTable dt = new DataTable(); 
     da.Fill(dt); 
     label7.Text = dt.Rows[0][1].ToString(); 
     label9.Text = dt.Rows[0][2].ToString(); 

    } 

    private void EntryForm_Load(object sender, EventArgs e) 
    { 
    } 

    private void timer1_Tick(object sender, EventArgs e) 
    { 

    } 

    private void button8_Click(object sender, EventArgs e)//---------clear text-------// 
    { 
     clear_textbox(); 
    } 

    private void clear_textbox() 
    { 
     textBox1.Text = ""; 
     textBox2.Text = ""; 
     textBox3.Text = ""; 
     textBox4.Text = ""; 
    } 

    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) 
    { 
     textBox1.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString(); 
     textBox2.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString(); 
     textBox3.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString(); 
     textBox4.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString(); 
     label14.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString(); 
    } 

    private void button6_Click(object sender, EventArgs e) 
    { 

    } 

    private void button7_Click(object sender, EventArgs e) 
    { 
     OleDbConnection con = new OleDbConnection(); 
     con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\RemindMe Beta 1.0\RemindMe Beta 1.0\sendmail.accdb"; 
     con.Open();    
     OleDbCommand cmd = new OleDbCommand("Delete from tb_sendmail where ID = @ID", con); 
     if (con.State == ConnectionState.Open) 
     { 
      cmd.Parameters.Add("@ID", OleDbType.Integer).Value = label14.Text; 

      try 
      { 
       cmd.ExecuteNonQuery(); 
       MessageBox.Show("DATA Deleted !!"); 

       con.Close(); 
      } 
      catch (OleDbException expe) 
      { 
       MessageBox.Show(expe.Message); 
       con.Close(); 
      } 
     } 
     else 
     { 
      MessageBox.Show("CON FAILED"); 
     } 
     grid_bind(); 
     clear_textbox(); 
    } 

    private void dataGridView1_SelectionChanged(object sender, EventArgs e) 
    { 
     label14.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString(); 
    } 

    private void button6_Click_1(object sender, EventArgs e) 
    { 
     panel4.Hide(); 
    } 

} 

我还附上我的代码文件: http://www.4shared.com/rar/Kh34lfL7ce/RemindMe_Beta_10.html

我是一个noob,这是我的第一个项目,所以请突出我的错误。

感谢

+0

因为很容易,你可以试试http://www.advancedinstaller.com/ –

+0

不!安装我的应用程序后仍然无法正常工作,它无法启动 - 给出错误 –

+0

也许如果您删除自己的安装程序代码 –

回答

0

我注意到,因为你在错误的时刻称之为InitializeComponent();它可能。

+0

你要我删除它吗? –

+0

无法删除InitializeComponent();因为删除它会产生很多错误 –

+0

不是不删除它,只是称它为第一个 –

相关问题