Пример #1
0
        private async void LoadUpGui()
        {
            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("bricks"));

                tbcementreg.Text = temp1.FirstOrDefault().AmountIn.ToString();
                tbwaterreg.Text  = temp2.FirstOrDefault().AmountIn.ToString();
                tbbrickreg.Text  = temp3.FirstOrDefault().AmountIn.ToString();

                //notifications
                Notifications();

                //remaining
                lblQty1.Text   = temp1.FirstOrDefault().Quantity.ToString() + " Kg";
                lblWtr.Text    = temp2.FirstOrDefault().Quantity.ToString() + " ltr";
                lblBricks.Text = temp3.FirstOrDefault().Quantity.ToString() + " pieces";

                btnSave1.Visible = false;
                lbltu.Visible    = true;
                btnSave2.Visible = false;
                lbltu2.Visible   = true;
                btnSave3.Visible = false;
                lbltu3.Visible   = true;
            }
        }
        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) { }
                    }
                }
            }
        }
        private async void GridInitializer(DateTime leo)
        {
            //change color of INX to green
            //gData.Columns[0].DefaultCellStyle.ForeColor = Color.Blue;

            var bb = leo.Date.ToShortDateString();

            var workListAsync = await Task.Factory.StartNew(() =>
            {
                using (var context = new KimathiEntities())
                {
                    return(context.Works
                           .OrderBy(x => x.Id)
                           //.Where(t => t.TimeIn.Value.Date.ToShortDateString() == bb)
                           .ToList());
                }
            });

            gData.Rows.Clear();

            try
            {
                foreach (var item in workListAsync)
                {
                    if (item.TimeIn.Value.Date.ToShortDateString().Equals(bb))
                    {
                        var hrs = item.TimeOut.Value - item.TimeIn.Value;
                        var pay = hrs.TotalHours * int.Parse(tbRate.Text);
                        value = item.Payed == 0 ? Res._1pending : Res._1paid;



                        gData.Rows.Add(new string[]
                        {
                            null,
                            $"{empFound(item.IdNum_fk).IdNum}",
                            $"{empFound(item.IdNum_fk).Name}",
                            $"{item.TimeIn.Value.ToShortTimeString()}",
                            $"{item.TimeOut.Value.ToShortTimeString()}",
                            $"KES {String.Format("{0:0,0}", pay)}",
                            null,
                            null
                        });
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        private Employee empFound(long idnum)
        {
            using (var context = new KimathiEntities())
            {
                var userList = context.Employees.ToList();

                foreach (var ss in userList.Where(a => a.IdNum == (idnum)))
                {
                    if (ss.IdNum == idnum)
                    {
                        return(ss);
                    }
                }
                return(null);
            }
        }
Пример #5
0
        private void CheckInPrep()
        {
            lblDate.Text = DateTime.Now.ToString("dd MMM yyy");

            Work dowork = null;

            if (theemp != null)
            {
                long xx = theemp.IdNum;
                using (var context = new KimathiEntities())
                {
                    var wList = context.Works
                                .OrderBy(a => a.TimeIn)
                                .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)
                    {
                        dTimePickerIn.Value  = dowork.TimeIn.Value;
                        dTimePickerOut.Value = dowork.TimeOut.Value;
                    }
                    else
                    {
                        dTimePickerIn.Value  = DateTime.Now;
                        dTimePickerOut.Value = DateTime.Now;
                    }
                }
            }
        }
        private async Task <Work> GridDelImageAsync(int rowIndex)
        {
            List <Work> wkList = await Task.Factory.StartNew(() =>
            {
                using (var context = new KimathiEntities())
                {
                    return(context.Works.ToList());
                }
            });

            string details;

            details = $"{(string)this.gData.Rows[rowIndex].Cells[1].Value} {(string)this.gData.Rows[rowIndex].Cells[3].Value} {(string)this.gData.Rows[rowIndex].Cells[4].Value}";

            foreach (var fi in wkList)
            {
                string id = $"{fi.IdNum_fk} {fi.TimeIn.Value.ToShortTimeString()} {fi.TimeOut.Value.ToShortTimeString()}";
                if (id.Equals(details))
                {
                    return(fi);
                }
            }
            return(null);
        }
Пример #7
0
        private async void Notifications()
        {
            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("bricks"));

                tbcementreg.Text = temp1.FirstOrDefault().AmountIn.ToString();
                tbwaterreg.Text  = temp2.FirstOrDefault().AmountIn.ToString();
                tbbrickreg.Text  = temp3.FirstOrDefault().AmountIn.ToString();

                //cement
                if (temp1.FirstOrDefault().Quantity < 50)
                {
                    not1.Text      = "Low Cement"; //Low Cement
                    not1.ForeColor = Color.Crimson;
                }
                else
                {
                    not1.Text      = "Cement Available"; //Low Cement
                    not1.ForeColor = Color.Black;
                }
                if (temp1.FirstOrDefault().Quantity < 40)
                {
                    not1.Text      = "Very Low Cement"; //Low Cement
                    not1.ForeColor = Color.Crimson;
                }
                if (temp1.FirstOrDefault().Quantity < 5 | temp1.FirstOrDefault().Quantity == 0)
                {
                    not1.Text      = "No Usable Cement"; //Low Cement
                    not1.ForeColor = Color.Crimson;
                }

                //water
                if (temp2.FirstOrDefault().Quantity < 500)
                {
                    not2.Text      = "Water Low"; //Low Cement
                    not2.ForeColor = Color.Crimson;
                }
                else
                {
                    not2.Text      = "Water Available"; //Low Cement
                    not2.ForeColor = Color.Black;
                }
                if (temp2.FirstOrDefault().Quantity < 400)
                {
                    not2.Text      = "Very Low water level"; //Low Cement
                    not2.ForeColor = Color.Crimson;
                }
                if (temp2.FirstOrDefault().Quantity < 200 | temp2.FirstOrDefault().Quantity == 0)
                {
                    not2.Text      = "No Usable Water"; //Low Cement
                    not2.ForeColor = Color.Crimson;
                }

                //bricks
                if (temp3.FirstOrDefault().Quantity < 50)
                {
                    not3.Text      = "Few Bricks"; //Low Cement
                    not3.ForeColor = Color.Crimson;
                }
                else
                {
                    not3.Text      = "Bricks Available"; //Low Cement
                    not3.ForeColor = Color.Black;
                }
                if (temp3.FirstOrDefault().Quantity < 40)
                {
                    not3.Text      = "Minimal Bricks"; //Low Cement
                    not3.ForeColor = Color.Crimson;
                }
                if (temp3.FirstOrDefault().Quantity < 5 | temp3.FirstOrDefault().Quantity == 0)
                {
                    not1.Text      = "No Bricks"; //Low Cement
                    not1.ForeColor = Color.Crimson;
                }
            }
        }
Пример #8
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) { }
            }
        }
        public void MonthlyUISet()
        {
            using (var context = new KimathiEntities())
            {
                var GMonth = DateTime.Now.Month;
                var GYear  = DateTime.Now.Year;

                var firstDayOfMonth = new DateTime(GYear, GMonth, 1);
                var lastDayOfMonth  = firstDayOfMonth.AddMonths(1).AddDays(-1);



                #region var init



                var incomeListAsync =
                    context.Works.ToList();

                //Days for income
                incDay0 = incomeListAsync.Where(x => x.TimeIn == firstDayOfMonth | x.TimeIn.Value.Day == 1)
                          .Select(
                    item =>
                {
                    var hrs = item.TimeOut.Value - item.TimeIn.Value;
                    return(hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text));
                }
                    ).FirstOrDefault();


                incDay5 = incomeListAsync.Where(x => x.TimeIn.Value.Day > 1 & x.TimeIn.Value.Day < 6)
                          .Select(
                    item =>
                {
                    var hrs = item.TimeOut.Value - item.TimeIn.Value;
                    return(hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text));
                }
                    ).FirstOrDefault();
                incDay10 = incomeListAsync.Where(x => x.TimeIn.Value.Day > 5 & x.TimeIn.Value.Day < 11)
                           .Select(
                    item =>
                {
                    var hrs = item.TimeOut.Value - item.TimeIn.Value;
                    return(hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text));
                }
                    ).FirstOrDefault();
                incDay15 = incomeListAsync.Where(x => x.TimeIn.Value.Day > 10 & x.TimeIn.Value.Day < 16)
                           .Select(
                    item =>
                {
                    var hrs = item.TimeOut.Value - item.TimeIn.Value;
                    return(hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text));
                }
                    ).FirstOrDefault();
                incDay20 = incomeListAsync.Where(x => x.TimeIn.Value.Day > 15 & x.TimeIn.Value.Day < 26)
                           .Select(
                    item =>
                {
                    var hrs = item.TimeOut.Value - item.TimeIn.Value;
                    return(hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text));
                }
                    ).FirstOrDefault();
                incDay25 = incomeListAsync.Where(x => x.TimeIn.Value.Day > 25 & x.TimeIn.Value.Day < 31)
                           .Select(
                    item =>
                {
                    var hrs = item.TimeOut.Value - item.TimeIn.Value;
                    return(hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text));
                }
                    ).FirstOrDefault();
                incDayLast = incomeListAsync.Where(x => x.TimeIn.Value.Day == lastDayOfMonth.Day)
                             .Select(
                    item =>
                {
                    var hrs = item.TimeOut.Value - item.TimeIn.Value;
                    return(hrs.TotalHours * int.Parse(PayrollUI.Instance.tbRate.Text));
                }
                    ).FirstOrDefault();


                #endregion

                cIncome = new ChartValues <double> {
                    incDay0, incDay5, incDay10, incDay15, incDay20, incDay25, incDayLast
                };

                cartesianChart1.Series = new SeriesCollection
                {
                    new LineSeries
                    {
                        Title  = "Payment",
                        Values = cIncome
                    },
                };

                cartesianChart1.AxisX.Add(new Axis
                {
                    Title  = "Days",
                    Labels = new[] { "0", "5", "10", "15", "20", "25", "30" }
                });

                cartesianChart1.AxisY.Add(new Axis
                {
                    Title          = "Amount",
                    LabelFormatter = value => $"KES {String.Format("{0:0,0}", value)}"
                                     //value.ToString("C3", CultureInfo.CreateSpecificCulture("sw-KE"))
                });

                cartesianChart1.LegendLocation = LegendLocation.Right;
            }
        }
Пример #10
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) { }
        }
Пример #11
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;
                        }
                    }
                }
            }
        }