コード例 #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string strCompanyID;

            try
            {
                if (strType == "Select")
                {
                    if (lvDetails.SelectedItems.Count > 0)
                    {
                        ListViewItem itm = lvDetails.SelectedItems[0];
                        strCompanyID = itm.SubItems[0].Text;

                        RegistryKey regKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\SmartAccounts");
                        if (regKey != null)
                        {
                            //string user = Environment.UserDomainName + "\\" + Environment.UserName;
                            //RegistrySecurity rs = new RegistrySecurity();
                            //rs.AddAccessRule(new RegistryAccessRule(user, RegistryRights.ReadKey | RegistryRights.WriteKey | RegistryRights.Delete, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow));//To allow permission
                            //RegistryKey rk = Registry.CurrentUser.CreateSubKey("SOFTWARE\\SmartAccounts");
                            regKey.SetValue("CompanyID", strCompanyID);
                            regKey.Close();
                        }

                        Utility.strDataBase = "SMART" + strCompanyID;
                        Utility.gSelectCompanyName(strCompanyID, "NO");
                        //string s = accms.gSelectCompanyName(strCompanyID);
                        if (Utility.gblnAccessControl == true)
                        {
                            if (System.Windows.Forms.Application.OpenForms["frmMain"] as frmERMain == null)
                            {
                                frmERMain objfrmmain = new frmERMain();
                                //objfrmmain.intCheckBackup = 1;
                                objfrmmain.Close();
                            }
                            else
                            {
                                ((frmERMain)Application.OpenForms["frmERMain"]).Text = Utility.gstrCompanyID + "-" + Utility.gstrCompanyName + " - " + Convert.ToDateTime(Utility.gdteFinancialYearFrom).ToString(Utility.DEFAULT_DATE_FORMAT)
                                                                                       + " to " + Convert.ToDateTime(Utility.gdteFinancialYearTo).ToString(Utility.DEFAULT_DATE_FORMAT);
                                frmERMain objfrm = (frmERMain)Application.OpenForms["frmERMain"];
                                //objfrm.intCheckBackup = 1;
                                objfrm.Close();
                            }
                            this.Close();

                            //if (System.Windows.Forms.Application.OpenForms["frmLogIn"] as frmELogIn == null)
                            //{

                            //    frmELogIn objfrmlogin = new frmELogIn();
                            //    objfrmlogin.mload();
                            //    objfrmlogin.ShowDialog();


                            //}
                            //else
                            //{
                            //    frmELogIn objfrmlogin = (frmELogIn)Application.OpenForms["frmELogIn"];
                            //    objfrmlogin.mload();
                            //    objfrmlogin.Show();
                            //    objfrmlogin.Focus();

                            //}

                            //frmLogIn objfrmlogin = new frmLogIn();
                            //objfrmlogin.ShowDialog();
                        }
                        else
                        {
                            //this.Dispose();
                            //frmMain objfrm = new frmMain();
                            ////((frmMain)Application.OpenForms["frmMain"]).Text = s;
                            //objfrm.Refresh();

                            //((frmMain)Application.OpenForms["frmMain"]).Text = Utility.gstrCompanyID + "-" + Utility.gstrCompanyName + " - " + Convert.ToDateTime(Utility.gdteFinancialYearFrom).ToString(Utility.DEFAULT_DATE_FORMAT)
                            //                                                + " to " + Convert.ToDateTime(Utility.gdteFinancialYearTo).ToString(Utility.DEFAULT_DATE_FORMAT);

                            if (System.Windows.Forms.Application.OpenForms["frmERMain"] as frmERMain == null)
                            {
                                frmERMain objfrmmain = new frmERMain();
                                //objfrmmain.intCheckBackup = 1;
                                //objfrmmain.Show();
                            }
                            else
                            {
                                ((frmERMain)Application.OpenForms["frmERMain"]).Text = Utility.gstrCompanyID + "-" + Utility.gstrCompanyName + " - " + Convert.ToDateTime(Utility.gdteFinancialYearFrom).ToString(Utility.DEFAULT_DATE_FORMAT)
                                                                                       + " to " + Convert.ToDateTime(Utility.gdteFinancialYearTo).ToString(Utility.DEFAULT_DATE_FORMAT);
                                frmERMain objfrm = (frmERMain)Application.OpenForms["frmERMain"];
                                //objfrm.intCheckBackup = 1;
                                objfrm.Focus();
                            }
                            this.Close();
                        }
                    }
                }

                else
                {
                    if (lvDetails.SelectedItems.Count > 0)
                    {
                        ListViewItem itm = lvDetails.SelectedItems[0];
                        strCompanyID = "SMART" + itm.SubItems[0].Text;
                        string strmsg = Utility.DeleteCompnay(itm.SubItems[0].Text, strCompanyID);
                        if (strmsg == "1")
                        {
                            //Utility.creaateWrite("0001");
                            Utility.Kill("DeepLaid");
                            this.Dispose();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #2
0
ファイル: frmELogIn.cs プロジェクト: kawserkibria/MobileERP
        private void btnLogon_Click(object sender, EventArgs e)
        {
            string        strSQL, strPassword = "";
            int           intUserLebel = 0;
            SqlDataReader rsget;

            //uctxtPassword.Text = "Smart420";

            strSQL = "SELECT USER_LOGIN_SERIAL,USER_LOGIN_NAME,USER_PASS,USER_LEBEL,USER_STATUS FROM USER_CONFIG ";
            strSQL = strSQL + "WHERE USER_LOGIN_NAME = '" + uctxtLogIn.Text.Trim().Replace("'", "''") + "' ";

            using (SqlConnection gcnMain = new SqlConnection(Utility.SQLConnstring()))
            {
                if (gcnMain.State == ConnectionState.Open)
                {
                    gcnMain.Close();
                }
                gcnMain.Open();

                SqlCommand cmd = new SqlCommand(strSQL, gcnMain);
                rsget = cmd.ExecuteReader();
                if (rsget.Read())
                {
                    intUserLebel         = Convert.ToInt32(rsget["USER_LEBEL"].ToString());
                    Utility.gstrUserName = rsget["USER_LOGIN_NAME"].ToString();
                    if (rsget["USER_STATUS"].ToString() == "S")
                    {
                        MessageBox.Show("Sorry, The User's has been suspended, Please contact with Administrator");
                        uctxtLogIn.Focus();
                        return;
                    }
                    strPassword = Utility.Decrypt(rsget["USER_PASS"].ToString(), rsget["USER_LOGIN_NAME"].ToString()).ToString();

                    if (uctxtPassword.Text.Trim() != strPassword.Trim())
                    {
                        MessageBox.Show("Login failed. Make sure user name and password are correct.");
                        uctxtPassword.Text = "";
                        uctxtPassword.Focus();
                        return;
                    }
                    rsget.Close();
                    gcnMain.Dispose();
                    uctxtPassword.Text   = "";
                    Utility.gstrUserName = uctxtLogIn.Text.Trim().Replace("'", "''");
                    if (intUserLebel == 1)
                    {
                        Utility.gblnAdminPrv = true;
                    }
                    else if (intUserLebel == 2)
                    {
                        Utility.gblnAdminPrv = false;
                    }

                    this.Hide();
                    //Interaction.SaveSetting(Application.ExecutablePath, "sUser", "sName", uctxtLogIn.Text);
                    RegistryKey rk = Registry.CurrentUser.CreateSubKey("SOFTWARE\\SmartAccounts");
                    rk.SetValue("sName", uctxtLogIn.Text);
                    rk.Close();
                    if (System.Windows.Forms.Application.OpenForms["frmMain"] as frmERMain == null)
                    {
                        frmERMain objfrm = new frmERMain();
                        objfrm.Show();
                    }
                    else
                    {
                        ((frmERMain)Application.OpenForms["frmERMain"]).Text = Utility.gstrCompanyID + "-" + Utility.gstrCompanyName + " - " + Convert.ToDateTime(Utility.gdteFinancialYearFrom).ToString(Utility.DEFAULT_DATE_FORMAT)
                                                                               + " to " + Convert.ToDateTime(Utility.gdteFinancialYearTo).ToString(Utility.DEFAULT_DATE_FORMAT);

                        frmERMain objfrm = (frmERMain)Application.OpenForms["frmERMain"];
                        objfrm.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Login failed. Make sure user name and password are correct.");
                    uctxtLogIn.Focus();
                    uctxtPassword.Text = "";
                    rsget.Close();
                    gcnMain.Dispose();
                    return;
                }
            }
        }