public bool Insert(BoxDetail model) { try { if (model != null) { var update = context.BoxDetail.Where(x => x.BoxDetailID == model.BoxDetailID).FirstOrDefault(); if (update != null) { update.MCameraTypeID = model.MCameraTypeID; update.MOptionID = model.MOptionID; update.OptionValue = model.OptionValue; update.UpdBy = model.UpdBy; update.UpdDateTime = DateTime.Now; } else { model.InsDateTime = DateTime.Now; context.BoxDetail.Add(model); } context.SaveChanges(); } } catch (Exception e) { var joke = e.Message.ToString(); return(false); } return(true); }
public bool Insert(Entity.KTrackERPDB.Master_H model) { bool pass = false; try { if (model != null) { var update = context.Master_H.Where(x => x.prmtyp == model.prmtyp).FirstOrDefault(); if (update != null) { update.thdesc = model.thdesc; update.endesc = model.endesc; update.recsts = model.recsts; update.remark = model.remark; update.upddte = DateTime.Now; update.updby = model.updby; } else { model.instdte = DateTime.Now; context.Master_H.Add(model); } context.SaveChanges(); pass = true; } } catch (Exception e) { var joke = e.Message.ToString(); return(pass); } return(pass); }
public bool Insert(Entity.KTrackERPDB.Master_D model) { try { var update = context.Master_D.Where(x => x.prmid == model.prmid).FirstOrDefault(); if (update != null) { update.prmtyp = model.prmtyp; update.thdesc = model.thdesc; update.endesc = model.endesc; update.prmflag = model.prmflag; update.remark = model.remark; update.recsts = model.recsts; update.updby = model.updby; update.upddte = DateTime.Now; } else { model.instdte = DateTime.Now; context.Master_D.Add(model); } context.SaveChanges(); return(true); } catch (Exception ex) { var joke = ex.Message; return(false); } }
public bool Insert(Box model) { try { if (model != null) { var update = context.Box.Where(x => x.BoxID == model.BoxID).FirstOrDefault(); if (update != null) { update.AmountCameraDVR = model.AmountCameraDVR; update.APN = model.APN; update.BatteryID = model.BatteryID; update.CarID = model.CarID; update.DeviceID = model.DeviceID; update.ElectricVoltID = model.ElectricVoltID; update.FirmWareID = model.FirmWareID; update.IP = model.IP; update.LimitSpeedID = model.LimitSpeedID; update.Password = model.Password; update.Port = model.Port; update.SerialDVRNumber = model.SerialDVRNumber; update.SerialNumber = model.SerialNumber; update.SimTypeID = model.SimTypeID; update.SoundAlertID = model.SoundAlertID; update.TimeSendDataID = model.TimeSendDataID; update.UpdBy = model.UpdBy; update.UpdDateTime = DateTime.Now; update.Username = model.Username; update.VID = model.VID; update.warrantydateEnd = model.warrantydateEnd; update.warrantydateStart = model.warrantydateStart; } else { model.InsDateTime = DateTime.Now; context.Box.Add(model); } context.SaveChanges(); } } catch (Exception e) { var joke = e.Message.ToString(); return(false); } return(true); }
public bool Insert(Car model) { try { if (model != null) { var update = context.Car.Where(x => x.CarID == model.CarID).FirstOrDefault(); if (update != null) { update.JobRequestNoID = model.JobRequestNoID; update.BrandID = model.BrandID; update.CarTypeID = model.CarTypeID; update.Chassis = model.Chassis; update.LicenceDriveTypeID = model.LicenceDriveTypeID; update.LicensePlate = model.LicensePlate; update.Shaft = model.Shaft; update.Tire = model.Tire; update.Wheel = model.Wheel; update.UpdBy = model.UpdBy; update.UpdDateTime = DateTime.Now; } else { model.InsDateTime = DateTime.Now; context.Car.Add(model); } context.SaveChanges(); } } catch (Exception e) { var joke = e.Message.ToString(); return(false); } return(true); }
public bool Insert(M_Employee model) { try { if (model != null) { var update = context.M_Employee.Where(x => x.EmployeeID == model.EmployeeID).FirstOrDefault(); if (update != null) { update.Active = model.Active; update.DivisionID = model.DivisionID; update.Email = model.Email; update.FirstNameEN = model.FirstNameEN; update.FirstNameTH = model.FirstNameTH; update.LastNameEN = model.LastNameEN; update.LastNameTH = model.LastNameTH; update.Mobile = model.Mobile; update.PositionID = model.PositionID; update.UpdBy = model.UpdBy; update.UpdDateTime = DateTime.Now; } else { model.InsDateTime = DateTime.Now; context.M_Employee.Add(model); } context.SaveChanges(); } } catch (Exception e) { var joke = e.Message.ToString(); return(false); } return(true); }
public bool Insert(JobRequest model) { using (var dbTransaction = context.Database.BeginTransaction()) { try { if (model != null) { var update = context.JobRequest.Where(x => x.JobRequestNoID == model.JobRequestNoID).FirstOrDefault(); if (update != null) { update.AccountFlag = model.AccountFlag; update.AppointmentDateTime = model.AppointmentDateTime; update.AppointmentDetail = model.AppointmentDetail; update.CompanyName = model.CompanyName; update.ContactFax = model.ContactFax; update.ContactMobile = model.ContactMobile; update.ContactName = model.ContactName; update.ContactTel = model.ContactTel; update.CostFlag = model.CostFlag; update.CostOtherDetail = model.CostOtherDetail; update.CostOtherFlag = model.CostOtherFlag; update.CustomerSupportFlag = model.CustomerSupportFlag; update.EndContactDate = model.EndContactDate; update.HardWareFlag = model.HardWareFlag; update.JobRef = model.JobRef; update.JobRequestNo = model.JobRequestNo; update.JobRequestType = model.JobRequestType; update.JobStatus = model.JobStatus; update.Location = model.Location; update.OtherDetail = model.OtherDetail; update.ProcessDateTime = model.ProcessDateTime; update.Remark = model.Remark; update.RentTypeID = model.RentTypeID; update.SaleCoordinatorID = model.SaleCoordinatorID; update.Informer = model.Informer; update.SaleID = model.SaleID; update.SoftWareFlag = model.SoftWareFlag; update.StartContactDate = model.StartContactDate; update.UpdBy = model.UpdBy; update.UpdDateTime = DateTime.Now; if (model.Car != null) { foreach (Car item in model.Car) { var updatecar = context.Car.Where(x => x.CarID == item.CarID).FirstOrDefault(); if (updatecar != null) { updatecar.CarID = item.CarID; updatecar.CarTypeID = item.CarTypeID; updatecar.Chassis = item.Chassis; updatecar.JobRequestNoID = item.JobRequestNoID; updatecar.LicenceDriveTypeID = item.LicenceDriveTypeID; updatecar.LicensePlate = item.LicensePlate; updatecar.Remark = item.Remark; updatecar.Shaft = item.Shaft; updatecar.Tire = item.Tire; updatecar.UpdBy = model.UpdBy; updatecar.UpdDateTime = DateTime.Now; updatecar.Wheel = item.Wheel; } } } if (model.Box != null) { foreach (Box item in model.Box) { var updatebox = context.Box.Where(x => x.BoxID == item.BoxID).FirstOrDefault(); if (updatebox != null) { updatebox.AmountCameraDVR = item.AmountCameraDVR; updatebox.APN = item.APN; updatebox.BatteryID = item.BatteryID; updatebox.CarID = item.CarID; updatebox.DeviceID = item.DeviceID; updatebox.ElectricVoltID = item.ElectricVoltID; updatebox.FirmWareID = item.FirmWareID; updatebox.IP = item.IP; updatebox.LimitSpeedID = item.LimitSpeedID; updatebox.Password = item.Password; updatebox.Port = item.Port; updatebox.SerialDVRNumber = item.SerialDVRNumber; updatebox.SerialNumber = item.SerialNumber; updatebox.SimTypeID = item.SimTypeID; updatebox.SoundAlertID = item.SoundAlertID; updatebox.TimeSendDataID = item.TimeSendDataID; updatebox.UpdBy = model.UpdBy; updatebox.UpdDateTime = DateTime.Now; updatebox.Username = item.Username; updatebox.VID = item.VID; updatebox.warrantydateEnd = item.warrantydateEnd; updatebox.warrantydateStart = item.warrantydateStart; } } } if (model.BoxDetail != null) { foreach (BoxDetail item in model.BoxDetail) { var updateboxd = context.BoxDetail.Where(x => x.BoxDetailID == item.BoxDetailID).FirstOrDefault(); if (updateboxd != null) { if (item.Selected == false || string.IsNullOrEmpty(item.OptionValue)) { var updateoperation = context.OperationTest.Where(x => x.BoxDetailID == item.BoxDetailID).FirstOrDefault(); if (updateoperation != null) { context.OperationTest.Remove(updateoperation); } context.BoxDetail.Remove(updateboxd); context.SaveChanges(); } //else //{ // var oper = model.OperationTest.Where(x => x.BoxDetailID == item.BoxDetailID).FirstOrDefault(); // if (oper != null) // { // var operup = context.OperationTest.Where(x => x.OperationID == oper.OperationID).FirstOrDefault(); // if (operup != null) // { // operup.UpdDateTime = DateTime.Now; // } // else // { // oper.InsDateTime = DateTime.Now; // context.OperationTest.Add(oper); // context.SaveChanges(); // } // } //} } else { if (item.BoxDetailID == 0) { item.UpdBy = model.UpdBy; item.UpdDateTime = DateTime.Now; context.BoxDetail.Add(item); context.SaveChanges(); } } } } if (model.OperationTest != null) { foreach (OperationTest itemoper in model.OperationTest) { var operup = context.OperationTest.Where(x => x.OperationID == itemoper.OperationID).FirstOrDefault(); if (operup != null) { operup.Tested = itemoper.Tested; operup.UpdDateTime = DateTime.Now; } else { itemoper.InsDateTime = DateTime.Now; context.OperationTest.Add(itemoper); context.SaveChanges(); } } } if (model.TechnicCheckList != null) { foreach (TechnicCheckList technicCheck in model.TechnicCheckList) { var dataCheck = context.TechnicCheckList.Where(x => x.CheckListID == technicCheck.CheckListID).FirstOrDefault(); if (dataCheck != null) { dataCheck.Remark = technicCheck.Remark; dataCheck.Checked = technicCheck.Checked; dataCheck.UpdDateTime = DateTime.Now; } else { technicCheck.InsDateTime = DateTime.Now; context.TechnicCheckList.Add(technicCheck); context.SaveChanges(); } } } if (model.TechnicDVR != null) { foreach (TechnicDVR technicDVR in model.TechnicDVR) { var dataDVR = context.TechnicDVR.Where(x => x.TechDVRID == technicDVR.TechDVRID).FirstOrDefault(); if (dataDVR != null) { dataDVR.UpdDateTime = DateTime.Now; dataDVR.MDVRDirectionID = technicDVR.MDVRDirectionID; dataDVR.Remark = technicDVR.Remark; } else { technicDVR.InsDateTime = DateTime.Now; context.TechnicDVR.Add(technicDVR); context.SaveChanges(); } } } if (model.TechnicELSys != null) { foreach (TechnicELSys technicEL in model.TechnicELSys) { var dataEL = context.TechnicELSys.Where(x => x.ELSysID == technicEL.ELSysID).FirstOrDefault(); if (dataEL != null) { dataEL.UpdDateTime = DateTime.Now; dataEL.DCPowerAfterStart = technicEL.DCPowerAfterStart; dataEL.DCPowerBeforStart = technicEL.DCPowerBeforStart; dataEL.DCPowerWhileStart = technicEL.DCPowerWhileStart; dataEL.GroudAfterStart = technicEL.GroudAfterStart; dataEL.GroudBeforStart = technicEL.GroudBeforStart; dataEL.GroudWhileStart = technicEL.GroudWhileStart; dataEL.MELCut = technicEL.MELCut; dataEL.OnEngineOnAfterStart = technicEL.OnEngineOnAfterStart; dataEL.OnEngineOnBeforStart = technicEL.OnEngineOnBeforStart; } else { technicEL.InsDateTime = DateTime.Now; context.TechnicELSys.Add(technicEL); context.SaveChanges(); } } } if (model.TechnicELSysEquip != null) { foreach (TechnicELSysEquip eLSysEquip in model.TechnicELSysEquip) { var dataEquip = context.TechnicELSysEquip.Where(x => x.ELSysEquipID == eLSysEquip.ELSysEquipID).FirstOrDefault(); if (dataEquip != null) { dataEquip.UpdDateTime = DateTime.Now; dataEquip.IsNormal = eLSysEquip.IsNormal; dataEquip.Remark = eLSysEquip.Remark; } else { eLSysEquip.InsDateTime = DateTime.Now; context.TechnicELSysEquip.Add(eLSysEquip); context.SaveChanges(); } } } if (model.TechnicSensorTemp != null) { foreach (TechnicSensorTemp technicSensor in model.TechnicSensorTemp) { var dataTemp = context.TechnicSensorTemp.Where(x => x.SensorTempID == technicSensor.SensorTempID).FirstOrDefault(); if (dataTemp != null) { dataTemp.UpdDateTime = DateTime.Now; dataTemp.Sensor1 = technicSensor.Sensor1; dataTemp.Sensor2 = technicSensor.Sensor2; dataTemp.Sensor3 = technicSensor.Sensor3; dataTemp.Sensor4 = technicSensor.Sensor4; } else { technicSensor.InsDateTime = DateTime.Now; context.TechnicSensorTemp.Add(technicSensor); context.SaveChanges(); } } } if (model.HardwareTest != null) { foreach (HardwareTest hardwareTest in model.HardwareTest) { var dataht = context.HardwareTest.Where(x => x.HardwareTestID == hardwareTest.HardwareTestID).FirstOrDefault(); if (dataht != null) { dataht.UpdDateTime = DateTime.Now; dataht.Tested = hardwareTest.Tested; } else { hardwareTest.InsDateTime = DateTime.Now; context.HardwareTest.Add(hardwareTest); context.SaveChanges(); } } } if (model.HardwareTestDVR != null) { foreach (HardwareTestDVR testDVR in model.HardwareTestDVR) { var datahdvr = context.HardwareTestDVR.Where(x => x.HardwareDVRID == testDVR.HardwareDVRID).FirstOrDefault(); if (datahdvr != null) { datahdvr.UpdDateTime = DateTime.Now; datahdvr.Tested = testDVR.Tested; } else { testDVR.InsDateTime = DateTime.Now; context.HardwareTestDVR.Add(testDVR); context.SaveChanges(); } } } if (model.HardwareTestEquip != null) { foreach (HardwareTestEquip equip in model.HardwareTestEquip) { var dataequip = context.HardwareTestEquip.Where(x => x.HardwareTestEquipID == equip.HardwareTestEquipID).FirstOrDefault(); if (dataequip != null) { dataequip.UpdDateTime = DateTime.Now; dataequip.Tested = equip.Tested; } else { equip.InsDateTime = DateTime.Now; context.HardwareTestEquip.Add(equip); context.SaveChanges(); } } } if (model.HardwareTestSensorTemp != null) { foreach (HardwareTestSensorTemp sensorTemp in model.HardwareTestSensorTemp) { var datasensor = context.HardwareTestSensorTemp.Where(x => x.HardwareTestSensorTempID == sensorTemp.HardwareTestSensorTempID).FirstOrDefault(); if (datasensor != null) { datasensor.UpdDateTime = DateTime.Now; datasensor.Sensor1 = sensorTemp.Sensor1; datasensor.Sensor2 = sensorTemp.Sensor2; datasensor.Sensor3 = sensorTemp.Sensor3; datasensor.Sensor4 = sensorTemp.Sensor4; } else { sensorTemp.InsDateTime = DateTime.Now; context.HardwareTestSensorTemp.Add(sensorTemp); context.SaveChanges(); } } } if (model.CarIDs != null) { foreach (string carid in model.CarIDs.Split(',').Where(x => x != "" || x != null)) { Car c = context.Car.Find(Convert.ToInt32(carid)); if (c != null) { context.Car.Remove(c); } } } if (model.BoxIDs != null) { foreach (string boxid in model.BoxIDs.Split(',').Where(x => x != "" || x != null)) { Box b = context.Box.Find(Convert.ToInt32(boxid)); if (b != null) { context.Box.Remove(b); var boxd = context.BoxDetail.Where(x => x.BoxID == b.BoxID).ToList(); if (boxd != null) { context.BoxDetail.RemoveRange(boxd); } } } } } else { model.InsDateTime = DateTime.Now; var jobtype = context.Master_D.Where(x => x.prmid == model.JobRequestType).Select(x => x.endesc).FirstOrDefault(); model.JobRequestNo = GenerateJobCodeDB(jobtype); context.JobRequest.Add(model); context.SaveChanges(); for (int i = 0; i < model.Car.Count; i++) { model.Car[i].JobRequestNoID = model.JobRequestNoID; model.Car[i].InsBy = model.InsBy; model.Car[i].InsDateTime = DateTime.Now; context.Car.Add(model.Car[i]); context.SaveChanges(); for (int k = i; k < model.Box.Count;) { model.Box[k].JobRequestNoID = model.JobRequestNoID; //model.Box[k].CarID = model.Car[i].CarID; model.Box[k].InsDateTime = DateTime.Now; model.Box[k].InsBy = model.InsBy; context.Box.Add(model.Box[k]); context.SaveChanges(); var boxdetails = model.BoxDetail.Where(x => (x.LicensePlate == model.Car[i].LicensePlate)).ToList(); for (int j = 0; j < boxdetails.Count; j++) { boxdetails[j].InsBy = model.InsBy; boxdetails[j].InsDateTime = DateTime.Now; boxdetails[j].BoxID = model.Box[k].BoxID; boxdetails[j].JobRequestNoID = model.JobRequestNoID; context.BoxDetail.Add(boxdetails[j]); context.SaveChanges(); } break; } } } context.SaveChanges(); dbTransaction.Commit(); } } catch (Exception e) { var joke = e.Message.ToString(); dbTransaction.Rollback(); return(false); } } return(true); }
public bool Insert(JobRequestClose model) { using (var dbTransaction = context.Database.BeginTransaction()) { try { if (model != null) { var update = context.JobRequestClose.Where(x => x.JobRequestCloseID == model.JobRequestCloseID).FirstOrDefault(); if (update != null) { update.AmountMounth = model.AmountMounth; update.CompanyName = model.CompanyName; update.ContactFax = model.ContactFax; update.ContactFax = model.ContactFax; update.ContactMobile = model.ContactMobile; update.ContactName = model.ContactName; update.ContactTel = model.ContactTel; update.DocDeliverAddress = model.DocDeliverAddress; update.ConditionBill = model.ConditionBill; update.ConditionPayBill = model.ConditionPayBill; update.PeriodPay = model.PeriodPay; update.Location = model.Location; update.Remark = model.Remark; update.serviceChargeNextDate = model.serviceChargeNextDate; update.serviceChargePMonthStartDate = model.serviceChargePMonthStartDate; update.serviceChargePYearStartDate = model.serviceChargePYearStartDate; update.serviceChargeRentStartDate = model.serviceChargeRentStartDate; update.TaxID = model.TaxID; update.UpdBy = model.UpdBy; update.UpdDateTime = DateTime.Now; foreach (InstallMent item in model.InstallMent) { var updateinstallment = context.InstallMent.Where(x => x.InstallMentID == item.InstallMentID).FirstOrDefault(); if (updateinstallment != null) { updateinstallment.PayDate = item.PayDate; updateinstallment.Price = item.Price; updateinstallment.UpdBy = item.UpdBy; updateinstallment.UpdDateTime = DateTime.Now; } } foreach (ServiceCharge item in model.ServiceCharge) { var updateservice = context.ServiceCharge.Where(x => x.ServiceID == item.ServiceID).FirstOrDefault(); if (updateservice != null) { updateservice.Amount = item.Amount; updateservice.OptionID = item.OptionID; updateservice.Price = item.Price; updateservice.ServiceChargeID = item.ServiceChargeID; updateservice.TotalPricee = item.TotalPricee; updateservice.UpdBy = item.UpdBy; updateservice.UpdDateTime = DateTime.Now; } } //foreach (string carid in model.CarIDs.Split(',').Where(x => x != "" || x != null)) //{ // Car c = context.Car.Find(Convert.ToInt32(carid)); // if (c != null) // { // context.Car.Remove(c); // } //} //foreach (string boxid in model.BoxIDs.Split(',').Where(x => x != "" || x != null)) //{ // Box c = context.Box.Find(Convert.ToInt32(boxid)); // if (c != null) // { // context.Box.Remove(c); // } //} } else { model.InsDateTime = DateTime.Now; //var jobtype = context.Master_D.Where(x => x.prmid == model.JobRequestType).Select(x => x.endesc).FirstOrDefault(); model.JobRequestCloseNo = GenerateJobCodeDB(); context.JobRequestClose.Add(model); context.SaveChanges(); for (int i = 0; i < model.ServiceCharge.Count; i++) { model.ServiceCharge[i].JobRequestCloseID = model.JobRequestCloseID; model.ServiceCharge[i].Seq = i + 1; model.ServiceCharge[i].InsDateTime = DateTime.Now; context.ServiceCharge.Add(model.ServiceCharge[i]); context.SaveChanges(); } for (int i = 0; i < model.InstallMent.Count; i++) { model.InstallMent[i].Seq = i + 1; model.InstallMent[i].InsDateTime = DateTime.Now; model.InstallMent[i].JobRequestCloseID = model.JobRequestCloseID; context.InstallMent.Add(model.InstallMent[i]); context.SaveChanges(); } } foreach (Car item in model.Car) { var updatecar = context.Car.Where(x => x.CarID == item.CarID).FirstOrDefault(); if (updatecar != null) { updatecar.ServiceReportBookNo = item.ServiceReportBookNo; updatecar.ServiceRportNo = item.ServiceRportNo; updatecar.NewServiceReportBookNo = item.NewServiceReportBookNo; updatecar.NewServiceRportNo = item.NewServiceRportNo; updatecar.UpdBy = item.UpdBy; updatecar.UpdDateTime = DateTime.Now; } } foreach (Box item in model.Box) { var updatebox = context.Box.Where(x => x.BoxID == item.BoxID).FirstOrDefault(); if (updatebox != null) { //updatebox.AmountCameraDVR = item.AmountCameraDVR; //updatebox.APN = item.APN; //updatebox.BatteryID = item.BatteryID; //updatebox.CarID = item.CarID; //updatebox.DeviceID = item.DeviceID; //updatebox.ElectricVoltID = item.ElectricVoltID; //updatebox.FirmWareID = item.FirmWareID; //updatebox.IP = item.IP; //updatebox.LimitSpeedID = item.LimitSpeedID; //updatebox.Password = item.Password; //updatebox.Port = item.Port; //updatebox.SerialDVRNumber = item.SerialDVRNumber; updatebox.SerialNumber = item.SerialNumber; //updatebox.SimTypeID = item.SimTypeID; //updatebox.SoundAlertID = item.SoundAlertID; //updatebox.TimeSendDataID = item.TimeSendDataID; updatebox.UpdBy = item.UpdBy; updatebox.UpdDateTime = DateTime.Now; //updatebox.Username = item.Username; updatebox.VID = item.VID; updatebox.InstallDate = item.InstallDate; updatebox.UnstallDate = item.UnstallDate; //updatebox.warrantydateEnd = item.warrantydateEnd; //updatebox.warrantydateStart = item.warrantydateStart; } } context.SaveChanges(); dbTransaction.Commit(); } } catch (Exception e) { var joke = e.Message.ToString(); dbTransaction.Rollback(); return(false); } } return(true); }