private async void gData_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewImageColumn &&
                e.RowIndex >= 0)
            {
                if (e.ColumnIndex == 7)
                {
                    if ((await GridDelImageAsync(e.RowIndex)) != null)
                    {
                        using (var context = new KimathiEntities())
                        {
                            try
                            {
                                context.Entry <Work>(await GridDelImageAsync(e.RowIndex)).State = EntityState.Deleted;
                                context.SaveChanges();

                                //short Custom Notification
                                alert.Show("Deleted", alert.AlertType.warnig);
                                gData.Rows[e.RowIndex].Visible = false;
                                //Load the grid again
                                GridInitializer(dTimePickerGrid.Value);
                            }
                            catch (Exception exp)
                            {
                                MessageBox.Show("Something went wrong" + exp.Message, "Unsuccessful");
                            }
                        }
                    }
                }
                if (e.ColumnIndex == 0)
                {
                    if (MetroMessageBox.Show(this, $"Hi do you want to pay {this.gData.Rows[e.RowIndex].Cells[2].Value.ToString()} {this.gData.Rows[e.RowIndex].Cells[5].Value.ToString()}", "Payment", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        //this employee wages have been payed
                        //get instance of employee and pay
                        Work xx = (await GridDelImageAsync(e.RowIndex));
                        xx.Payed = 1;

                        try
                        {
                            using (var context = new KimathiEntities())
                            {
                                context.Entry <Work>(xx).State = EntityState.Modified;
                                context.SaveChanges();
                                //short Custom Notification
                                alert.Show("Payment Successfull", alert.AlertType.info);
                                //Load the grid again
                                GridInitializer(dTimePickerGrid.Value);
                            }
                        }
                        catch (Exception) { }
                    }
                }
            }
        }
示例#2
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbFullName.Text))
            {
                //UI code

                alert.Show("Required info \n Enter Name !", alert.AlertType.warnig);
                return;
            }
            if (string.IsNullOrEmpty(tbDept.Text))
            {
                //UI code

                alert.Show("Required info \n Enter Department !", alert.AlertType.warnig);
                return;
            }
            if (string.IsNullOrEmpty(tbTypeOfemployee.Text))
            {
                //UI code

                alert.Show("Required info \n Enter Employee Type !", alert.AlertType.warnig);
                return;
            }
            if (string.IsNullOrEmpty(tbIdReg.Text))
            {
                //UI code

                alert.Show("Required info \n Enter Employee ID !", alert.AlertType.warnig);
                return;
            }

            Employee yy = empFound(long.Parse(tbIdReg.Text));

            theemp = yy;

            if (yy != null)
            {
                //UI code

                alert.Show("Error \n Employee ID Found!", alert.AlertType.warnig);
                return;
            }

            try
            {
                Employee my = new Employee();
                my.IdNum          = long.Parse(tbIdReg.Text);
                my.Name           = tbFullName.Text;
                my.TypeOfEmployee = tbTypeOfemployee.Text;
                my.Department     = tbDept.Text;

                using (var context = new KimathiEntities())
                {
                    try
                    {
                        context.Employees.Add(my);
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        throw;
                    }

                    alert.Show("Saved !", alert.AlertType.success);
                    CheckInPrep();
                }
            }
            catch (Exception) { }
        }
示例#3
0
        private async void btnSave3_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbbrickreg.Text))
            {
                //UI code

                alert.Show("Required info \n Brick Registered !", alert.AlertType.warnig);
                return;
            }
            if (string.IsNullOrEmpty(tbbrickused.Text))
            {
                //UI code

                alert.Show("Required info \n Brick Used !", alert.AlertType.warnig);
                return;
            }

            btnSave3.Visible = false;
            lbltu3.Visible   = true;

            using (var context = new KimathiEntities())
            {
                var stoklist = await Task.Factory.StartNew(() =>
                {
                    return(context.Stocks
                           .OrderBy(x => x.Id)
                           .ToList());
                });

                var temp1 = stoklist.Where(x => x.RawMaterial.Equals("cement"));
                var temp2 = stoklist.Where(x => x.RawMaterial.Equals("water"));
                var temp3 = stoklist.Where(x => x.RawMaterial.Equals("brick"));



                try
                {
                    //check if required quantity has changed
                    if (int.Parse(tbbrickreg.Text) == temp3.FirstOrDefault().AmountIn)
                    {
                        temp3.FirstOrDefault().AmountOut += int.Parse(tbbrickused.Text);
                        temp3.FirstOrDefault().Quantity   = temp3.FirstOrDefault().AmountIn - temp3.FirstOrDefault().AmountOut;

                        try
                        {
                            context.Entry <Stock>(temp3.FirstOrDefault()).State = EntityState.Modified;
                            context.SaveChanges();
                            alert.Show("Updated !", alert.AlertType.success);
                            LoadUpGui();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    else
                    {
                        //now update
                        temp3.FirstOrDefault().AmountIn  += int.Parse(tbbrickreg.Text);
                        temp3.FirstOrDefault().AmountOut += int.Parse(tbbrickused.Text);
                        temp3.FirstOrDefault().Quantity   = temp3.FirstOrDefault().AmountIn - temp3.FirstOrDefault().AmountOut;

                        try
                        {
                            context.Entry <Stock>(temp3.FirstOrDefault()).State = EntityState.Modified;
                            context.SaveChanges();
                            alert.Show("Updated !", alert.AlertType.success);
                            LoadUpGui();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                catch (Exception) { }
            }
        }
示例#4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Work dowork = null;

            if (theemp != null)
            {
                long xx = theemp.IdNum;
                using (var context = new KimathiEntities())
                {
                    var wList = context.Works
                                .OrderBy(a => a.TimeOut)
                                .Where(a => a.IdNum_fk == xx)
                                .ToList();

                    foreach (var ss in wList.Where(a => a.Employee == theemp))
                    {
                        if (ss.Id == theemp.IdNum)
                        {
                            //returns the latest work entry
                            dowork = ss;
                            break;
                        }
                    }

                    if (dowork != null)
                    {
                        dowork.TimeIn   = dTimePickerIn.Value;
                        dowork.TimeOut  = dTimePickerOut.Value;
                        dowork.IdNum_fk = theemp.IdNum;

                        context.Entry <Work>(dowork).State = EntityState.Modified;
                        try
                        {
                            context.SaveChanges();
                            alert.Show("Updated !", alert.AlertType.success);
                        }
                        catch (Exception) { }
                    }
                    else
                    {
                        Work d = new Work();

                        d.IdNum_fk = theemp.IdNum;
                        d.TimeIn   = dTimePickerIn.Value;
                        d.TimeOut  = dTimePickerOut.Value;
                        d.Payed    = 0;
                        //d.Employee = theemp;

                        try
                        {
                            context.Works.Add(d);
                            context.SaveChanges();
                            alert.Show("Saved !", alert.AlertType.success);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            throw;
                        }
                    }
                }
            }
        }