예제 #1
0
        public void Save(WorkingDataBase db)
        {
            String selectSql = "Select [DBID] from [WorkDataBase] Where [DBName]='" + db.Name + "' And [DBYear]='" + db.Year + "' And [DBNo]<>'" + db.Code + "' ";

            if (new SqlCon().GetTable(selectSql).Rows.Count > 0)
            {
                throw new Exception("无法保存登录设置,保存会与现有登录冲突");
            }

            EncryptionClass entry = new EncryptionClass(db.PassWord);
            //    user.pwd1 = entry.EncrKey;
            //    user.pwd2 = entry.EnIndex;
            //    user.pwd3 = entry.IV;
            //    user.pwd4 = entry.IvIndex;
            //    user.pwd5 = entry.EncryString;

            String updateSql = @"UPDATE [WorkDataBase]
   SET [DBName] = '" + db.Name + @"'
      ,[DBYear] ='" + db.Year + @"'
      ,[DBSysName] ='" + db.SysName + @"'
      ,[IsActive] = '" + System.Convert.ToInt32(db.IsActive) + @"'
      
      ,[pwd1] = " + ByteToString(entry.EncrKey) + @"
      ,[pwd2] = " + ByteToString(entry.EnIndex) + @"
      ,[pwd3] = " + ByteToString(entry.IV) + @"
      ,[pwd4] =" + ByteToString(entry.IvIndex) + @"
      ,[pwd5] = '" + entry.EncryString + @"'
      ,[UserName] = '" + db.UserName + @"'
      ,[CompanyName] = '" + db.CompanyName + @"'
      ,[ServerIp]='" + db.ServerIp + @"'
      ,[IsLocal]='" + System.Convert.ToInt32(db.IsLocal) + @"'
        WHERE [DBNo]='" + db.Code + "'";

            new SqlCon().ExcuteSql(updateSql);
        }
예제 #2
0
        private void Init(DataRow i)
        {
            this.Name        = i["DBName"].ToString();
            this.SysName     = i["DBSysName"].ToString();
            this.Year        = i["DBYear"].ToString();
            this.IsActive    = System.Convert.ToBoolean(i["IsActive"]);
            this.Code        = i["DBNo"].ToString();
            this.CompanyName = i["CompanyName"].ToString();
            this.ServerIp    = i["ServerIp"].ToString();

            try
            {
                EncryptionClass entry = new EncryptionClass();
                entry.EncrKey     = i["pwd1"] as byte[];
                entry.EnIndex     = i["pwd2"] as byte[]; // ToArray();
                entry.IV          = i["pwd3"] as byte[]; // ToArray();
                entry.IvIndex     = i["pwd4"] as byte[]; // ToArray();
                entry.EncryString = i["pwd5"].ToString();
                PassWord          = entry.Decrypt();
                this.UserName     = i["UserName"].ToString();

                this.IsLocal = (bool)i["IsLocal"];
            }
            catch
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(Global.ConnectionString);
                this.UserName = builder.UserID;
                this.PassWord = builder.Password;
                new WorkDataBaseFactory().Save(this);
            }
        }
예제 #3
0
        public void Create(WorkingDataBase db)
        {
            //using (DBDataDataContext contect = DBDataDataContext.Instance)
            //{

            String selectSql = "Select [DBID] from [WorkDataBase] Where [DBName]='" + db.Name + "' And [DBYear]='" + db.Year + "'";

            if (new SqlCon().GetTable(selectSql).Rows.Count > 0)
            {
                throw new Exception("不能创建名称,年度相同的帐套");
            }
            else
            {
                var NoSql = "Select Max(DBNo) from  [WorkDataBase]";

                var    noTable = new SqlCon().GetTable(NoSql);
                var    topno   = noTable.Rows[0][0];
                String dbNo;
                if (topno == null ||
                    (topno is DBNull))
                {
                    dbNo = "01";
                }
                else
                {
                    dbNo = (System.Convert.ToInt32(topno.ToString()) + 1).ToString().PadLeft(2, '0');
                }


                EncryptionClass entry = new EncryptionClass(db.PassWord);
                //user.pwd1 = entry.EncrKey;
                //user.pwd2 = entry.EnIndex;
                //user.pwd3 = entry.IV;
                //user.pwd4 = entry.IvIndex;
                //user.pwd5 = entry.EncryString;

                String InsertSql = @"INSERT INTO  [WorkDataBase]
           ([DBName]
           ,[DBYear]
           ,[DBSysName]
           ,[IsActive]
           ,[DBNo]
           ,[pwd1]
           ,[pwd2]
           ,[pwd3]
           ,[pwd4]
           ,[pwd5]
           ,[UserName]
           ,[CompanyName]
           ,[ServerIp])
     VALUES
           ('" + db.Name + @"'
           ,'" + db.Year + @"'
           ,'" + db.SysName + @"'
           ,'" + System.Convert.ToInt32(db.IsActive).ToString() + @"'
           ,'" + dbNo + @"'
           ," + ByteToString(entry.EncrKey) + @"
           ," + ByteToString(entry.EnIndex) + @"
           ," + ByteToString(entry.IV) + @"
           ," + ByteToString(entry.IvIndex) + @"
           ,'" + entry.EncryString + @"'
           ,'" + db.UserName + @"'
             ,'" + db.CompanyName + @"'
           ,'" + db.ServerIp + @"')";
                new SqlCon().ExcuteSql(InsertSql);
            }
//                WorkDataBase user = new WorkDataBase();
//                var q = from db1 in contect.WorkDataBases
//                        where db1.DBName == db.Name
//                        && db.Year == db1.DBYear
//                        select db1 ;
//                if (q.Count() > 0)
//                {
//                    throw new Exception("不能创建名称,年度相同的帐套");
//                }
//                  var q2=contect.WorkDataBases ;
//                    if (q2.Count() > 0)
//                    {
//                        user.DBNo  = (System.Convert.ToInt32(q2.Max(p => p.DBNo ))+1).ToString().PadLeft(2, '0');
//                    }
//                    else
//                        user.DBNo  =  "01";


//                user.UserName = db.UserName;
//                user.DBYear = db.Year;
//                user.DBSysName = db.SysName;
//                user.IsActive = db.IsActive;
//                user.DBName = db.Name;

//                EncryptionClass entry = new EncryptionClass(db.PassWord);
//                user.pwd1 = entry.EncrKey;
//                user.pwd2 = entry.EnIndex;
//                user.pwd3 = entry.IV;
//                user.pwd4 = entry.IvIndex;
//                user.pwd5 = entry.EncryString;

//                contect.WorkDataBases.InsertOnSubmit(user);
//                contect.SubmitChanges();
//            }
        }