protected void lnk_Edit_Command(object sender, CommandEventArgs e) { try { clearControls(); SMHR_MedicalInvoice oSMHR_MedicalInvoice = new SMHR_MedicalInvoice(); oSMHR_MedicalInvoice.OPERATION = operation.Select; oSMHR_MedicalInvoice.InvoiceDocID = Convert.ToInt32(Convert.ToString(e.CommandArgument)); oSMHR_MedicalInvoice.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); DataTable dt = BLL.get_MedicalInvoice(oSMHR_MedicalInvoice); if (Convert.ToInt32(Session["WRITEFACILITY"]) == 2) { btn_Edit.Visible = false; } else { btn_Edit.Visible = true; } Rm_CG_page.SelectedIndex = 1; } catch (Exception ex) { SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "UploadInvoice", ex.StackTrace, DateTime.Now); Response.Redirect("~/Frm_ErrorPage.aspx"); } }
protected void btn_Save_Click(object sender, EventArgs e) { try { oSMHR_MedicalInvoice = new SMHR_MedicalInvoice(); bool result = true; ValidateData(out oSMHR_MedicalInvoice, out result); if (result) { oSMHR_MedicalInvoice.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); switch (((Button)sender).ID.ToUpper()) { case "BTN_EDIT": oSMHR_MedicalInvoice.InvoiceDocID = Convert.ToInt32(lbl_InvoiceDocID.Text); oSMHR_MedicalInvoice.OPERATION = operation.Update; if (BLL.set_MedicalInvoice(oSMHR_MedicalInvoice)) { BLL.ShowMessage(this, "Information Updated Successfully"); } else { BLL.ShowMessage(this, "Information Not Saved"); } break; case "BTN_SAVE": oSMHR_MedicalInvoice.OPERATION = operation.Insert; if (BLL.set_MedicalInvoice(oSMHR_MedicalInvoice)) { BLL.ShowMessage(this, "Information Saved Successfully"); } else { BLL.ShowMessage(this, "Information Not Saved"); } break; default: break; } Rm_CG_page.SelectedIndex = 0; LoadGrid(); Rg_Categories.DataBind(); } } catch (Exception ex) { SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "UploadInvoice", ex.StackTrace, DateTime.Now); Response.Redirect("~/Frm_ErrorPage.aspx"); } }
public void LoadGrid() { try { SMHR_MedicalInvoice oSMHR_MedicalInvoice = new SMHR_MedicalInvoice(); oSMHR_MedicalInvoice.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); oSMHR_MedicalInvoice.OPERATION = operation.Select; DataTable DT = BLL.get_MedicalInvoice(oSMHR_MedicalInvoice); Rg_Categories.DataSource = DT; clearControls(); } catch (Exception ex) { SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "UploadInvoice", ex.StackTrace, DateTime.Now); Response.Redirect("~/Frm_ErrorPage.aspx"); } }
private void ValidateData(out SMHR_MedicalInvoice oSMHR_MedicalInvoice, out bool result) { try { result = true; oSMHR_MedicalInvoice = new SMHR_MedicalInvoice(); string strfilename = Guid.NewGuid().ToString() + FBrowse.FileName; strfilename2 = strfilename; if (FBrowse.HasFile) { FBrowse.PostedFile.SaveAs(Server.MapPath("~/MedicalInvoice/") + strfilename); } else { result = false; BLL.ShowMessage(this, "Please Select the File to upload"); return; } string strpath = Server.MapPath("~/MedicalInvoice/") + strfilename; string ExcelPath = System.Configuration.ConfigurationManager.AppSettings["ExcelPath"];//"Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;"; string strcon = ExcelPath + "Data Source='" + strpath + "';"; DataTable dtExcelData = GetDatafromExcel(strcon); if (dtExcelData != null && ValidateHeader(dtExcelData)) { if (dtExcelData.Rows.Count != 0) { oSMHR_MedicalInvoice.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); oSMHR_MedicalInvoice.OPERATION = operation.Check; DataTable dtBenficaryDetails = BLL.get_MedicalInvoice(oSMHR_MedicalInvoice); oSMHR_MedicalInvoice.OPERATION = operation.Validate; DataTable dtInvoiceValidate = BLL.get_MedicalInvoice(oSMHR_MedicalInvoice); DataTable dtInvoices = CreateInvoiceTable(); SMHR_EXPENDITURE oSMHR_EXPENDITURE = new SMHR_EXPENDITURE(); oSMHR_EXPENDITURE.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); oSMHR_EXPENDITURE.OPERATION = operation.Select; DataTable dtexpenditures = BLL.get_Expenditure(oSMHR_EXPENDITURE); foreach (DataRow record in dtExcelData.Rows) { if (!string.IsNullOrEmpty(record["Beneficiary Name"].ToString().Trim())) { if (dtBenficaryDetails.Select("BenficaryName='" + record["Beneficiary Name"].ToString().Trim() + "'").Length == 0) { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Benficary Name not exists"); return; } } else { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Benficary Name should not be empty"); return; } if (string.IsNullOrEmpty(record["Invoice ID"].ToString().Trim())) { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Invoice ID should not be empty"); return; } if (string.IsNullOrEmpty(record["Invoice Date"].ToString().Trim())) { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Invoice Date should not be empty"); return; } if (string.IsNullOrEmpty(record["Staff Name"].ToString().Trim())) { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Staff Name should not be empty"); return; } if (!string.IsNullOrEmpty(record["Exp Name"].ToString().Trim())) { if (dtexpenditures.Select("expenditure_name='" + record["Exp Name"].ToString().Trim() + "'").Length == 0) { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Exp Name not exists"); return; } } else { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Exp Name should not be empty"); return; } if (!string.IsNullOrEmpty(record["Service Provider"].ToString().Trim()) && string.Compare(record["Service Provider"].ToString().Trim(), "Select", true) != 0) { if (string.Compare(record["Service Provider"].ToString().Trim(), RadServiceProviderName.SelectedItem.Text.Trim(), true) != 0) { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Service Provider mismatch"); return; } } else { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Service Provider should not be empty"); return; } if (!string.IsNullOrEmpty(record["Amount"].ToString().Trim())) { double d; if (!double.TryParse(record["Amount"].ToString().Trim(), out d)) { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Amount should be a number"); return; } } else { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Amount should not be empty"); return; } if (dtInvoiceValidate.Select("SERVICEPROVIDERNAME='" + record["Service Provider"].ToString().Trim() + "' and INVOICEID='" + record["Invoice ID"].ToString().Trim() + "'").Length > 0) { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Invoice ID already exists"); return; } DateTime drt = new DateTime(); try { drt = Convert.ToDateTime(record[1].ToString()); } catch (Exception ex) { result = false; BLL.ShowMessage(this, "Date Format should be mm/dd/yyyy"); } dtInvoices.Rows.Add(record[0].ToString(), drt.ToString("MM/dd/yyyy"), record[2].ToString(), record[3].ToString(), record[4].ToString(), record[5].ToString(), record[6].ToString()); } //if (dtInvoices.Select("Invoice ID='" + record["Exp Name"].ToString().Trim() + "'").Length == 0) //{ //} oSMHR_MedicalInvoice.ServiceProviderID = Convert.ToInt32(RadServiceProviderName.SelectedValue); oSMHR_MedicalInvoice.InvoiceDoc = "~/MedicalInvoice/" + strfilename; oSMHR_MedicalInvoice.MedicalInvoice = dtInvoices; oSMHR_MedicalInvoice.CREATEDBY = Convert.ToInt32(Session["USER_ID"]); oSMHR_MedicalInvoice.CREATEDDATE = DateTime.Now; oSMHR_MedicalInvoice.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); } else { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "There are no records to load"); return; } } else { Delete_Excel_File(); result = false; BLL.ShowMessage(this, "Header mismatch"); return; } } catch (Exception ex) { throw ex; } }