Exemplo n.º 1
0
 private void btnopen_Click(object sender, EventArgs e)
 {
     try
     {
         if (Convert.ToString(cmbMySqlFilll.Text) == "")
         {
             MessageBox.Show(this, "DataBase Name can't be Blank", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         else
         {
             PublicClass.CreateConnection("route");
             DbClass.executequery(CommandType.Text, "Update lastdatabase set DBName= '" + Convert.ToString(cmbMySqlFilll.Text) + "' where UserName = '******' and InstrumentName='" + PublicClass.currentInstrument + "' ");
             PublicClass.CreateConnection(Convert.ToString(cmbMySqlFilll.Text));
             PublicClass.flagAlarm = true;
             check1 = true;
             this.Close();
         }
     }
     catch { }
 }
        private void btnDBRestore_Click(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToString(txtNewDBName.Text).Trim() == "")
                {
                    MessageBox.Show(this, "DataBase Name can't be Blank", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                DataTable dt = new DataTable();
                dt = DbClass.getdata(CommandType.Text, "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '" + txtNewDBName.Text.Trim() + "'");
                if (dt.Rows.Count > 0)
                {
                    MessageBox.Show(this, "This DataBase is Already Exist", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    if (PublicClass.ValidateDatabase(Convert.ToString(txtNewDBName.Text).Trim()))
                    {
                        PublicClass.statusbar(dbRestoreProgbar);
                        DbClass.executequery(CommandType.Text, "CREATE database  " + Convert.ToString(txtNewDBName.Text).Trim() + " ");
                        PublicClass.statusbar(dbRestoreProgbar);
                        string constring = "SERVER=localhost ; DATABASE=" + Convert.ToString(txtNewDBName.Text).Trim() + "; UID=root; PASSWORD=1234 ;Convert Zero Datetime=true; Allow Zero Datetime=true";
                        PublicClass.statusbar(dbRestoreProgbar);
                        using (MySqlConnection conn = new MySqlConnection(constring))
                        {
                            PublicClass.statusbar(dbRestoreProgbar);
                            using (MySqlCommand cmd = new MySqlCommand())
                            {
                                PublicClass.statusbar(dbRestoreProgbar);
                                using (MySqlBackup mb = new MySqlBackup(cmd))
                                {
                                    PublicClass.statusbar(dbRestoreProgbar);
                                    cmd.Connection = conn;
                                    PublicClass.statusbar(dbRestoreProgbar);
                                    conn.Open();
                                    PublicClass.statusbar(dbRestoreProgbar);
                                    try
                                    {
                                        mb.ImportFromFile(spath);
                                    }

                                    catch { }
                                    PublicClass.statusbar(dbRestoreProgbar);
                                    conn.Close();
                                    PublicClass.statusbar(dbRestoreProgbar);
                                    PublicClass.statusbar(dbRestoreProgbar);
                                    PublicClass.statusbar(dbRestoreProgbar);
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "Only alphanumeric characters may be used in Database Name", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtNewDBName.Text = "";
                        return;
                    }
                    PublicClass.CreateConnection("route");
                    PublicClass.statusbar(dbRestoreProgbar);
                    DbClass.executequery(CommandType.Text, "Insert into databasename(Database_Name,InstrumentName)values('" + Convert.ToString(txtNewDBName.Text).Trim() + "','" + PublicClass.currentInstrument + "')");
                    PublicClass.statusbar(dbRestoreProgbar);
                    DbClass.executequery(CommandType.Text, "Update lastdatabase set DBName= '" + Convert.ToString(txtNewDBName.Text).Trim() + "' where UserName = '******' ");
                    PublicClass.statusbar(dbRestoreProgbar);
                    PublicClass.statusbar(dbRestoreProgbar);
                    PublicClass.CreateConnection(Convert.ToString(txtNewDBName.Text).Trim());
                    PublicClass.statusbar(dbRestoreProgbar);
                    dbRestoreProgbar.Value = 100;
                    PublicClass.flagAlarm  = true;
                    this.Close();
                }
            }
            catch
            {
            }
        }
Exemplo n.º 3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string lastdbName = null;
                PublicClass.currentInstrument = getInstrumentName(cmbdata.Text);
                PublicClass.CreateConnection("route");
                //bool licenseCheck = GetLicenseValidity(PublicClass.ValidityTo, PublicClass.InstrumentSerial);
                //if (licenseCheck)
                //{
                DataTable dtt = new DataTable();
                dtt = DbClass.getdata(CommandType.Text, "select * from route.lastdatabase where Instrumentname='" + PublicClass.currentInstrument + "'");
                //DbClass.executequery(CommandType.Text, "Update route.tblLicense set LastLoginDate = '" + DateTime.Today.ToString("yyyy/MM/dd") + "' where LicenseKey = '" + PublicClass.InstrumentSerial + "'");
                if (PublicClass.currentInstrument == Convert.ToString(dtt.Rows[0]["Instrumentname"]))
                {
                    foreach (DataRow dr in dtt.Rows)
                    {
                        lastdbName = Convert.ToString(dr["DBName"]);
                    }
                    PublicClass.User_DataBase = lastdbName;

                    if (PublicClass.conn.State == ConnectionState.Open)
                    {
                        PublicClass.conn.Close();
                    }
                    PublicClass.CreateConnection(lastdbName);
                    if (String.IsNullOrEmpty(txtID.Text))
                    {
                        MessageBox.Show(this, "Please Enter The ID.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    if (String.IsNullOrEmpty(txtPassword.Text))
                    {
                        MessageBox.Show(this, "Please Enter The Password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    if (cmbdata.SelectedIndex == 0)
                    {
                        MessageBox.Show(this, "Please Select any Data Source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show(this, "Please insert right 'Key' for using 'VibAnalyst' ! You are using other key for this 'Instrument'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                PublicClass.cUserName = Convert.ToString(txtID.Text).Trim();
                PublicClass.cPassword = Convert.ToString(txtPassword.Text).Trim();
                DataTable dt1 = new DataTable();
                dt1 = DbClass.getdata(CommandType.Text, "Select ID from userdetail where UserName = '******'  and Password = '******'");
                foreach (DataRow dr in dt1.Rows)
                {
                    PublicClass.cUID = Convert.ToString(dr["ID"]);
                }
                DataTable dt = new DataTable();
                dt = DbClass.getdata(CommandType.Text, "Select distinct  User_ID ,uPassword from login_data where  user_id= '" + Convert.ToString(txtID.Text).Trim() + "' and upassword = '******'");
                if (dt.Rows.Count <= 0)
                {
                    MessageBox.Show(this, "Please Enter the valid Id and Password", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtID.Text       = "";
                    txtPassword.Text = "";
                    return;
                }
                else
                {
                    int uchk = String.Compare(Convert.ToString(dt.Rows[0]["User_ID"]), PublicClass.cUserName);
                    int pchk = String.Compare(Convert.ToString(dt.Rows[0]["upassword"]), PublicClass.cPassword);

                    if (uchk == 0 && pchk == 0)
                    {
                        PublicClass.LoginStatus = true;
                        this.Close();
                        PublicClass.User_Name = Convert.ToString(txtID.Text).Trim();
                        DbClass.executequery(CommandType.Text, "Update userdetail set Login = '******' , LastloginDate = '" + PublicClass.GetDatetime() + "'where ID = '" + PublicClass.cUID + "'");
                    }
                    else
                    {
                        MessageBox.Show(this, "You have entered wrong user name or password...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtID.Text       = "";
                        txtPassword.Text = "";
                    }
                }
                //}
                //else
                //{
                //    MessageBox.Show("Please insert right 'Key' or correct your system date & time or contact vendor !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    Process.GetCurrentProcess().Kill();
                //}
            }
            catch { }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string lastdbName = null;

                PublicClass.CreateConnection("route");
                PublicClass.currentInstrument = cmbdata.SelectedItem.ToString();
                DataTable dtt = new DataTable();
                dtt = DbClass.getdata(CommandType.Text, "select * from route.lastdatabase where Instrumentname='" + PublicClass.currentInstrument + "'");

                foreach (DataRow dr in dtt.Rows)
                {
                    lastdbName = Convert.ToString(dr["DBName"]);
                }
                PublicClass.User_DataBase = lastdbName;

                if (PublicClass.conn.State == ConnectionState.Open)
                {
                    PublicClass.conn.Close();
                }
                PublicClass.CreateConnection(lastdbName);
                if (String.IsNullOrEmpty(txtID.Text))
                {
                    MessageBox.Show(this, "Please Enter The ID.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (String.IsNullOrEmpty(txtPassword.Text))
                {
                    MessageBox.Show(this, "Please Enter The Password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (cmbdata.SelectedIndex == 0)
                {
                    MessageBox.Show(this, "Please Select any Data Source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                PublicClass.cUserName = Convert.ToString(txtID.Text).Trim();
                PublicClass.cPassword = Convert.ToString(txtPassword.Text).Trim();
                DataTable dt1 = new DataTable();
                dt1 = DbClass.getdata(CommandType.Text, "Select ID from userdetail where UserName = '******'  and Password = '******'");
                foreach (DataRow dr in dt1.Rows)
                {
                    PublicClass.cUID = Convert.ToString(dr["ID"]);
                }
                DataTable dt = new DataTable();
                dt = DbClass.getdata(CommandType.Text, "Select distinct  User_ID ,uPassword from login_data where  user_id= '" + Convert.ToString(txtID.Text).Trim() + "' and upassword = '******'");
                if (dt.Rows.Count <= 0)
                {
                    MessageBox.Show(this, "Please Enter the valid Id and Password", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtID.Text       = "";
                    txtPassword.Text = "";
                    return;
                }
                else
                {
                    int uchk = String.Compare(Convert.ToString(dt.Rows[0]["User_ID"]), PublicClass.cUserName);
                    int pchk = String.Compare(Convert.ToString(dt.Rows[0]["upassword"]), PublicClass.cPassword);

                    if (uchk == 0 && pchk == 0)
                    {
                        PublicClass.LoginStatus = true;
                        this.Close();
                        PublicClass.User_Name = Convert.ToString(txtID.Text).Trim();
                        DbClass.executequery(CommandType.Text, "Update userdetail set Login = '******' , LastloginDate = '" + PublicClass.GetDatetime() + "'where ID = '" + PublicClass.cUID + "'");
                    }
                    else
                    {
                        MessageBox.Show(this, "You have entered wrong user name or password...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtID.Text       = "";
                        txtPassword.Text = "";
                    }
                }
            }
            catch { }
        }