Beispiel #1
0
        private void button3_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                Excel.Application app     = Globals.ThisAddIn.Application;
                Excel.Workbook    wkbook  = app.ActiveWorkbook;
                Excel.Worksheet   wksheet = wkbook.ActiveSheet;

                string jobnumber = wksheet.Cells[1, "A"].Value;

                var wip = new adoEntities();

                Kickoff    ko  = wip.Kickoffs.Find(jobnumber);
                ActualsRep act = wip.ActualsReps.Find(jobnumber);

                //RecordDataView recorddataview = db.RecordDataView.SingleOrDefault(m => m.Record_number == id);

                JobMetric jo = wip.JobMetrics.FirstOrDefault(m => m.BaseID == jobnumber);
                // JobMetric jo = wip.JobMetrics.Find(jobnumber);



                //Quoted Hours
                wksheet.Cells[16, "B"].Value = ko.DesignEst;
                wksheet.Cells[17, "B"].Value = ko.PlanningEst;
                wksheet.Cells[18, "B"].Value = ko.WaterjetEst;
                wksheet.Cells[19, "B"].Value = ko.WeldEst;
                wksheet.Cells[20, "B"].Value = ko.NCEst;
                wksheet.Cells[21, "B"].Value = ko.ConventionalEst;
                wksheet.Cells[22, "B"].Value = ko.AssemblyEst;
                wksheet.Cells[23, "B"].Value = ko.InspectionEst;

                //Adjusted Hours

                wksheet.Cells[16, "E"].Value = ko.Design;
                wksheet.Cells[17, "E"].Value = ko.Planning;
                wksheet.Cells[18, "E"].Value = ko.Waterjet;
                wksheet.Cells[19, "E"].Value = ko.Weld;
                wksheet.Cells[20, "E"].Value = ko.NC;
                wksheet.Cells[21, "E"].Value = ko.Convetional;
                wksheet.Cells[22, "E"].Value = ko.Assy;
                wksheet.Cells[23, "E"].Value = ko.Inspection;

                //Actual Hours
                MessageBox.Show("Time for the Actuals");
                try
                {
                    wksheet.Cells[16, "H"].Value = act.Design;
                    wksheet.Cells[17, "H"].Value = act.Planning;
                    wksheet.Cells[18, "H"].Value = act.Waterjet;
                    wksheet.Cells[19, "H"].Value = act.Weld;
                    wksheet.Cells[20, "H"].Value = act.Nc;
                    wksheet.Cells[21, "H"].Value = act.Machining;
                    wksheet.Cells[22, "H"].Value = act.Assy;
                    wksheet.Cells[23, "H"].Value = act.Inspection;

                    wksheet.Cells[16, "I"].Value = act.DesignCost;
                    wksheet.Cells[17, "I"].Value = act.PlanningCost;
                    wksheet.Cells[18, "I"].Value = act.WaterJetCost;
                    wksheet.Cells[19, "I"].Value = act.WeldCost;
                    wksheet.Cells[20, "I"].Value = act.NcCost;
                    wksheet.Cells[21, "I"].Value = act.MachiningCost;
                    wksheet.Cells[22, "I"].Value = act.AssyCost;
                    wksheet.Cells[23, "I"].Value = act.InspectionCost;
                }

                catch (Exception ef)
                {
                    MessageBox.Show(ef.ToString());
                }


                //Margin

                wksheet.Cells[8, "I"].Value = jo.Margin;
                wksheet.Cells[9, "I"].Value = jo.Actual;
                wksheet.Cells[1, "F"].Value = jo.POValue;
                wksheet.Cells[2, "F"].Value = jo.ContractDate;
                wksheet.Cells[1, "I"].Value = "FUCKIFIKNOW";
                wksheet.Cells[2, "I"].Value = jo.ShipDate;
            }

            catch (Exception ef)
            {
                MessageBox.Show(ef.Message.ToString());
            }

            //Convert.ToInt32(wksheet.Cells[20, "BV"].Value);
        }
Beispiel #2
0
        private void btnKickoff_Click(object sender, RibbonControlEventArgs e)
        {
            Excel.Workbook    xlBook  = Globals.ThisAddIn.Application.ActiveWorkbook;
            Excel.Application xlApp   = new Excel.Application();
            Excel.Worksheet   xlSheet = xlBook.Sheets[1];
            Excel.Range       xlRange = xlSheet.UsedRange;

            adoEntities db = new adoEntities();


            try
            {
                for (int i = 2; i < 900; i++)
                {
                    try
                    {
                        if (xlRange.Cells[i, 1] != null && xlRange.Cells[i, 1].Value2 != null)
                        {
                            if (xlRange.Cells[i, 1].value.ToString() != "End")
                            {
                                try
                                {
                                    string jobnumber = xlRange.Cells[i, 1].Value.ToString();
                                    var    jobs      = from b in db.ActualsReps
                                                       where b.BaseID.Equals(jobnumber)
                                                       select b;
                                    if (jobs.Count() > 0)
                                    {
                                        db.ActualsReps.Remove(db.ActualsReps.Single(b => b.BaseID == jobnumber));
                                    }

                                    ActualsRep act = new ActualsRep();
                                    act.BaseID = xlRange.Cells[i, 1].Value.ToString();

                                    act.BaseID         = Convert.ToString(xlRange.Cells[i, 1].value());
                                    act.Design         = Convert.ToString(xlRange.Cells[i, 7].value());
                                    act.Planning       = Convert.ToString(xlRange.Cells[i, 8].value());
                                    act.Waterjet       = Convert.ToString(xlRange.Cells[i, 9].value());
                                    act.Weld           = Convert.ToString(xlRange.Cells[i, 10].value());
                                    act.Nc             = Convert.ToString(xlRange.Cells[i, 11].value());
                                    act.Machining      = Convert.ToString(xlRange.Cells[i, 12].value());
                                    act.Assy           = Convert.ToString(xlRange.Cells[i, 13].value());
                                    act.Inspection     = Convert.ToString(xlRange.Cells[i, 14].value());
                                    act.DesignCost     = Convert.ToDecimal(xlRange.Cells[i, 15].value());
                                    act.PlanningCost   = Convert.ToDecimal(xlRange.Cells[i, 16].value());
                                    act.WaterJetCost   = Convert.ToDecimal(xlRange.Cells[i, 17].value());
                                    act.WeldCost       = Convert.ToDecimal(xlRange.Cells[i, 18].value());
                                    act.NcCost         = Convert.ToDecimal(xlRange.Cells[i, 18].value());
                                    act.MachiningCost  = Convert.ToDecimal(xlRange.Cells[i, 20].value());
                                    act.AssyCost       = Convert.ToDecimal(xlRange.Cells[i, 21].value());
                                    act.InspectionCost = Convert.ToDecimal(xlRange.Cells[i, 22].value());
                                    act.LaborCost      = Convert.ToDecimal(xlRange.Cells[i, 23].value());
                                    act.BurdenCost     = Convert.ToDecimal(xlRange.Cells[i, 24].value());
                                    act.MaterialCost   = Convert.ToDecimal(xlRange.Cells[i, 25].value());
                                    act.ServiceCost    = 0;

                                    db.ActualsReps.Add(act);
                                }

                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.InnerException.ToString());
                                    MessageBox.Show("There is an issue with the data you are trying to import. Check for data formatting issues!");
                                    break;
                                }
                            }

                            else
                            {
                                int count = i - 1;
                                MessageBox.Show("Success! " + count.ToString() + " records imported successfully");
                                break;
                            }
                        }

                        else
                        {
                            break;
                        }

                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException fe)
                    {
                        foreach (var eve in fe.EntityValidationErrors)
                        {
                            Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                              eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                  ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }
                }
            }

            catch (Exception enhh)
            {
                MessageBox.Show(enhh.Message.ToString());
            }
        }