private void gridView1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) { var LoadAttachments = new Action <int>((poId) => { _fileMgr.DocumentFileLink = new FileLink[] { new FileLink(Attachment.LemHeaderId, poId, Company.CurrentId, FileLink.Database.TR, 0, true) }; }); DataRow row = gridView1.GetDataRow(e.FocusedRowHandle); if (row != null && row.GetValue(colId) != DBNull.Value) { LoadAttachments(row.GetValue <int>(colId)); btnEmail.Enabled = true; btnPrint.Enabled = true; btnSubmit.Enabled = GetEnumName(EnumSubmitStatus.Open) == row.GetValueString(colSubmitStatus); _fileMgr.Enabled = LemHeader.CheckEditable(row.GetCharEnumValue <EnumLogStatus>(colLogStatus)); _fileMgr.ReadOnly = !_fileMgr.Enabled; } else { LoadAttachments(-1); btnEmail.Enabled = false; btnPrint.Enabled = false; btnSubmit.Enabled = false; _fileMgr.Enabled = false; _fileMgr.ReadOnly = true; } }
private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e) { if (new GridColumn[] { colProjectCode, colProjectName }.Contains(e.Column)) { DataRow row = gridView1.GetDataRow(e.RowHandle); int projectId = row.GetValue <int>(e.Column); Project project = Project.GetProject(projectId); row.SetValue(colProjectCode, projectId); row.SetValue(colProjectName, projectId); row.SetValue(colCustomerCode, project?.CustomerCode); row.SetValue(colCustomerName, project?.CustomerName); row.SetValue(colSiteLocation, project?.SiteLocation); row.SetValue(colStartDate, StrEx.GetDateString(project?.StartDate)); row.SetValue(colEstCompletionDate, StrEx.GetDateString(project?.EstCompletionDate)); row.SetValue(colLemNum, project.GetNextLemNum()); } if (!gridView1.IsNewItemRow(e.RowHandle)) { if (new GridColumn[] { colProjectCode, colProjectName, colLogDate, colLogStatus, colDescription }.Contains(e.Column)) { DataRow row = gridView1.GetDataRow(e.RowHandle); row.SetValue(colSubmitStatus, GetEnumName(EnumSubmitStatus.Open)); LemHeader.SqlUpdate(row.GetValue <int>(colId), row.GetValue <DateTime>(colLogDate), row.GetValue <int>(colProjectCode), row.GetCharEnumValue <EnumLogStatus>(colLogStatus), row.GetValueString(colDescription)); } } }
public ucToolEmpSum() { InitializeComponent(); luProject.Properties.DataSource = Project.AccessibleList().Select(p => new { Project = p.Name, Code = p.Code, MatchId = p.MatchId, DisplayName = p.DisplayName }); luLemNumber.Properties.DataSource = LemHeader.GetAllLemNumber().Select(x => new { LemNum = x }); Func <string, string, int, GridColumn> CreateColumn = new Func <string, string, int, GridColumn>((field, caption, visibleIndex) => { GridColumn column = gvSummary.Columns.AddVisible(field, caption); column.VisibleIndex = visibleIndex; return(column); }); int visionIndex = 0; new List <string> { ColName.EmpNum, ColName.EmployeeName, ColName.WorkClass, ColName.Project }.ForEach( x => gvSummary.Columns[x].VisibleIndex = visionIndex++ ); foreach (var timecode in TimeCode.SubList(EnumValueType.Hours)) { tableLabour.Columns.Add(ColName.BillRateI(timecode), Type.GetType("System.Decimal")); var rateCol = CreateColumn(ColName.BillRateI(timecode), $"{timecode.Desc} Bill Rate", visionIndex++); rateCol.DisplayFormat.FormatType = FormatType.Numeric; rateCol.DisplayFormat.FormatString = "c2"; rateCol.OptionsColumn.AllowEdit = false; tableLabour.Columns.Add(ColName.EnterValueI(timecode), Type.GetType("System.Decimal")); var hourCol = CreateColumn(ColName.EnterValueI(timecode), $"{timecode.Desc} Hours", visionIndex++); hourCol.DisplayFormat.FormatType = FormatType.Numeric; hourCol.DisplayFormat.FormatString = "n2"; hourCol.OptionsColumn.AllowEdit = false; hourCol.Summary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] { new DevExpress.XtraGrid.GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum, hourCol.FieldName, "{0:n2}") }); } foreach (var timecode in TimeCode.SubList(TimeCode.EnumValueType.Dollars)) { tableLabour.Columns.Add(ColName.EnterValueI(timecode), Type.GetType("System.Decimal")); var amountCol = CreateColumn(ColName.EnterValueI(timecode), timecode.Desc, visionIndex++); amountCol.DisplayFormat.FormatType = FormatType.Numeric; amountCol.DisplayFormat.FormatString = "c2"; amountCol.OptionsColumn.AllowEdit = false; amountCol.Summary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] { new DevExpress.XtraGrid.GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum, amountCol.FieldName, "{0:c2}") }); } gvSummary.Columns[ColName.TotalHours].VisibleIndex = visionIndex++; gvSummary.Columns[ColName.BillAmount].VisibleIndex = visionIndex++; gvSummary.BestFitColumns(true); }
private void gvAP_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (e.Column.FieldName == MColName.Select) { DataRow row = gvAP.GetDataRow(e.RowHandle); LemAP.SqlUpdateLemAP((int)row[MColName.Id], (bool)row[MColName.Select] ? (int?)_headerRecord.Id : null); LemHeader.SqlUpdateSubmitStatus(_headerRecord.Id, EnumSubmitStatus.Open); } }
private void btnSearch_Click(object sender, EventArgs e) { int? project = (int?)luProject.EditValue; DateTime?from = (DateTime?)deFromDate.EditValue; DateTime?to = (DateTime?)deToDate.EditValue; string lumNum = (string)luLemNumber.EditValue; var logList = LemHeader.GetLogHeaderList(project, from, to, null, lumNum); SetData(logList); }
private void btnSearch_Click(object sender, EventArgs e) { int? project = (int?)luProject.EditValue; DateTime? from = (DateTime?)deFromDate.EditValue; DateTime? to = (DateTime?)deToDate.EditValue; EnumLogStatus?status = luLogStatus.EditValue == null ? null : (EnumLogStatus?)Enum.Parse(typeof(EnumLogStatus), (string)luLogStatus.EditValue); var logList = LemHeader.GetLogHeaderList(project, from, to, status, null); SetData(logList); }
private void gridView1_RowUpdated(object sender, RowObjectEventArgs e) { if (gridView1.IsNewItemRow(e.RowHandle)) { DataRow row = (e.Row as DataRowView).Row; row.SetValue(colId, LemHeader.SqlInsert(row.GetValue <DateTime>(colLogDate), row.GetValue <int>(colProjectCode), row.GetValueString(colLemNum), row.GetValueString(colDescription))); btnEmail.Enabled = true; btnPrint.Enabled = true; btnSubmit.Enabled = GetEnumName(EnumSubmitStatus.Open) == row.GetValueString(colSubmitStatus); } }
private void gvEquipment_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { DataRow row = gvEquipment.GetDataRow(e.RowHandle); if (e.Column == colEqpNum || e.Column == colAssetDescription) { string eqtNum = Convert.ToString(row[e.Column.FieldName]); row[colEqpNum.FieldName] = eqtNum; row[colAssetDescription.FieldName] = eqtNum; var equip = Equipment.GetEquipment(eqtNum); row[colEquipmentClass.FieldName] = EquipmentClass.GetEquipmentClass(equip.ClassCode)?.DisplayName ?? ""; Employee employee = (equip.OwnerType == EnumOwnerType.Employee) ? EquipmentAssignment.GetEmployee(equip.EqpNum, _headerRecord.LogDate) : null; row[colEmpNum.FieldName] = (object)employee?.EmpNum ?? DBNull.Value; row[colEmployeeName.FieldName] = employee?.DisplayName ?? ""; RefreshBillRate(row); } else if (e.Column == colLevel1Code) { row[colLevel2Code.FieldName] = DBNull.Value; row[colLevel3Code.FieldName] = DBNull.Value; row[colLevel4Code.FieldName] = DBNull.Value; } else if (e.Column == colLevel2Code) { row[colLevel3Code.FieldName] = DBNull.Value; row[colLevel4Code.FieldName] = DBNull.Value; } else if (e.Column == colLevel3Code) { row[colLevel4Code.FieldName] = DBNull.Value; } else if (e.Column == colBillCycle) { RefreshBillRate(row); } else if (e.Column == colQuantity) { RefreshBillAmount(row); } if (!gvEquipment.IsNewItemRow(e.RowHandle)) { if (new GridColumn[] { colEqpNum, colAssetDescription, colChangeOrder, colLevel1Code, colLevel2Code, colLevel3Code, colLevel4Code, colBillable, colQuantity, colBillCycle }.Contains(e.Column)) { EquipTimeEntry.SqlUpdate((int)row[colId.FieldName], (string)row[colEqpNum.FieldName], ConvertEx.ToNullable <int>(row[colEmpNum.FieldName]), ConvertEx.ToNullable <int>(row[colChangeOrder.FieldName]), ConvertEx.ToNullable <int>(row[colLevel1Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel2Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel3Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel4Code.FieldName]), (bool)row[colBillable.FieldName], ConvertEx.ToNullable <decimal>(row[colQuantity.FieldName]) ?? 0, ConvertEx.CharToEnum <EnumBillCycle>(row[colBillCycle.FieldName]), ConvertEx.ToNullable <decimal>(row[colBillAmount.FieldName])); LemHeader.SqlUpdateSubmitStatus(_headerRecord.Id, EnumSubmitStatus.Open); } } }
private void SetSubmitStatus(EnumSubmitStatus status) { var row = gridView1.GetDataRow(gridView1.FocusedRowHandle); if (row != null && row.GetValue(colSubmitStatus) != DBNull.Value && ConvertEx.StringToEnum <EnumSubmitStatus>(row.GetValueString(colSubmitStatus)) != status) { row.SetValue(colSubmitStatus, GetEnumName(status)); LemHeader.SqlUpdateSubmitStatus(row.GetValue <int>(colId), status); btnSubmit.Enabled = (status == EnumSubmitStatus.Open); } }
public void LoadFromPrevDay() { if (EquipTimeEntry.CopyDataFromPrevDay(_headerRecord.ProjectId, _headerRecord.LogDate, _headerRecord.Id)) { SetCurrent(_headerRecord); LemHeader.SqlUpdateSubmitStatus(_headerRecord.Id, EnumSubmitStatus.Open); } else { GuiCommon.ShowMessage("The previous day data is not available."); } }
private void gvEquipment_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { if (gvEquipment.IsNewItemRow(e.RowHandle)) { DataRowView row = e.Row as DataRowView; row[colId.FieldName] = EquipTimeEntry.SqlInsert(_headerRecord.Id, (string)row[colEqpNum.FieldName], ConvertEx.ToNullable <int>(row[colEmpNum.FieldName]), ConvertEx.ToNullable <int>(row[colChangeOrder.FieldName]), ConvertEx.ToNullable <int>(row[colLevel1Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel2Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel3Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel4Code.FieldName]), (bool)row[colBillable.FieldName], ConvertEx.ToNullable <decimal>(row[colQuantity.FieldName]) ?? 0, ConvertEx.CharToEnum <EnumBillCycle>(row[colBillCycle.FieldName]), ConvertEx.ToNullable <decimal>(row[colBillAmount.FieldName])); LemHeader.SqlUpdateSubmitStatus(_headerRecord.Id, EnumSubmitStatus.Open); } }
public void LoadFromTemplate() { if (LabourTimeEntry.CopyDataFromTemplate(_headerRecord.ProjectId, _headerRecord.LogDate, _headerRecord.Id)) { SetCurrent(_headerRecord); LemHeader.SqlUpdateSubmitStatus(_headerRecord.Id, EnumSubmitStatus.Open); } else { GuiCommon.ShowMessage("The template data is not available."); } }
private void btnSubmit_Click(object sender, EventArgs e) { var row = gridView1.GetDataRow(gridView1.FocusedRowHandle); if (!LemHeader.CheckLevelCodeValid(row.GetValue <int>(colId))) { ShowMessage($"Not all the LEM records contain {Company.GetCurrCompany().GetLevelCodeText()}, please check."); return; } SetSubmitStatus(EnumSubmitStatus.Ready); }
private void gridView1_RowDeleting(object sender, DevExpress.Data.RowDeletingEventArgs e) { DataRow row = gridView1.GetDataRow(e.RowHandle); if (ShowMessage("Delete Record?", "Confirmation", PopupType.Yes_No) == PopupResult.No) { e.Cancel = true; } else { LemHeader.SqlDelete(row.GetValue <int>(colId)); } }
private void gvLabour_RowDeleting(object sender, DevExpress.Data.RowDeletingEventArgs e) { if (GuiCommon.ShowMessage("Delete Record?", "Confirmation", PopupType.Yes_No) == PopupResult.No) { e.Cancel = true; } else { DataRow row = gvLabour.GetDataRow(e.RowHandle); LabourTimeEntry.DeleteEntry((int)row[colId.FieldName]); LemHeader.SqlUpdateSubmitStatus(_headerRecord.Id, EnumSubmitStatus.Open); } }
public void RefreshCurrentRowStatus() { var row = gridView1.GetDataRow(gridView1.FocusedRowHandle); if (row != null) { int id = row.GetValue <int>(colId); LemHeader data = LemHeader.GetLogHeader(id); row.SetValue(colSubmitStatus, GetEnumName(data.SubmitStatus)); btnSubmit.Enabled = GetEnumName(EnumSubmitStatus.Open) == row.GetValueString(colSubmitStatus); _fileMgr.Enabled = LemHeader.CheckEditable(row.GetCharEnumValue <EnumLogStatus>(colLogStatus)); } }
private void btnEmail_Click(object sender, EventArgs e) { CL_Dialog.PleaseWait.Show("Generating report...\r\nPlease Wait", ParentForm); string reportName = "LEMSheetApprovalX.rpt"; if (File.Exists($"{Application.StartupPath}\\{reportName}")) { var row = gridView1.GetDataRow(gridView1.FocusedRowHandle); try { string userName = LoginUser.CurrUser.GetUserName(); using (SqlConnection sqlcon = new SqlConnection(MobileDB)) { sqlcon.Open(); string sSQL = @"ReportLEMApproval"; SqlCommand cmd = new SqlCommand(sSQL, sqlcon); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@id", row.GetValue <int>(colId))); cmd.Parameters.Add(new SqlParameter("@username", userName)); cmd.ExecuteNonQuery(); } string[,] para = new string[2, 1]; para[0, 0] = "@username"; para[1, 0] = userName; var hmReport = new HMReport($"{Application.StartupPath}\\{reportName}", ServerName, DatabaseName, para, HMCon); string tempFile = Path.GetTempFileName(); hmReport.ExportReportToPDF(tempFile); byte[] bytes = File.ReadAllBytes(tempFile); LemHeader.SqlUpdateEmail(row.GetValue <int>(colId), bytes); File.Delete(tempFile); row.SetValue(colEmail, true); } catch (Exception ex) { ShowMessage($"Error: {ex.Message}"); } } else { ShowMessage($"The report {reportName} cannot be found."); } CL_Dialog.PleaseWait.Hide(); }
public void SetCurrent(LemHeader header) { _headerRecord = header; SetEnabled(_headerRecord.CheckEditable()); var changeOrderList = ChangeOrder.ListForProject(_headerRecord.ProjectId).Select(cs => new { EstimateId = cs.EstimateId, DisplayName = cs.DisplayName }).Distinct().ToList(); changeOrderList.Add(new { EstimateId = -1, DisplayName = "" }); luChangeOrder.DataSource = changeOrderList; tableLabour.Clear(); var list = LabourTimeEntry.GetLabourEntryList(header.Id).ToList(); list.ForEach(lte => { DataRow row = tableLabour.Rows.Add( lte.Id, lte.EmpNum, lte.EmpNum, lte.WorkClassCode, lte.ChangeOrderId, lte.Level1Id, lte.Level2Id, lte.Level3Id, lte.Level4Id, lte.Billable, lte.Manual, lte.IncludedHours, lte.TotalHours, lte.BillAmount); foreach (var timecode in TimeCode.SubList(TimeCode.EnumValueType.Hours)) { row[BillRateI(timecode)] = (object)ProjectWorkClass.GetBillRate(_headerRecord.ProjectId, timecode.MatchId, (string)row[colWorkClass.FieldName]) ?? DBNull.Value; row[EnterHoursI(timecode)] = (object)list.Find(x => x.Id == (int)row[colId.FieldName]).DetailList.SingleOrDefault(d => d.TimeCodeId == timecode.MatchId)?.WorkHours ?? DBNull.Value; } foreach (var timecode in TimeCode.SubList(TimeCode.EnumValueType.Dollars)) { row[EnterAmountI(timecode)] = (object)list.Find(x => x.Id == (int)row[colId.FieldName]).DetailList.SingleOrDefault(d => d.TimeCodeId == timecode.MatchId)?.Amount ?? DBNull.Value; } }); tableLabour.AcceptChanges(); gvLabour.BestFitColumns(true); }
public IHttpActionResult Post(int syncId, [FromBody] LemHeader log) { try { using (SqlConnection sqlcon = new SqlConnection(WebCommon.WebConnection)) { sqlcon.Open(); string sSQL = @"WS_FLEM_LogHeader_PostPut"; using (SqlCommand cmd = new SqlCommand(sSQL, sqlcon)) { cmd.CommandType = CommandType.StoredProcedure; SqlParameter paraMatchId; SqlParameter paraLemNum; cmd.Parameters.Add(new SqlParameter("@SyncId", syncId)); cmd.Parameters.Add(new SqlParameter("@ContactId", log.CreatorId)); cmd.Parameters.Add(new SqlParameter("@CompanyId", log.CompanyId)); cmd.Parameters.Add(paraMatchId = new SqlParameter("@MatchId", log.MatchId) { Direction = ParameterDirection.InputOutput }); cmd.Parameters.Add(new SqlParameter("@LogDate", log.LogDate)); cmd.Parameters.Add(new SqlParameter("@LogStatus", Enum.GetName(typeof(EnumLogStatus), log.LogStatus))); cmd.Parameters.Add(new SqlParameter("@ProjectId", log.ProjectId)); cmd.Parameters.Add(paraLemNum = new SqlParameter("@LemNum", log.LemNum) { Direction = ParameterDirection.InputOutput, Size = 20 }); cmd.Parameters.Add(new SqlParameter("@BillAmount", log.BillAmount)); cmd.Parameters.Add(new SqlParameter("@Description", ConvertEx.DbNullable(log.Description))); cmd.Parameters.Add(new SqlParameter("@EmailData", SqlDbType.VarBinary, log.EmailData?.Length ?? 0)).Value = ConvertEx.DbNullable(log.EmailData); cmd.ExecuteNonQuery(); string[] returnData = new string[] { paraMatchId.Value.ToString(), paraLemNum.Value.ToString() }; return(Ok(returnData)); } } } catch (Exception e) { SqlCommon.ReportInfo(e.Message); return(BadRequest(e.Message)); } }
private void gridView1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) { var row = gridView1.GetDataRow(gridView1.FocusedRowHandle); if (!LemHeader.CheckEditable(row.GetCharEnumValue <EnumLogStatus>(colLogStatus))) { e.Cancel = true; return; } if (new GridColumn[] { colProjectCode, colProjectName }.Contains(gridView1.FocusedColumn)) { if (row.GetValue(colId) != DBNull.Value && LemHeader.CheckHasEntry(row.GetValue <int>(colId))) { ShowMessage("This LEM Header contains Entries, cannot change the Project."); e.Cancel = true; return; } } }
public void SetCurrent(LemHeader header) { _headerRecord = header; SetEnabled(_headerRecord.CheckEditable()); tableAP.Clear(); LemAP.GetLemAP(header.ProjectId, header.Id).ForEach(x => tableAP.Rows.Add( x.Id, x.InvoiceDate, x.HeaderId == header.Id, x.InvoiceNum, Supplier.GetSupplier(x.SupplierCode).SupplierName, x.PONum, Project.GetProject(x.ProjectId).DisplayName, x.InvoiceAmount, x.MarkupAmount, x.BillAmount) ); tableAP.AcceptChanges(); }
public void SetCurrent(LemHeader header) { _headerRecord = header; SetEnabled(_headerRecord.CheckEditable()); var changeOrderList = ChangeOrder.ListForProject(_headerRecord.ProjectId).Select(cs => new { EstimateId = cs.EstimateId, DisplayName = cs.DisplayName }).Distinct().ToList(); luChangeOrder.DataSource = changeOrderList; tableEquipEntry.Clear(); EquipTimeEntry.GetEquipEntryList(header.Id).ToList().ForEach(x => { var equip = Equipment.GetEquipment(x.EqpNum); double?billRate = null; if (equip != null) { var list = equip.GetBillRateList(_headerRecord.ProjectId); billRate = (double?)list.SingleOrDefault(c => c.BillCycle == x.BillCycle)?.BillRate; } tableEquipEntry.Rows.Add( x.Id, x.EqpNum, x.EqpNum, EquipmentClass.GetEquipmentClass(equip.ClassCode)?.DisplayName ?? "", x.EmpNum, x.EmpNum != null ? Employee.GetEmployee(x.EmpNum.Value).DisplayName : "", x.ChangeOrderId, x.Level1Id, x.Level2Id, x.Level3Id, x.Level4Id, x.Billable, x.Quantity, (char)x.BillCycle, billRate, x.BillAmount); }); tableEquipEntry.AcceptChanges(); }
public void SetCurrentHeader(LemHeader header) { _headerRecord = header; var project = Project.GetProject(header.ProjectId); labelProject.Text = project.DisplayName; labelDate.Text = header.LogDate.ToString("yyyy/MM/dd"); labelCustName.Text = project.CustomerName; labelCustAddress.Text = project.CustomerAddress; labelSheetNum.Text = header.LemNum; labelReference.Text = project.POReference ?? ""; SetEnabled(_headerRecord.CheckEditable()); if (tabControl1.SelectedTabPage == tpLabour) { SetCurrentPage(tpLabour); } else { tabControl1.SelectedTabPage = tpLabour; } }
private void gvLabour_RowUpdated(object sender, RowObjectEventArgs e) { if (gvLabour.IsNewItemRow(e.RowHandle)) { DataRowView row = e.Row as DataRowView; row[colId.FieldName] = LabourTimeEntry.SqlInsert(_headerRecord.Id, (int)row[colEmpNum.FieldName], ConvertEx.ToNullable <int>(row[colChangeOrder.FieldName]), ConvertEx.ToNullable <int>(row[colLevel1Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel2Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel3Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel4Code.FieldName]), (bool)row[colBillable.FieldName], (bool)row[colManual.FieldName], (string)row[colWorkClass.FieldName], ConvertEx.ToNullable <decimal>(row[colIncludedHours.FieldName]), ConvertEx.ToNullable <decimal>(row[colTotalHours.FieldName]), ConvertEx.ToNullable <decimal>(row[colBillAmount.FieldName])); foreach (var timeCode in TimeCode.SubList(EnumValueType.Hours)) { LabourTimeDetail.SqlInsert((int)row[colId.FieldName], timeCode.MatchId, ConvertEx.ToNullable <decimal>(row[BillRateI(timeCode)]), ConvertEx.ToNullable <decimal>(row[EnterHoursI(timeCode)]), null); } foreach (var timeCode in TimeCode.SubList(EnumValueType.Dollars)) { LabourTimeDetail.SqlInsert((int)row[colId.FieldName], timeCode.MatchId, null, null, ConvertEx.ToNullable <decimal>(row[EnterAmountI(timeCode)])); } LemHeader.SqlUpdateSubmitStatus(_headerRecord.Id, EnumSubmitStatus.Open); } }
public LemHeader GetCurrentLog() { var row = gridView1.GetDataRow(gridView1.FocusedRowHandle); return(row == null ? null : LemHeader.GetLogHeader(row.GetValue <int>(colId))); }
private void gvEmployee_CellValueChanged(object sender, CellValueChangedEventArgs e) { DataRow row = gvLabour.GetDataRow(e.RowHandle); bool needSave = false; if (e.Column == colEmpNum || e.Column == colEmployeeName) { int enmNum = (int)row[e.Column.FieldName]; row[colEmpNum.FieldName] = enmNum; row[colEmployeeName.FieldName] = enmNum; var wc = LabourTemplate.GetWorkClass(_headerRecord.ProjectId, enmNum, _headerRecord.LogDate); row[colWorkClass.FieldName] = wc ?? (object)Employee.GetEmployee(enmNum)?.WorkClassCode ?? DBNull.Value; needSave = true; } if (e.Column == colEmpNum || e.Column == colEmployeeName || e.Column == colWorkClass) { UpdateBillRate(row); CalcTotal(row); needSave = true; } if (e.Column == colManual) { bool manual = (bool)row[colManual.FieldName]; if (!manual) { foreach (var timeCode in TimeCode.SubList(TimeCode.EnumValueType.Hours)) { row[EnterHoursI(timeCode)] = 0; } CalcTotal(row); } needSave = true; } if (e.Column == colLevel1Code) { row[colLevel2Code.FieldName] = DBNull.Value; row[colLevel3Code.FieldName] = DBNull.Value; row[colLevel4Code.FieldName] = DBNull.Value; needSave = true; } if (e.Column == colLevel2Code) { row[colLevel3Code.FieldName] = DBNull.Value; row[colLevel4Code.FieldName] = DBNull.Value; needSave = true; } if (e.Column == colLevel3Code) { row[colLevel4Code.FieldName] = DBNull.Value; needSave = true; } if (e.Column.FieldName.Contains(strEnterHours)) { CalcOvertime(row, e.Column.FieldName); CalcTotal(row); needSave = true; } if (new GridColumn[] { colChangeOrder, colBillable }.Contains(e.Column)) { needSave = true; } if (needSave && !gvLabour.IsNewItemRow(e.RowHandle)) { LabourTimeEntry.SqlUpdate((int)row[colId.FieldName], (int)row[colEmpNum.FieldName], ConvertEx.ToNullable <int>(row[colChangeOrder.FieldName]), ConvertEx.ToNullable <int>(row[colLevel1Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel2Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel3Code.FieldName]), ConvertEx.ToNullable <int>(row[colLevel4Code.FieldName]), (bool)row[colBillable.FieldName], (bool)row[colManual.FieldName], (string)row[colWorkClass.FieldName], ConvertEx.ToNullable <decimal>(row[colIncludedHours.FieldName]), ConvertEx.ToNullable <decimal>(row[colTotalHours.FieldName]), ConvertEx.ToNullable <decimal>(row[colBillAmount.FieldName])); row.AcceptChanges(); LemHeader.SqlUpdateSubmitStatus(_headerRecord.Id, EnumSubmitStatus.Open); } }
public void SetData(List <LemHeader> headerList) { tableLabour.Clear(); var table = LemHeader.GetCostCodeSummary(headerList.Select(x => x.Id).ToList()); var list = table.Select().Select(r => new { EmpNum = Convert.ToInt32(r["EmpNum"]), WorkClassCode = Convert.ToString(r["WorkClassCode"]), Billable = Convert.ToBoolean(r["Billable"]), ProjectId = Convert.ToInt32(r["ProjectId"]), ChangeOrderId = ConvertEx.ToNullable <int>(r["ChangeOrderId"]), Level1Id = ConvertEx.ToNullable <int>(r["Level1Id"]), Level2Id = ConvertEx.ToNullable <int>(r["Level2Id"]), Level3Id = ConvertEx.ToNullable <int>(r["Level3Id"]), Level4Id = ConvertEx.ToNullable <int>(r["Level4Id"]), TimeCodeId = Convert.ToInt32(r["TimeCodeId"]), SumWorkHour = ConvertEx.ToNullable <decimal>(r["SumWorkHour"]), SumAmount = ConvertEx.ToNullable <decimal>(r["SumAmount"]), }); var groupList = list.ToLookup(x => new { x.EmpNum, x.WorkClassCode, x.Billable, x.ProjectId, x.ChangeOrderId, x.Level1Id, x.Level2Id, x.Level3Id, x.Level4Id, EmpName = Employee.GetEmployee(x.EmpNum)?.DisplayName, WorkClass = WorkClass.GetWorkClass(x.WorkClassCode).DisplayName, Project = Project.GetProject(x.ProjectId), ChangeOrder = ChangeOrder.GetChangeOrder(x.ProjectId, x.ChangeOrderId)?.DisplayName, Level1 = LevelOneCode.GetLevelCode(x.Level1Id)?.DisplayName, Level2 = LevelTwoCode.GetLevelCode(x.Level2Id)?.DisplayName, Level3 = LevelThreeCode.GetLevelCode(x.Level3Id)?.DisplayName, Level4 = LevelFourCode.GetLevelCode(x.Level4Id)?.DisplayName }).OrderBy(x => x.Key.Level1).ThenBy(x => x.Key.Level2).ThenBy(x => x.Key.Level3).ThenBy(x => x.Key.Level4).ThenBy(x => x.Key.EmpName).ThenBy(x => x.Key.Project).ThenBy(x => x.Key.ChangeOrder).ThenBy(x => x.Key.WorkClass).ThenBy(x => x.Key.Billable).ToList(); groupList.ForEach(g => { DataRow row = tableLabour.Rows.Add( g.Key.EmpNum, g.Key.EmpName, g.Key.WorkClass, g.Key.Project, g.Key.ChangeOrder, g.Key.Level1, g.Key.Level2, g.Key.Level3, g.Key.Level4, g.Key.Billable, null, null); decimal?billRate; decimal totalHours = 0; decimal billAmounts = 0; foreach (var timecode in TimeCode.ListForCompany()) { if (timecode.ValueType == EnumValueType.Hours) { billRate = ProjectWorkClass.GetBillRate(g.Key.ProjectId, timecode.MatchId, g.Key.WorkClassCode); row[ColName.BillRateI(timecode)] = (object)billRate ?? DBNull.Value; decimal hours = g.Where(x => x.TimeCodeId == timecode.MatchId).Sum(x => x.SumWorkHour) ?? 0; row[ColName.EnterValueI(timecode)] = hours != 0 ? (object)hours : DBNull.Value; totalHours += hours; billAmounts += (billRate ?? 0) * hours; } else { decimal amount = g.Where(x => x.TimeCodeId == timecode.MatchId).Sum(x => x.SumAmount) ?? 0; row[ColName.EnterValueI(timecode)] = amount != 0 ? (object)amount : DBNull.Value; billAmounts += amount; } row[ColName.TotalHours] = totalHours != 0 ? (object)totalHours : DBNull.Value; row[ColName.BillAmount] = billAmounts != 0 ? (object)billAmounts : DBNull.Value; } }); }
public void SetCurrent(LemHeader header) { _headerRecord = header; tableLabour.Clear(); var table = LemHeader.GetEmployeeSummary(new List <int> { header.Id }); var list = table.Select().Select(r => new { EmpNum = Convert.ToInt32(r["EmpNum"]), WorkClassCode = Convert.ToString(r["WorkClassCode"]), ProjectId = Convert.ToInt32(r["ProjectId"]), TimeCodeId = Convert.ToInt32(r["TimeCodeId"]), SumWorkHour = ConvertEx.ToNullable <decimal>(r["SumWorkHour"]), SumAmount = ConvertEx.ToNullable <decimal>(r["SumAmount"]), }); var groupList = list.ToLookup(x => new { x.EmpNum, x.WorkClassCode, x.ProjectId, EmpName = Employee.GetEmployee(x.EmpNum)?.DisplayName, WorkClass = WorkClass.GetWorkClass(x.WorkClassCode).DisplayName }).OrderBy(x => x.Key.EmpName).ThenBy(x => x.Key.WorkClass).ToList(); groupList.ForEach(g => { var row = tableLabour.Rows.Add( g.Key.EmpNum, g.Key.EmpName, g.Key.WorkClass, null, null); decimal?billRate; decimal totalHours = 0; decimal billAmounts = 0; foreach (var timecode in TimeCode.ListForCompany()) { if (timecode.ValueType == EnumValueType.Hours) { billRate = ProjectWorkClass.GetBillRate(g.Key.ProjectId, timecode.MatchId, g.Key.WorkClassCode); row[BillRateI(timecode)] = (object)billRate ?? DBNull.Value; decimal hours = g.Where(x => x.TimeCodeId == timecode.MatchId).Sum(x => x.SumWorkHour) ?? 0; row[EnterValueI(timecode)] = hours != 0 ? (object)hours : DBNull.Value; totalHours += hours; billAmounts += (billRate ?? 0) * hours; } else { decimal amount = g.Where(x => x.TimeCodeId == timecode.MatchId).Sum(x => x.SumAmount) ?? 0; row[EnterValueI(timecode)] = amount != 0 ? (object)amount : DBNull.Value; billAmounts += amount; } row[colTotalHours.FieldName] = totalHours != 0 ? (object)totalHours : DBNull.Value; row[colBillAmount.FieldName] = billAmounts != 0 ? (object)billAmounts : DBNull.Value; } }); }