protected void btnSubmit_Click(object sender, EventArgs e) { using (var ctx = new dsSPDDataContext()) { var spd = ctx.trSPDs.FirstOrDefault(o => o.noSPD == Id.Value); var firstApproval = ctx.ApprovalStatus.FirstOrDefault(o => o.NoSPD == Id.Value && o.IndexLevel.Value == 1); if (spd == null) { errorMessageHidden.Add("SPD tidak ditemukan"); } if (firstApproval == null) { errorMessageHidden.Add("Approval pertama tidak ditemukan"); } if (errorMessageHidden.Count() == 0) { spd.diubahOleh = karyawan.nrp; spd.diubahTanggal = DateTime.Now; spd.isSubmitDate = DateTime.Now; spd.nrpAtasan = firstApproval.NrpApproval; spd.status = "Menunggu approval " + firstApproval.ApprovalRule.Deskripsi; spd.isSubmit = true; try { ctx.SubmitChanges(); } catch (Exception ex) { errorMessageHidden.Add("Error Submit SPD, gangguan teknis"); errorMessageHidden.Add(ex.Message); } finally { pnlSuccess.Visible = true; pnlError.Visible = false; lblSuccess.Text = "SPD Berhasil di Submit, No SPD : " + spd.noSPD + ", status spd saat ini adalah " + spd.status; btnSubmit.Enabled = false; // send approval atasan EmailCore.ApprovalSPD(firstApproval.NrpApproval, Id.Value, firstApproval.IndexLevel.Value.ToString(), spd); } } if (errorMessageHidden.Count() > 0) { errorMessage.DataSource = errorMessageHidden; errorMessage.DataBind(); pnlError.Visible = true; pnlSuccess.Visible = false; } } }
void ProcessNew(string noSPD) { noSPD = noSPD.Trim(); using (var ctx = new dsSPDDataContext()) { var dataSpd = ctx.trSPDs.FirstOrDefault(o => o.noSPD == noSPD); var approval = ctx.ApprovalStatus.Where(o => o.NoSPD == noSPD).OrderBy(o => o.IndexLevel); if (dataSpd != null && approval != null) { switch (dataSpd.isApproved) { case null: if (approval.Where(o => o.Status == null).Count() == 0) { // proses approval tujuan EmailCore.ApprovalSPD(dataSpd.nrpApprovalTujuan, dataSpd.noSPD, string.Empty, dataSpd); } else { // proses next approval var currentApproval = approval.FirstOrDefault(o => o.Status == null); EmailCore.ApprovalSPD(currentApproval.NrpApproval, dataSpd.noSPD, currentApproval.IndexLevel.ToString(), dataSpd); } break; case true: var dataClaim = ctx.trClaims.FirstOrDefault(o => o.noSPD == noSPD); if (dataClaim != null) { if (dataClaim.isSubmit == true) { if (dataClaim.isApprovedAtasan == null && dataClaim.isApprovedFinance == null && dataClaim.isApprovedGA == null) { //send approval atasan EmailCore.ApprovalClaim(dataClaim.nrpAtasan, dataClaim.noSPD, dataSpd, "Atasan", dataClaim.status); } if (dataClaim.isApprovedAtasan == true && dataClaim.isApprovedFinance == null && dataClaim.isApprovedGA == null) { //send approval GA var role = (from p in ctx.msUsers where p.roleId == 17 select p.nrp).ToList(); var dataGa = ctx.msKaryawans .Where(o => o.coCd == "0001" && role.Contains(o.nrp)); foreach (var item in dataGa) { EmailCore.ApprovalClaim(item.nrp, dataClaim.noSPD, dataSpd, "GA", dataClaim.status); } } if (dataClaim.isApprovedAtasan == true && dataClaim.isApprovedFinance == null && dataClaim.isApprovedGA == true) { //send approval Finance var creator = ctx.msKaryawans.FirstOrDefault(o => o.nrp == dataSpd.nrp); var role2 = (from p in ctx.msUsers where p.roleId == 19 select p.nrp).ToList(); var datafinace = ctx.msKaryawans .Where(o => o.coCd == creator.coCd && role2.Contains(o.nrp)); foreach (var item in datafinace) { EmailCore.ApprovalClaim(item.nrp, dataClaim.noSPD, dataSpd, "finance", dataClaim.status); } } } } // claim break; default: break; } } } }