成功登录后打开新表单

时间:2015-06-11 20:16:34

标签: c# visual-studio-2012

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void quitbtn_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

    private void loginbtn_Click(object sender, EventArgs e)
    {
        if (usertext.Text=="")
        {
            MessageBox.Show("Enter Username");
        }
        else if (passtext.Text=="")
        {
            MessageBox.Show("Enter Password");

        }
        else
        {
            if(usertext.Text=="admin")
            {
                if (passtext.Text== "adminpass")
            {
                Class1 class1 = new class1();
                Class1.Show();
            }
                else
                {
                    MessageBox.Show("Invalid Login");
                }
            }

        }
    }
}

}

所以我目前有这个非常简单的登录webform,一旦我输入正确的用户名和密码,它就会打开一个控制台应用程序。我不确定我是否做得对,因为我不断收到构建错误。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

 namespace LoanCalculator
 {
  class Class1
 {
    static void Main(string[] args)
    {
        // declare variables
        double principle = 0;
        double years = 0;
        double interest = 0;
        string principleInput, yearsInput, interestInput;


        // User input for Principle amount in dollars
        Console.Write("Enter the loan amount, in dollars(0000.00): ");
        principleInput = Console.ReadLine();
        principle = double.Parse(principleInput);
        //Prompt the user to reenter any illegal input
        if (principle < 0)
        {
            Console.WriteLine("The value for the mortgage cannot be a negative value");
            principle = 0;
        }


        // User input for number of years
        Console.Write("Enter the number of years: ");
        yearsInput = Console.ReadLine();
        years = double.Parse(yearsInput);
        //Prompt the user to reenter any illegal input
        if (years < 0)
        {
            Console.WriteLine("Years cannot be a negative value");
            years = 0;
        }

        // User input for interest rate
        Console.Write("Enter the interest rate(%): ");
        interestInput = Console.ReadLine();
        interest = double.Parse(interestInput);
        //Prompt the user to reenter any illegal input
        if (interest < 0)
        {
            Console.WriteLine("The value for the interest rate cannot be a negative value");
            interest = 0;
        }

        //Calculate the monthly payment
        //ADD IN THE .Net function call Math.pow(x, y) to compute xy (x raised to the y power). 
        double loanM = (interest / 1200.0);
        double numberMonths = years * 12;
        double negNumberMonths = 0 - numberMonths;
        double monthlyPayment = principle * loanM / (1 - System.Math.Pow((1 + loanM), negNumberMonths));

        //double totalPayment = monthlyPayment;


        //Output the result of the monthly payment
        Console.WriteLine(String.Format("The amount of the monthly payment is: {0}{1:0.00}", "$", monthlyPayment));
        Console.WriteLine();
        Console.WriteLine("Press the Enter key to end. . .");
        Console.Read();

    }
}

}

1 个答案:

答案 0 :(得分:0)

您的winform和控制台应用程序将编译为单独的程序。如果您想从winform启动控制台应用程序,您需要像任何其他外部程序一样启动它:

https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start%28v=vs.110%29.aspx

另外,请看这个问题: how to execute console application from windows form?

其他一些评论 - 您无法在控制台应用程序前提供任何类型的安全性。如果winform可以启动控制台应用程序,那么用户也可以(通过直接执行它)。