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 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) { }
            }
        }
Пример #3
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;
                        }
                    }
                }
            }
        }