コード例 #1
0
ファイル: frmMain.cs プロジェクト: gregggdavis/schedww2
        private void Delete()
        {
            if (strMenuOption == "User...")
            {
                int Row = fUser.gvwUser.FocusedRowHandle;
                if (Row >= 0)
                {
                    int intUserID =
                        Convert.ToInt32(fUser.gvwUser.GetRowCellValue(fUser.gvwUser.FocusedRowHandle, fUser.gcolUserID).ToString());
                    int intContactID =
                        Convert.ToInt32(fUser.gvwUser.GetRowCellValue(fUser.gvwUser.FocusedRowHandle, fUser.gcolContactID).ToString());

                    if (Message.MsgDelete())
                    {
                        User objUser = new User();
                        objUser.UserID = intUserID;
                        objUser.ContactID = intContactID;
                        if (!objUser.DeleteData())
                        {
                            Message.MsgWarning("User cannot be deleted");
                            fUser.grdUser.Focus();
                            return;
                        }

                        fUser.LoadUser();
                        fUser.grdUser.Focus();
                        fUser.gvwUser.FocusedRowHandle = Row - 1;
                        if (fUser.gvwUser.RowCount > 0)
                        {
                            if (fUser.gvwUser.FocusedRowHandle < 0)
                            {
                                fUser.gvwUser.FocusedRowHandle = 0;
                            }
                        }
                    }
                }
            }
            else if ((strMenuOption == "Contact...") || (strMenuOption == "Instructor...") || (strMenuOption == "Client..."))
            {
                string strtemp = "";
                int Row = fContact.gvwContact.FocusedRowHandle;
                if (Row >= 0)
                {
                    int intID =
                        Convert.ToInt32(
                            fContact.gvwContact.GetRowCellValue(fContact.gvwContact.FocusedRowHandle, fContact.gcolContactID).ToString());
                    strtemp = strMenuOption;
                    strtemp = strtemp.Replace("...", "");

                    if (Message.MsgDelete())
                    {
                        Contact objContact = new Contact();
                        objContact.ContactID = intID;
                        //objContact.DeleteData();
                        if (!objContact.DeleteData())
                        {
                            Message.MsgWarning(strtemp + " cannot be deleted");
                            fContact.grdContact.Focus();
                            return;
                        }

                        fContact.LoadContact(strtemp);
                        fContact.grdContact.Focus();
                        fContact.gvwContact.FocusedRowHandle = Row - 1;
                        if (fContact.gvwContact.RowCount > 0)
                        {
                            if (fContact.gvwContact.FocusedRowHandle < 0)
                            {
                                fContact.gvwContact.FocusedRowHandle = 0;
                            }
                        }
                    }
                }
            }
            else if (strMenuOption == "Department...")
            {
                int Row = fDept.gvwDept.FocusedRowHandle;
                if (Row >= 0)
                {
                    int intDeptID =
                        Convert.ToInt32(fDept.gvwDept.GetRowCellValue(fDept.gvwDept.FocusedRowHandle, fDept.gColDeptID).ToString());
                    int intContactID =
                        Convert.ToInt32(fDept.gvwDept.GetRowCellValue(fDept.gvwDept.FocusedRowHandle, fDept.gColContactID).ToString());

                    if (Message.MsgDelete())
                    {
                        Department objDept = new Department();
                        objDept.DeptID = intDeptID;
                        objDept.ContactID = intContactID;
                        //objDept.DeleteData();
                        if (!objDept.DeleteData())
                        {
                            Message.MsgWarning("Department cannot be deleted");
                            fDept.grdDept.Focus();
                            return;
                        }

                        fDept.LoadDepartment();
                        fDept.grdDept.Focus();
                        fDept.gvwDept.FocusedRowHandle = Row - 1;
                        if (fDept.gvwDept.RowCount > 0)
                        {
                            if (fDept.gvwDept.FocusedRowHandle < 0)
                            {
                                fDept.gvwDept.FocusedRowHandle = 0;
                            }
                        }
                    }
                }
            }
            else if (strMenuOption == "Program...")
            {
                int Row = fProgram.gvwProgram.FocusedRowHandle;
                if (Row >= 0)
                {
                    int intID =
                        Convert.ToInt32(
                            fProgram.gvwProgram.GetRowCellValue(fProgram.gvwProgram.FocusedRowHandle, fProgram.gcolProgID).ToString());

                    if (Message.MsgDelete())
                    {
                        Program objProg = new Program();
                        objProg.ProgramID = intID;
                        //objProg.DeleteData();
                        if (!objProg.DeleteData())
                        {
                            Message.MsgWarning("Program cannot be deleted");
                            fProgram.grdProgram.Focus();
                            return;
                        }

                        fProgram.LoadProgram();
                        fProgram.grdProgram.Focus();
                        fProgram.gvwProgram.FocusedRowHandle = Row - 1;
                        if (fProgram.gvwProgram.RowCount > 0)
                        {
                            if (fProgram.gvwProgram.FocusedRowHandle < 0)
                            {
                                fProgram.gvwProgram.FocusedRowHandle = 0;
                            }
                        }
                    }
                }
            }
            else if (strMenuOption == "Class...")
            {
                int Row = fCourse.gvwCourse.FocusedRowHandle;
                if (Row >= 0)
                {
                    int intID =
                        Convert.ToInt32(
                            fCourse.gvwCourse.GetRowCellValue(fCourse.gvwCourse.FocusedRowHandle, fCourse.gcolCourseId).ToString());

                    if (Message.MsgDelete())
                    {
                        Course objCourse = new Course();
                        objCourse.CourseId = intID;
                        //objCourse.DeleteData();
                        if (!objCourse.DeleteData())
                        {
                            Message.MsgWarning("Class cannot be deleted");
                            fCourse.grdCourse.Focus();
                            return;
                        }

                        fCourse.LoadCourse();
                        fCourse.grdCourse.Focus();
                        fCourse.gvwCourse.FocusedRowHandle = Row - 1;
                        if (fCourse.gvwCourse.RowCount > 0)
                        {
                            if (fCourse.gvwCourse.FocusedRowHandle < 0)
                            {
                                fCourse.gvwCourse.FocusedRowHandle = 0;
                            }
                        }
                    }
                }
            }
            else if (strMenuOption == "Event...")
            {
                int Row = fEvt.gvwEvent.FocusedRowHandle;
                bool IsRecur = false;

                if (Row >= 0)
                {
                    int intID =
                        Convert.ToInt32(fEvt.gvwEvent.GetRowCellValue(fEvt.gvwEvent.FocusedRowHandle, fEvt.gcolEventID).ToString());
                    int intCalID =
                        Convert.ToInt32(fEvt.gvwEvent.GetRowCellValue(fEvt.gvwEvent.FocusedRowHandle, fEvt.colCalendarEventID).ToString());
                    int CourseId = Convert.ToInt32(fEvt.gvwEvent.GetRowCellValue(fEvt.gvwEvent.FocusedRowHandle, fEvt.gcolCourseId).ToString());

                    if (fEvt.gvwEvent.GetRowCellValue(fEvt.gvwEvent.FocusedRowHandle, fEvt.gcolIsRecur).ToString() != "")
                        IsRecur = true;

                    if (IsRecur)
                    {
                        frmDeleteEvents frmDelEvt = new frmDeleteEvents(intID, intCalID);
                        if (frmDelEvt.ShowDialog() == DialogResult.OK)
                        {
                            fEvt.LoadEvent();
                            fEvt.grdEvent.Focus();
                            fEvt.gvwEvent.FocusedRowHandle = Row - 1;
                            if (fEvt.gvwEvent.RowCount > 0)
                            {
                                if (fEvt.gvwEvent.FocusedRowHandle < 0)
                                    fEvt.gvwEvent.FocusedRowHandle = 0;
                            }
                        }
                        frmDelEvt.Close();
                        frmDelEvt.Dispose();
                        frmDelEvt = null;
                    }
                    else
                    {
                        if (Message.MsgDelete())
                        {
                            string strMess = "";
                            Events evt = new Events();
                            evt.EventID = intID;
                            strMess = evt.CheckClassEvent();
                            if (strMess == "") strMess = evt.CheckProgramEvent();

                            if (strMess != "")
                            {
                                Message.MsgWarning("This Event is linked with" + strMess + ".\n\nEvent cannot be deleted.");
                                return;
                            }

                            //evt.DeleteData(true);
                            if (evt.EventType=="Extra Class")
                                evt.DeleteSingleCalendarEvent();
                            else
                                evt.DeleteTestEvent("Course", CourseId);

                            fEvt.LoadEvent();
                            fEvt.grdEvent.Focus();
                            fEvt.gvwEvent.FocusedRowHandle = Row - 1;
                            if (fEvt.gvwEvent.RowCount > 0)
                                if (fEvt.gvwEvent.FocusedRowHandle < 0)
                                    fEvt.gvwEvent.FocusedRowHandle = 0;
                        }
                    }
                }
            }
            else if (strMenuOption == "Calendar...")
            {
                if (fCalendar.schedulerControl1.SelectedAppointments.Count > 0)
                {
                    Appointment apt = fCalendar.schedulerControl1.SelectedAppointments[0];
                    bool IsRecur = false;

                    controller = new AppointmentFormController(fCalendar.schedulerControl1, apt);

                    int intCalID = Convert.ToInt32(controller.LabelId.ToString());
                    int intEventID = Common.GetID("select EventID from CalendarEvent where CalendarEventID=" + intCalID.ToString());
                    string strRecurrenceText =
                        Common.GetString("select RecurrenceText from Event where EventID=" + intEventID.ToString());

                    if (strRecurrenceText != "")
                        IsRecur = true;

                    if (IsRecur)
                    {
                        frmDeleteEvents frmDelEvt = new frmDeleteEvents(intEventID, intCalID);
                        if (frmDelEvt.ShowDialog() == DialogResult.OK)
                        {
                            fCalendar.LoadCalendar();
                        }
                        frmDelEvt.Close();
                        frmDelEvt.Dispose();
                        frmDelEvt = null;
                    }
                    else
                    {
                        if (Message.MsgDelete())
                        {
                            string strMess = "";
                            Events evt = new Events();
                            evt.EventID = intEventID;
                            strMess = evt.CheckClassEvent();
                            if (strMess == "") strMess = evt.CheckProgramEvent();

                            if (strMess != "")
                            {
                                Message.MsgWarning("This Event is linked with" + strMess + ".\n\nEvent cannot be deleted.");
                                return;
                            }

                            evt.DeleteData(true);
                            fCalendar.LoadCalendar();
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void btnDelete_Click(object sender, System.EventArgs e)
        {
            if(BusinessLayer.Message.MsgDelete())
            {
                Scheduler.BusinessLayer.Department objDept=new Scheduler.BusinessLayer.Department();
                objDept.DeptID = _deptid;
                objDept.ContactID = intContactID;
                if(!objDept.DeleteData())
                {
                    BusinessLayer.Message.MsgWarning("Department cannot be deleted");
                    return;
                }
                else
                {
                    deleted=true;
                    btnDelete.Enabled=false;
                    this.Text = "Adding Department...";
                    _mode="Add";
                    _deptid=0;

                    foreach(Control c in tbpContact.Controls)
                    {
                        if(c.GetType().ToString() == "System.Windows.Forms.TextBox")
                        {
                            if(c.Tag==null) c.Text="";
                            else if(c.Tag.ToString()=="N") c.Text="0";
                        }
                        if(c.GetType().ToString() == "System.Windows.Forms.ComboBox")
                        {
                            c.Text="";
                        }
                        if(c.GetType().ToString() == "System.Windows.Forms.DateTimePicker")
                        {
                            DateTimePicker dp=c as DateTimePicker;
                            dp.Value = DateTime.Now;
                        }
                    }
                    foreach(Control c in tbpDeptInfo.Controls)
                    {
                        if(c.GetType().ToString() == "System.Windows.Forms.TextBox")
                        {
                            if(c.Tag==null) c.Text="";
                            else if(c.Tag.ToString()=="N") c.Text="0";
                        }
                        if(c.GetType().ToString() == "System.Windows.Forms.ComboBox")
                        {
                            c.Text="";
                        }
                        if(c.GetType().ToString() == "System.Windows.Forms.DateTimePicker")
                        {
                            DateTimePicker dp=c as DateTimePicker;
                            dp.Value = DateTime.Now;
                        }
                    }
                    this.DialogResult = DialogResult.OK;
                    Close();
                }
            }
        }