Ejemplo n.º 1
0
        private void UpdateServerData()
        {
            if (mEdited.Count == 0)
            {
                MessageBox.Show("변경사항이 없으므로 저장할 데이터가 없습니다.", "저장하지 않음", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            string accType = ParentWindow.Client.AccountType;

            if (!AuthorityChecker.CheckAuthority(accType, mCurrentGrade, mCurrentClass, AccessType.Edit, ObjectToAccess.Attendance))
            {
                MessageBox.Show("데이터를 수정할 권한이 없습니다.\n\n특정 학급의 출석부를 수정하려면 그 학급의 담임이여야 합니다.",
                                "권한 없음", MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }

            foreach (int index in mEdited)
            {
                TcpDataUpdate update = new TcpDataUpdate();
                update.TableName = "출석부";
                update.Setter.Add($"[{mCurrentPeriod}교시]", ((int)StrToAttDict[mTable.Rows[index]["출석상태"].ToString()]).ToString());
                update.Where = $"[일자]=#{mOriginal.Rows[index]["일자"]}# AND [학년]={mOriginal.Rows[index]["학년"].ToString().ToSQLString()} AND [반]={mOriginal.Rows[index]["반"].ToString().ToSQLString()} AND [번호]={mOriginal.Rows[index]["번호"].ToString().ToSQLString()}";

                ParentWindow.Client.UpdateData(update);
            }

            mEdited.Clear();
            Save.IsEnabled   = false;
            Cancel.IsEnabled = false;
            mOriginal        = mTable.Copy();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            DatabaseManager.Initialize();

            TcpAccountInfo accInfo = new TcpAccountInfo("root", "123qweasd", "김정현", "Super");

            if (DatabaseManager.TryToRegister(accInfo, false))
            {
                Console.WriteLine("root 계정을 추가하였습니다.");
            }
            else
            {
                Console.WriteLine("root 계정이 이미 있으므로 추가하지 않았습니다.");
            }

            TcpLoginInfo loginInfo1 = new TcpLoginInfo("wrong", "123qweasd");
            TcpLoginInfo loginInfo2 = new TcpLoginInfo("root", "wrong");
            TcpLoginInfo loginInfo3 = new TcpLoginInfo("root", "123qweasd");

            Console.WriteLine(DatabaseManager.MatchLoginInfo(loginInfo1).ToString());
            Console.WriteLine(DatabaseManager.MatchLoginInfo(loginInfo2).ToString());
            Console.WriteLine(DatabaseManager.MatchLoginInfo(loginInfo3).ToString());

            TcpDataInsert         insert = new TcpDataInsert();
            List <DatabaseValues> values = new List <DatabaseValues>();

            values.Add(new DatabaseValues("#2000-8-14#", "99".ToSQLString(), "99".ToSQLString(), "99".ToSQLString(), "김정현".ToSQLString(), "1", "1", "1", "1", "1", "1", "1", "1", "1"));
            values.Add(new DatabaseValues("#2000-8-14#", "99".ToSQLString(), "99".ToSQLString(), "100".ToSQLString(), "김정현".ToSQLString(), "1", "1", "1", "1", "1", "1", "1", "1", "1"));
            values.Add(new DatabaseValues("#2000-8-14#", "99".ToSQLString(), "99".ToSQLString(), "101".ToSQLString(), "김정현".ToSQLString(), "1", "1", "1", "1", "1", "1", "1", "1", "1"));

            insert.ColumnsText = "";
            insert.TableName   = "출석부";
            insert.Values      = values;

            Console.WriteLine($"출석부에 {DatabaseManager.DBInsert(insert)}개 줄이 추가됨.");

            TcpDataUpdate update = new TcpDataUpdate();

            update.TableName = "출석부";
            update.Setter.Add("[0교시]", "2");
            update.Setter.Add("[1교시]", "2");
            update.Setter.Add("[2교시]", "2");
            update.Setter.Add("[3교시]", "2");
            update.Where = "[일자]=#2000-8-14# AND 학년=\"99\" AND 반=\"99\" AND 번호=\"99\"";


            Console.WriteLine($"출석부에서 {DatabaseManager.DBUpdate(update)}개 줄이 업데이트됨.");

            TcpDataDelete delete = new TcpDataDelete();

            delete.TableName = "[출석부]";
            delete.Where     = "[일자]=#2000-8-14# AND 학년=\"99\" AND 반=\"99\" AND 번호=\"99\"";

            Console.WriteLine($"출석부에서 {DatabaseManager.DBDelete(delete)}개 줄이 삭제됨.");

            DatabaseManager.Close();
        }
Ejemplo n.º 3
0
        public static int DBUpdate(TcpDataUpdate dataUpdate)
        {
            if (dataUpdate == null)
            {
                throw new ArgumentNullException(nameof(dataUpdate));
            }
            if (string.IsNullOrWhiteSpace(dataUpdate.TableName))
            {
                throw new ArgumentException("테이블명은 공백이거나 null 일 수 없습니다.", nameof(dataUpdate.TableName));
            }
            if (string.IsNullOrWhiteSpace(dataUpdate.Where))
            {
                throw new ArgumentException("조건문은 공백이거나 null 일 수 없습니다.", nameof(dataUpdate.Where));
            }
            if (dataUpdate.Setter == null)
            {
                throw new ArgumentNullException(nameof(dataUpdate.Setter));
            }
            if (dataUpdate.Setter.Count == 0)
            {
                throw new ArgumentException("치환할 값이 설정되지 않았습니다.");
            }

            OleDbCommand cmd = new OleDbCommand();

            cmd.Connection = mConnection;
            int sum = 0;

            StringBuilder sb = new StringBuilder();

            sb.Append($"UPDATE {dataUpdate.TableName} SET ");
            KeyValuePair <string, string>[] setters = dataUpdate.Setter.ToArray();

            for (int i = 0; i < setters.Length; ++i)
            {
                if (i == setters.Length - 1)
                {
                    sb.Append($"{setters[i].Key}={setters[i].Value} ");
                }
                else
                {
                    sb.Append($"{setters[i].Key}={setters[i].Value}, ");
                }
            }

            sb.Append($"WHERE {dataUpdate.Where}");

            cmd.CommandText = sb.ToString();

            lock (LOCKER)
            {
                sum += cmd.ExecuteNonQuery();
            }

            return(sum);
        }
Ejemplo n.º 4
0
        private void AcceptChecked_Click(object sender, RoutedEventArgs e)
        {
            List <int> rowIndexes = GetCheckedRows();

            if (rowIndexes == null ? true : rowIndexes.Count == 0)
            {
                MessageBox.Show("체크된 항목이 없습니다.", "항목 없음", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
                return;
            }

            string accType = ParentWindow.Client.AccountType;

            if (!AuthorityChecker.CheckAuthority(accType, null, null, AccessType.Edit, ObjectToAccess.Accounts))
            {
                MessageBox.Show("데이터를 수정할 권한이 없습니다.\n\n대기중인 계정 목록을 수정하려면 전 학년 총괄 관리자여야 합니다.",
                                "권한 없음", MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }

            MessageBoxResult qResult = MessageBox.Show($"총 {rowIndexes.Count} 개의 계정이 수정됩니다.\n계속하시겠습니까?", "준비 완료", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (qResult == MessageBoxResult.Yes)
            {
                foreach (int index in rowIndexes)
                {
                    TcpDataUpdate update = new TcpDataUpdate();
                    update.TableName = "[교사 목록]";
                    update.Setter.Add("[가입 허가 여부]", "True");
                    update.Where = $"[교사 ID]={mTable.Rows[index]["교사ID"].ToString().ToSQLString()}";

                    ParentWindow.Client.UpdateData(update);
                }

                Clear();
                this.Dispatcher.Invoke(() =>
                {
                    Inquire.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                });
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            DatabaseManager.Initialize();

            Console.Write("서버 데이터베이스 accdb 파일의 경로를 입력하십시오: ");
            string path = Console.ReadLine();

            ServerDatabaseManager.Initialize(path);

            TcpDataSetRequirement stuListReq = new TcpDataSetRequirement(new string[] { "*" }, "[학생 명단]", null, "Val([번호])");
            DataSet stuList = DatabaseManager.DBSelect(stuListReq);

            int attEdited, stuEdited;
            int attEdited_Sum = 0, stuEdited_Sum = 0;

            foreach (DataRow row in stuList.Tables[0].Rows)
            {
                Console.WriteLine($"{row["학년"].ToString()}학년 {row["반"].ToString()}반 {row["번호"].ToString()}번호 작업 중...");

                TcpDataUpdate update = new TcpDataUpdate();
                update.TableName = "[출석부]";
                update.Setter.Add("[성명]", row["성명"].ToString().ToSQLString());
                update.Where = $"[학년]={row["학년"].ToString().ToSQLString()} AND [반]={row["반"].ToString().ToSQLString()} AND [번호]={row["번호"].ToString().ToSQLString()}";
                attEdited    = ServerDatabaseManager.DBUpdate(update);

                update           = new TcpDataUpdate();
                update.TableName = "[학생 명단]";
                update.Setter.Add("[성명]", row["성명"].ToString().ToSQLString());
                update.Where = $"[학년]={row["학년"].ToString().ToSQLString()} AND [반]={row["반"].ToString().ToSQLString()} AND [번호]={row["번호"].ToString().ToSQLString()}";
                stuEdited    = ServerDatabaseManager.DBUpdate(update);

                Console.WriteLine($"출석부에서 {attEdited}개, 학생 명단에서 {stuEdited}개 레코드 편집됨.\n");

                attEdited_Sum += attEdited;
                stuEdited_Sum += stuEdited;
            }

            Console.WriteLine($"최종적으로, 전체 출석부에서 {attEdited_Sum}개 레코드, 학생 명단에서 {stuEdited_Sum}개 레코드 편집됨.");

            ServerDatabaseManager.Close();
            DatabaseManager.Close();
        }
        public bool Update(DataRow oldRow, string newNum, string newName)
        {
            if (oldRow == null)
            {
                throw new ArgumentNullException(nameof(oldRow));
            }

            if (mTable == null)
            {
                return(false);
            }

            bool success = false;

            this.Dispatcher.BeginInvoke((Action)(() =>
            {
                try
                {
                    TcpDataUpdate update = new TcpDataUpdate();
                    update.TableName = "[출석부]";
                    update.Setter.Add("[번호]", newNum.ToSQLString());
                    update.Setter.Add("[성명]", newName.ToSQLString());
                    update.Where = $"[학년]={oldRow["학년"].ToString().ToSQLString()} AND [반]={oldRow["반"].ToString().ToSQLString()} AND [번호]={oldRow["번호"].ToString().ToSQLString()} AND [성명]={oldRow["성명"].ToString().ToSQLString()}";

                    ParentWindow.Client.UpdateData(update);

                    success = true;
                }
                catch (Exception e)
                {
                    MessageBox.Show($"출석부의 데이터를 새로운 번호와 성명으로 수정하는데 실패하였습니다...\n\n디버그용 메세지 : {e.Message}\n{e.StackTrace}", "수정 실패", MessageBoxButton.OK, MessageBoxImage.Error);
                    success = false;
                }

                if (!success)
                {
                    return;
                }

                try
                {
                    TcpDataUpdate update = new TcpDataUpdate();
                    update.TableName = "[학생 명단]";
                    update.Setter.Add("[번호]", newNum.ToSQLString());
                    update.Setter.Add("[성명]", newName.ToSQLString());
                    update.Where = $"[학년]={oldRow["학년"].ToString().ToSQLString()} AND [반]={oldRow["반"].ToString().ToSQLString()} AND [번호]={oldRow["번호"].ToString().ToSQLString()} AND [성명]={oldRow["성명"].ToString().ToSQLString()}";

                    oldRow["번호"] = newNum;
                    oldRow["성명"] = newName;

                    ParentWindow.Client.UpdateData(update);

                    success = true;
                }
                catch (Exception e)
                {
                    MessageBox.Show($"학생 명단의 데이터를 수정하는데 실패하였습니다...\n\n디버그용 메세지 : {e.Message}\n{e.StackTrace}", "수정 실패", MessageBoxButton.OK, MessageBoxImage.Error);
                    success = false;
                }
            })).Wait();

            return(success);
        }