コード例 #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            tblLogFault fault = new tblLogFault();

            if (dgvViewLog.CurrentRow.Index != -1)
            {
                model.LogID = Convert.ToInt32(dgvViewLog.CurrentRow.Cells["LogID"].Value);
                using (MacrocommEntities db = new MacrocommEntities())
                {
                    model = db.tblViewLogs.Where(x => x.LogID == model.LogID).FirstOrDefault();

                    if (MessageBox.Show("Are you sure to delete this record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        var entry = db.Entry(model);
                        if (entry.State == EntityState.Detached)
                        {
                            db.tblViewLogs.Attach(model);
                        }
                        db.tblViewLogs.Remove(model);
                        db.SaveChanges();
                        MessageBox.Show("Deleted Successfully");
                    }
                }
            }
        }
コード例 #2
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                MacrocommEntities context  = new MacrocommEntities();
                tblLogOther       objOther = new tblLogOther();

                objOther.Fault_Type   = cmbFaultType.Text;
                objOther.ConsumerType = cmbCustomerType.Text;
                objOther.Location     = txtLocation.Text;
                objOther.Comment      = txtComment.Text;

                context.tblLogOthers.Add(objOther);
                context.SaveChanges();
                MessageBox.Show("Request Logged successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Clear();
                cmbFaultType.Focus();
            }
            catch
            {
                MessageBox.Show("Request not logged, Please check all fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Clear();
                cmbFaultType.Focus();
            }
        }
コード例 #3
0
 private void frmViewLog_Load(object sender, EventArgs e)
 {
     using (MacrocommEntities db = new MacrocommEntities())
     {
         tblViewLogBindingSource.DataSource = db.tblViewLogs.ToList();
     }
 }
コード例 #4
0
 private void frmRegistration_Load(object sender, EventArgs e)
 {
     using (MacrocommEntities db = new MacrocommEntities())
     {
         tblRegistrationBindingSource.DataSource = db.tblRegistrations.ToList();
     }
 }
コード例 #5
0
        private void frmDashboard_Load(object sender, EventArgs e)
        {
            using (MacrocommEntities db = new MacrocommEntities())
            {
                tblRegistrationBindingSource.DataSource = db.tblRegistrations.ToList();
            }

            // Circular progress bar for fixed
            for (int x = 1; x <= 80; x++)
            {
                Thread.Sleep(5);
                cbFixed.Value = x;
                cbFixed.Update();
            }
            // Circular progress bar for Not fixed
            for (int x = 1; x <= 90; x++)
            {
                Thread.Sleep(5);
                cbNotFixed.Value = x;
                cbNotFixed.Update();
            }

            // Circular progress bar for Total
            for (int x = 1; x <= 60; x++)
            {
                Thread.Sleep(5);
                cbTotal.Value = x;
                cbTotal.Update();
            }
        }
コード例 #6
0
 void populateDataGridview()
 {
     dataGridView1.AutoGenerateColumns = false;
     using (MacrocommEntities db = new MacrocommEntities())
     {
         dataGridView1.DataSource = db.tblRegistrations.ToList <tblRegistration>();
     }
 }
コード例 #7
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            MacrocommEntities context = new MacrocommEntities();
            tblLogFault       objLog  = new tblLogFault();

            if (cmbFaultType.Text == "" || cmbCustomerType.Text == "" || txtComment.Text == "")
            {
                MessageBox.Show("Please enter all requered field.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                try
                {
                    // Adding logs to the FaultLogs table.
                    objLog.Log_Type      = cmbFaultType.Text;
                    objLog.Consumer_Type = cmbCustomerType.Text;
                    objLog.Comment       = txtComment.Text;
                    context.tblLogFaults.Add(objLog);
                    context.SaveChanges();
                    MessageBox.Show("Log request Successfully logged.", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Clear();
                }
                catch
                {
                    MessageBox.Show("Something went wrong please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Clear();
                }
            }

            using (MacrocommEntities db = new MacrocommEntities())
            {
                tblViewLog view = new tblViewLog();
                var        logg = (from p in db.tblLogFaults
                                   join r in db.tblViewLogs
                                   on p.Ref_No equals r.LogID
                                   where p.Log_Type == "Water,Electricity,Refuse,Sawege"
                                   select new
                {
                    ID = p.Ref_No,
                    cmbFaultType = p.Log_Type,
                    cmbCustomerType = p.Consumer_Type,
                    txtComment = p.Comment,
                    lID = r.LogID,
                    fault = r.Fault_Type,
                    comsumer = r.Consumer_Status,
                    comments = r.Comment
                }).ToList();
                context.tblViewLogs.Add(view);
                context.SaveChanges();
            }
        }
コード例 #8
0
 private void ViewProfile_Load(object sender, EventArgs e)
 {
     if (roleVUp == "Administrator" || roleVUp == "Management")
     {
         btnAddUser.Visible = true;
     }
     else
     {
         btnAddUser.Visible = false;
     }
     using (MacrocommEntities db = new MacrocommEntities())
     {
         tblRegistrationBindingSource.DataSource = db.tblRegistrations.ToList();
     }
 }
コード例 #9
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string x      = txtSearch.Text.Trim();
            int    result = System.Int32.Parse(x);

            model.Ref_No = result;
            using (MacrocommEntities db = new MacrocommEntities())
            {
                //dgvViewLog.Visible = true;
                //dgvViewLog.Visible = false;

                dgvViewLog.DataSource = ef.tblViewLogs.SqlQuery("SELECT * FROM tblViewLog WHERE Ref_No=" + txtSearch.Text).ToList <tblViewLog>();
            }
            txtSearch.Text = "";
        }
コード例 #10
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure to delete this record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (MacrocommEntities db = new MacrocommEntities())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.tblRegistrations.Attach(model);
             }
             db.tblRegistrations.Remove(model);
             db.SaveChanges();
             MessageBox.Show("Deleted Successfully");
             this.Close();
         }
     }
 }
コード例 #11
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.CurrentRow.Index != -1)
            {
                model.UserID = Convert.ToInt32(dataGridView1.CurrentRow.Cells["UserID"].Value);
                using (MacrocommEntities db = new MacrocommEntities())
                {
                    model = db.tblRegistrations.Where(x => x.UserID == model.UserID).FirstOrDefault();

                    imageVUp   = byteArrayToImage(model.images);
                    roleVUp    = model.UserRole;
                    nameVUp    = model.FirstName;
                    emailVUp   = model.Email;
                    mobileVUp  = model.Mobile;
                    surnameVUp = model.Surname;
                }
            }

            frmUserProfile ViewUserProfile = new frmUserProfile(imageVUp, roleVUp, nameVUp, emailVUp, mobileVUp, surnameVUp, model, oldRoleVUP);

            ViewUserProfile.Show();
        }
コード例 #12
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //txtFirstName.Visible = false;
            //txtEmail.Visible = false;
            //txtMobile.Visible = false;
            //txtSurname.Visible = false;
            //tblroles.Visible = false;

            //btnUpload.Visible = false;
            //btnSave.Visible = false;
            //btnEditProfile.Visible = true;


            //lblFirstName.Visible = true;
            //lblEmail.Visible = true;
            //lblMobile.Visible = true;
            //lblrole.Visible = true;
            //lblSurname.Visible = true;


            if (txtFirstName.Text == "" || txtSurname.Text == "" || txtMobile.Text == "" || txtEmail.Text == "" || imgProfile.Image == null)
            {
                MessageBox.Show("Please enter all fields");

                txtFirstName.Visible = true;
                txtSurname.Visible   = true;
                txtEmail.Visible     = true;
                txtMobile.Visible    = true;
                tblroles.Visible     = true;
                cmbUserRole.Visible  = true;

                btnUpload.Visible      = true;
                btnSave.Visible        = true;
                btnEditProfile.Visible = false;
                btnCancel.Visible      = false;
                btnDelete.Visible      = false;
                btnCancel2.Visible     = true;

                lblFirstName.Visible = false;
                lblSurname.Visible   = false;
                lblrole.Visible      = false;
                lblEmail.Visible     = false;
                lblMobile.Visible    = false;
            }
            else
            {
                try
                {
                    //MacrocommEntities context = new MacrocommEntities();


                    model.FirstName = txtFirstName.Text;
                    model.Surname   = txtSurname.Text;
                    model.Email     = txtEmail.Text;
                    model.UserRole  = cmbUserRole.Text;
                    model.Mobile    = txtMobile.Text;
                    //model.images = ConvertFiltoByte(this.imgProfile.ImageLocation);

                    using (MacrocommEntities context = new MacrocommEntities())
                    {
                        context.Entry(model).State = EntityState.Modified;
                        context.SaveChanges();
                    }

                    MessageBox.Show("Record Modified", "Confirmation");
                    txtFirstName.Visible = false;
                    txtEmail.Visible     = false;
                    txtMobile.Visible    = false;
                    txtSurname.Visible   = false;
                    tblroles.Visible     = false;
                    cmbUserRole.Visible  = false;

                    btnUpload.Visible      = false;
                    btnSave.Visible        = false;
                    btnEditProfile.Visible = true;
                    btnCancel2.Visible     = true;
                    btnDelete.Visible      = false;


                    lblFirstName.Visible = true;
                    lblEmail.Visible     = true;
                    lblMobile.Visible    = true;
                    lblrole.Visible      = true;
                    lblSurname.Visible   = true;
                }
                catch
                {
                    txtFirstName.Visible = true;
                    txtSurname.Visible   = true;
                    txtEmail.Visible     = true;
                    txtMobile.Visible    = true;
                    tblroles.Visible     = true;

                    btnUpload.Visible      = true;
                    btnSave.Visible        = true;
                    btnEditProfile.Visible = false;
                    btnCancel.Visible      = false;
                    btnDelete.Visible      = false;
                    btnCancel2.Visible     = true;

                    lblFirstName.Visible = false;
                    lblSurname.Visible   = false;
                    lblrole.Visible      = false;
                    lblEmail.Visible     = false;
                    lblMobile.Visible    = false;
                    MessageBox.Show("User not Updated", "Confirmation");
                }
            }
        }