static void Main()
        {
            dboperation operation = new dboperation();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string db = Settings.Default.DatabasePath + "\\" + Global.ROOT_DATA_FOLDER + "\\" + Global.DB_NAME_PREFIX + ".sdf";

            if (!File.Exists(db))
            {
                Application.Run(new registration());
            }
            else
            {
                if (operation.keyvalidation())
                {
                    Application.Run(new loginPanel());
                }
                else
                {
                    Application.Run(new registration());
                }
            }



            // Application.Run(new TestPicture());
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            dboperation operation = new dboperation();

            if (!operation.keyvalidation())
            {
                this.Close();
                thread = new Thread(openreg);
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
            }
            int flag = 0;

            if (userselector.Text != null && passwd.Text != null)
            {
                flag = Authentication(userselector.Text, passwd.Text);
                if (flag == 1)
                {
                    this.Close();
                    thread = new Thread(openPref);
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                }
                else if (flag == 2)
                {
                    this.Close();
                    thread = new Thread(openBill);
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                }
                else
                {
                    MessageBox.Show("Incorrect Login Credential", "Error");
                    passwd.Clear();
                }
            }
        }
        private void regbtn_Click(object sender, EventArgs e)
        {
            if (flag)
            {
                updateInformation();
            }
            else
            {
                if (compnametb.Text == "")
                {
                    MessageBox.Show("Company Name can't be empty");
                }
                else if (compaddrtb.Text == "")
                {
                    MessageBox.Show("Company Address can't be empty");
                }
                else if (compmbltb.Text == "")
                {
                    MessageBox.Show("Company Mobile number can't be empty");
                }
                else if (gstuintb.Text == "")
                {
                    MessageBox.Show("GSTIN/UIN field can't be empty");
                }
                else if (regkeytb.Text == "")
                {
                    MessageBox.Show("Please, specify a registration key or Contact [email protected]");
                }
                else if (prefix.Text == "")
                {
                    MessageBox.Show("Please specify a prefix for invoice number");
                }
                else if (compemail.Text == "")
                {
                    compemail.Text = "0";
                }
                else if (compvattb.Text == "")
                {
                    compvattb.Text = "0";
                }
                else if (compcsttb.Text == "")
                {
                    compcsttb.Text = "0";
                }
                else if (comppantb.Text == "")
                {
                    comppantb.Text = "0";
                }
                else
                {
                    dboperation operation = new dboperation();
                    if (!(operation.keyvalidation(regkeytb.Text, gstuintb.Text)))
                    {
                        MessageBox.Show("Your Key is not Valid");
                        this.Close();
                    }


                    if (Settings.Default.DatabasePath == "" || !File.Exists(Settings.Default.DatabasePath + "\\" + Global.ROOT_DATA_FOLDER + "\\" + Global.DB_NAME_PREFIX + ".sdf"))
                    {
                        FilePath setpath = new FilePath();
                        setpath.ShowDialog();
                    }

                    else
                    {
                        SqlCeConnection conn = null;
                        SqlCeCommand    cmd  = null;
                        int             flag;
                        byte[]          photo_array = null;
                        MemoryStream    ms          = new MemoryStream();
                        if (complogopb.Image == null)
                        {
                            complogopb.Image = Resources.defaultlogo;
                        }
                        complogopb.Image.Save(ms, ImageFormat.Png);
                        photo_array = new byte[ms.Length];
                        ms.Position = 0;
                        ms.Read(photo_array, 0, photo_array.Length);

                        string insertquery = "INSERT INTO regdetails(Id,companyName, companyAddr, companyMobile, companyEmail, companygstin, companyVAT, companyCST, companyPAN, regkey, prefix, logo) VALUES(@compid,@cname, @caddr, @mbl, @email, @gstin, @vat, @cst, @pan,@key,@prefix,@img)";
                        try
                        {
                            conn = operation.dbConnection(Settings.Default.DatabasePath);
                            cmd  = new SqlCeCommand(insertquery, conn);
                            cmd.Parameters.AddWithValue("@compid", "1");
                            cmd.Parameters.AddWithValue("@cname", compnametb.Text);
                            cmd.Parameters.AddWithValue("@caddr", compaddrtb.Text);
                            cmd.Parameters.AddWithValue("@mbl", compmbltb.Text);
                            cmd.Parameters.AddWithValue("@email", compemail.Text);
                            cmd.Parameters.AddWithValue("@gstin", gstuintb.Text);
                            cmd.Parameters.AddWithValue("@vat", compvattb.Text);
                            cmd.Parameters.AddWithValue("@cst", compcsttb.Text);
                            cmd.Parameters.AddWithValue("@pan", comppantb.Text);
                            cmd.Parameters.AddWithValue("@key", regkeytb.Text);
                            cmd.Parameters.AddWithValue("@prefix", prefix.Text);
                            cmd.Parameters.AddWithValue("@img", photo_array);
                            flag = cmd.ExecuteNonQuery();
                            if (flag < 0)
                            {
                                MessageBox.Show("Error User to Register");
                                this.Close();
                            }
                            else
                            {
                                this.Close();
                                thread = new Thread(openlogin);
                                thread.SetApartmentState(ApartmentState.STA);
                                thread.Start();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("An error occured to creating database" + ex);
                        }
                    }
                }
            }
        }