Beispiel #1
0
        private void LoadData()
        {
            AccountObject   obj;
            AccountObject   objOprt;
            string          DefNo = SystemInfo.ini.ReadIni("Public", "OprtNo", "");
            Database        dbEx  = null;
            DataTableReader dr    = null;

            cbbOpter.Items.Clear();
            if (cbbAccount.SelectedIndex == -1)
            {
                return;
            }
            obj = (AccountObject)cbbAccount.Items[cbbAccount.SelectedIndex];
            SystemInfo.AccIsForward = obj.IsForward;
            SystemInfo.AccDBVersion = "";
            SystemInfo.DatabaseName = obj.Value;
            SystemInfo.AccDBName    = obj.Name;
            dbEx = new Database(GetConnStr(SystemInfo.DatabaseName));
            try
            {
                dbEx.Open();
                dr = dbEx.GetDataReader(Pub.GetSQL(DBCode.DB_000002, new string[] { "1" }));
                while (dr.Read())
                {
                    objOprt       = new AccountObject();
                    objOprt.Name  = dr["OprtName"].ToString();
                    objOprt.Value = dr["OprtNo"].ToString();
                    objOprt.Text  = objOprt.Value + "[" + objOprt.Name + "]";
                    cbbOpter.Items.Add(objOprt);
                    if ((DefNo != "") && (objOprt.Value == DefNo))
                    {
                        cbbOpter.SelectedIndex = cbbOpter.Items.Count - 1;
                    }
                }
                dr.Close();
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                dr = null;
                dbEx.Close();
            }
            if ((cbbOpter.SelectedIndex == -1) && (cbbOpter.Items.Count > 0))
            {
                cbbOpter.SelectedIndex = 0;
            }
            btnOk.Enabled = (cbbOpter.SelectedIndex >= 0);
        }
Beispiel #2
0
        private void LoadAccount()
        {
            string          DatabaseName = SystemInfo.ini.ReadIni("Public", "DatabaseName", "");
            DataTableReader dr           = null;
            string          AccName;
            string          DBName;
            bool            IsForward;
            AccountObject   obj;
            bool            IsError = false;

            cbbAccount.Items.Clear();
            try
            {
                if (!db.IsOpen)
                {
                    db.Open(SystemInfo.ConnStr);
                }
                db.CreateAccountTable();
                dr = db.GetDataReader(Pub.GetSQL(DBCode.DB_000001, new string[] { "100" }));
                if (!dr.Read() && (SystemInfo.DBType == 2))
                {
                    DBName = "ECard" + DateTime.Now.ToString(SystemInfo.YMFormatDB);
                    string FileName = db.GetDatabasePath().ToString() + SystemInfo.DefaultDBBak;
                    string DBPath   = db.GetDatabasePath().ToString();
                    if (!db.CreateDatabase(DBPath, DBName))
                    {
                        db.DeleteDatabase(DBName, true);
                    }
                    else if (!db.RestoreDatabase(DBName, FileName))
                    {
                        db.DeleteDatabase(DBName, true);
                    }
                    else
                    {
                        bool     IsOk = true;
                        string   fn   = FileName.Substring(FileName.LastIndexOf("\\") + 1).ToLower();
                        Database dbEx = new Database(GetConnStr(DBName));
                        try
                        {
                            dbEx.Open();
                            if (IsOk && (fn == SystemInfo.DefaultDBBak.ToLower()))
                            {
                                IsOk = dbEx.UpdateDatabasesLang();
                            }
                            if (IsOk)
                            {
                                string sql = Pub.GetSQL(DBCode.DB_000001, new string[] { "801", DBName, DBName, DBPath + DBName });
                                db.ExecSQL(sql);
                            }
                        }
                        catch (Exception E)
                        {
                            IsOk = false;
                            Pub.ShowErrorMsg(E);
                        }
                        finally
                        {
                            dbEx.Close();
                            dbEx = null;
                        }
                        if (!IsOk)
                        {
                            db.DeleteDatabase(DBName, true);
                        }
                    }
                }
                dr.Close();
                dr = db.GetDataReader(Pub.GetSQL(DBCode.DB_000001, new string[] { "100" }));
                while (dr.Read())
                {
                    AccName   = dr["AccName"].ToString();
                    DBName    = dr["DBName"].ToString();
                    IsForward = ((dr["IsForward"].ToString() == "Y") || GetForwardState(DBName));
                    obj       = new AccountObject();
                    obj.Text  = AccName;
                    if (IsForward)
                    {
                        obj.Text = obj.Text + "[" + Pub.GetResText(formCode, "AccForwardY", "") + "]";
                    }
                    obj.Name      = AccName;
                    obj.Value     = DBName;
                    obj.IsForward = IsForward;
                    cbbAccount.Items.Add(obj);
                    if ((AccName == DatabaseName) && !IsForward)
                    {
                        cbbAccount.SelectedIndex = cbbAccount.Items.Count - 1;
                    }
                }
                if (((DatabaseName == "") || (cbbAccount.SelectedIndex == -1)) && (cbbAccount.Items.Count > 0))
                {
                    for (int i = 0; i < cbbAccount.Items.Count; i++)
                    {
                        obj = (AccountObject)cbbAccount.Items[i];
                        if (!obj.IsForward)
                        {
                            cbbAccount.SelectedIndex = i;
                            break;
                        }
                    }
                }
                if ((cbbAccount.SelectedIndex == -1) && (cbbAccount.Items.Count > 0))
                {
                    cbbAccount.SelectedIndex = 0;
                }
            }
            catch (Exception E)
            {
                IsError = true;
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                dr = null;
            }
            if (!IsError && (cbbAccount.Items.Count == 0))
            {
                if (!Pub.MessageBoxShowQuestion(Pub.GetResText(formCode, "Msg001", "")))
                {
                    try
                    {
                        System.Diagnostics.Process.Start(SystemInfo.AppPath + "ECardDB78.exe");
                    }
                    catch (Exception E)
                    {
                        Pub.ShowErrorMsg(E);
                    }
                    this.Close();
                }
            }
        }
Beispiel #3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            CheckDBUpdate();
            if (!SameAppVer())
            {
                string msg = Pub.GetResText(formCode, "MsgSameAppVer", "");
                if (DBAppVer.Substring(0, 3) == "2.0" || DBAppVer.Substring(0, 3) == "2.1" || DBAppVer.Substring(0, 3) == "70.")
                {
                    msg = string.Format(msg, "V70.X.X");
                }
                else
                {
                    msg = string.Format(msg, "V78.X.X");
                }
                Pub.ShowErrorMsg(msg);
                return;
            }
            bool CheckApp = SystemInfo.ini.ReadIni("Public", "CheckApp", true);

            if (CheckApp)
            {
                if (!db.CheckAppIsNewVer(true, DBAppVer))
                {
                    Pub.ShowErrorMsg(string.Format(Pub.GetResText(formCode, "Msg003", ""), DBAppVer));
                    return;
                }
            }
            AccountObject   obj     = (AccountObject)cbbOpter.Items[cbbOpter.SelectedIndex];
            string          OprtNo  = obj.Value;
            string          OprtPWD = Pub.GetOprtEncrypt(txtPass.Text.Trim());
            Database        dbEx    = new Database(GetConnStr(SystemInfo.DatabaseName));
            DataTableReader dr      = null;
            bool            IsOk    = false;
            string          Pass    = "";

            if (IsRePassword && chkPass.Checked && !PassIsChange)
            {
                OprtPWD = RePassword;
            }
            try
            {
                dbEx.Open();
                dr = dbEx.GetDataReader(Pub.GetSQL(DBCode.DB_000002, new string[] { "3", OprtNo }));
                if (dr.Read())
                {
                    Pass = dr["OprtPWD"].ToString();
                    if (OprtPWD == "")
                    {
                        OprtPWD = Pub.GetOprtEncrypt("0");
                    }
                    if (Pass == "")
                    {
                        Pass = Pub.GetOprtEncrypt("0");
                    }
                    if (Pass != OprtPWD)
                    {
                        txtPass.Focus();
                        Pub.ShowErrorMsg(Pub.GetResText(formCode, "Error002", ""));
                    }
                    else
                    {
                        IsOk = true;
                    }
                    if ((IsOk) && (dr["OprtIsActive"].ToString() != "Y"))
                    {
                        cbbOpter.Focus();
                        Pub.ShowErrorMsg(Pub.GetResText(formCode, "Error003", ""));
                        IsOk = false;
                    }
                    if (IsOk)
                    {
                        DateTime dt1     = Convert.ToDateTime(dr["OprtStartDay"]);
                        DateTime dt2     = Convert.ToDateTime(dr["OprtEndDay"]);
                        DateTime svrDate = new DateTime();
                        if (!db.GetServerDate(ref svrDate))
                        {
                            return;
                        }
                        string msg = string.Format(Pub.GetResText(formCode, "Error000", ""), dt1, dt2, svrDate);
                        if (dt1 > svrDate)
                        {
                            cbbOpter.Focus();
                            Pub.ShowErrorMsg(Pub.GetResText(formCode, "Error004", "") + msg);
                            IsOk = false;
                        }
                        if (dt2 < svrDate)
                        {
                            cbbOpter.Focus();
                            Pub.ShowErrorMsg(Pub.GetResText(formCode, "Error005", "") + msg);
                            IsOk = false;
                        }
                    }
                    if (IsOk)
                    {
                        OprtInfo.OprtSysID        = dr["OprtSysID"].ToString();
                        OprtInfo.OprtNo           = OprtNo;
                        OprtInfo.OprtIsSys        = (dr["RoleIsSys"].ToString() == "Y");
                        OprtInfo.DepartPower      = "";
                        OprtInfo.DepartPowerSysID = "";
                        if (!OprtInfo.OprtIsSys)
                        {
                            dr.Close();
                            dr = dbEx.GetDataReader(Pub.GetSQL(DBCode.DB_000003, new string[] { "108", OprtInfo.OprtSysID }));
                            while (dr.Read())
                            {
                                OprtInfo.DepartPower      = OprtInfo.DepartPower + " OR DepartID='" + dr["DepartID"].ToString() + "'";
                                OprtInfo.DepartPowerSysID = OprtInfo.DepartPowerSysID + " OR DepartSysID='" +
                                                            dr["DepartSysID"].ToString() + "'";
                            }
                            if (OprtInfo.DepartPower == "")
                            {
                                OprtInfo.DepartPower      = " AND (1=2)";
                                OprtInfo.DepartPowerSysID = " AND (1=2)";
                            }
                            else
                            {
                                OprtInfo.DepartPower      = " AND (DepartID IS NULL OR DepartID='' OR " + OprtInfo.DepartPower.Substring(4) + ")";
                                OprtInfo.DepartPowerSysID = " AND (OR DepartSysID IS NULL OR DepartSysID='' OR " + OprtInfo.DepartPowerSysID.Substring(4) + ")";
                            }
                        }
                        OprtInfo.OprtNoAndName = cbbOpter.Text;
                        SystemInfo.ini.WriteIni("Public", "OprtNo", OprtInfo.OprtNo);
                        if (chkPass.Checked)
                        {
                            SystemInfo.ini.WriteIni("Public", "IsRePassword", IsRePassword);
                            SystemInfo.ini.WriteIni("Public", "RePassword", OprtPWD);
                        }
                        else
                        {
                            SystemInfo.ini.WriteIni("Public", "IsRePassword", "");
                            SystemInfo.ini.WriteIni("Public", "RePassword", "");
                        }
                        SystemInfo.ini.WriteIni("Public", "DatabaseName", SystemInfo.AccDBName);
                        dbEx.ExecSQL(Pub.GetSQL(DBCode.DB_000002, new string[] { "4", OprtNo }));
                        dr.Close();
                        dr = dbEx.GetDataReader(Pub.GetSQL(DBCode.DB_000002, new string[] { "101" }));
                        if (dr.Read())
                        {
                            SystemInfo.CommanyName  = dr["DepartName"].ToString();
                            SystemInfo.CommanySysID = dr["DepartSysID"].ToString();
                        }
                        dbEx.ExecSQL(Pub.GetSQL(DBCode.DB_000002, new string[] { "6", SystemInfo.CardValidDays.ToString() }));
                        dbEx.ExecSQL(Pub.GetSQL(DBCode.DB_000001, new string[] { "3001",
                                                                                 Pub.GetOprtEncrypt(DeviceObject.objCPIC.GetMacTAG()) }));
                        if (SystemInfo.ini.ReadIni("Public", "NotCheckSF", false))
                        {
                            dbEx.CheckSFDataCount();
                        }
                    }
                }
            }
            catch (Exception E)
            {
                IsOk = false;
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                dr = null;
                dbEx.Close();
            }
            if (IsOk)
            {
                this.Close();
                this.DialogResult        = DialogResult.OK;
                SystemInfo.ConnStr       = GetConnStr(SystemInfo.DatabaseName);
                SystemInfo.ConnStrReport = GetConnStrReport(SystemInfo.DatabaseName);
            }
        }