public static string ExportPreEnterStr(string month, string gridCode) { MMR_CP22Entities1 entities = new MMR_CP22Entities1(); var _context = new MMR_CP22Entities1(); int iGridCode = int.Parse(gridCode); List <VW_PRE_ENTER> pe = _context.VW_PRE_ENTER.Where(s => s.MONTH == month && s.GRID_CODE == iGridCode ).ToList <VW_PRE_ENTER>(); StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}{1}", "billing_month, grid_code, grid_name, feeder_code, feeder_name, prev_kwh_reading, prv_kvarh_reading, prv_meter_status, multiplying_factor, meter_range", Environment.NewLine); foreach (VW_PRE_ENTER row in pe) { sb.AppendFormat( "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}" , row.MONTH != null ? row.MONTH.ToString() : "" , row.GRID_CODE != 0 ? row.GRID_CODE.ToString() : "" , row.GRID_NAME != null ? row.GRID_NAME.ToString() : "" , row.FEEDER_CODE != null ? row.FEEDER_CODE.ToString() : "" , row.FEEDER_NAME != null ? row.FEEDER_NAME.ToString() : "" , row.PREV_KWH_READING != null ? row.PREV_KWH_READING.ToString() : "" , row.PREV_KVARH_READING != null ? row.PREV_KVARH_READING.ToString() : "" , row.PREV_METER_STATUS != null ? row.PREV_METER_STATUS.ToString() : "" , row.M_FACTOR != null ? row.M_FACTOR.ToString() : "" , row.RANGE != null ? row.RANGE.ToString() : "" , Environment.NewLine.ToString()); } return(sb.ToString()); }
protected void gvReading_RowUpdating(object sender, GridViewUpdateEventArgs e) { string month = gvReading.DataKeys[e.RowIndex].Values[0].ToString(); string feeder = gvReading.DataKeys[e.RowIndex].Values[1].ToString(); TextBox txtCur_Kwh_Reading = (TextBox)gvReading.Rows[e.RowIndex].FindControl("txtCur_Kwh_Reading"); TextBox txtCur_Kvarh_Reading = (TextBox)gvReading.Rows[e.RowIndex].FindControl("txtCur_Kvarh_Reading"); TextBox txtCur_Meter_Status = (TextBox)gvReading.Rows[e.RowIndex].FindControl("txtCur_Meter_Status"); TextBox txtCur_MF = (TextBox)gvReading.Rows[e.RowIndex].FindControl("txtCur_MF"); string uName = Session["uname"].ToString(); using (MMR_CP22Entities1 context = new MMR_CP22Entities1()) { var FrmBRow = context.CP22_FORMB.Find(month, feeder); if (FrmBRow != null) { //update FrmBRow.FIN_READ = !string.IsNullOrEmpty(txtCur_Kwh_Reading.Text) ? decimal.Parse(txtCur_Kwh_Reading.Text) : FrmBRow.FIN_READ; FrmBRow.FIN_KVARH_READ = !string.IsNullOrEmpty(txtCur_Kvarh_Reading.Text) ? decimal.Parse(txtCur_Kvarh_Reading.Text) : FrmBRow.FIN_KVARH_READ; FrmBRow.STATUS_CODE = txtCur_Meter_Status.Text.Length > 0 ? txtCur_Meter_Status.Text.Substring(0, 1) : string.Empty; FrmBRow.MFACTOR = !string.IsNullOrEmpty(txtCur_MF.Text) ? decimal.Parse(txtCur_MF.Text) : FrmBRow.MFACTOR; FrmBRow.MODIFIED_BY = uName; FrmBRow.MODIFIED_ON = DateTime.Now; } context.SaveChanges(); } gvReading.EditIndex = -1; BindGrid(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["auth"] != null && Session["auth"].ToString() == "1") { if (!IsPostBack) { string loggedinUser = Session["uname"].ToString(); var user = (VW_USER)Session["user"]; string month = Request.QueryString["month"].ToString(); string gridCD = Request.QueryString["grid"].ToString(); string postedFlag = Request.QueryString["posted"].ToString(); ReportViewer1.ProcessingMode = ProcessingMode.Local; ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/rptMonReading.rdlc"); MMR_CP22Entities1 context = new MMR_CP22Entities1(); ReportDataSource datasource = new ReportDataSource("dsCP22_FORMB", (from VW_CP22_FORMB in context.VW_CP22_FORMB where VW_CP22_FORMB.GRID_CODE == gridCD && VW_CP22_FORMB.MONTH == month && VW_CP22_FORMB.uName.ToUpper().Equals(user.uName.ToUpper()) && VW_CP22_FORMB.POSTED_FLAG == postedFlag select VW_CP22_FORMB)); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(datasource); } } else { Response.Redirect("~/Login.aspx"); } }
protected void GVEmployee_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "InsertNew") { GridViewRow row = GVEmployee.FooterRow; TextBox txtName = row.FindControl("txtEmpNameNew") as TextBox; TextBox txtPassword = row.FindControl("txtPasswordNew") as TextBox; DropDownList ddlStatusNew = row.FindControl("ddlStatusNew") as DropDownList; DropDownList ddlRoleNew = row.FindControl("ddlRoleNew") as DropDownList; DropDownList ddlCompanyNew = row.FindControl("ddlCompanyNew") as DropDownList; TextBox txtuFULL_NAME = row.FindControl("txtuFULL_NAMENew") as TextBox; DropDownList ddlGridCodeNew = row.FindControl("ddlGridCodeNew") as DropDownList; if (ddlRoleNew.SelectedValue.ToString() != "1") { using (MMR_CP22Entities1 context = new MMR_CP22Entities1()) { User obj = new User(); obj.uName = txtName.Text; obj.uPassword = txtPassword.Text; obj.uStatus = bool.Parse(ddlStatusNew.SelectedValue); obj.rID = int.Parse(ddlRoleNew.SelectedValue); obj.CMP_CODE = ddlCompanyNew.SelectedValue; obj.uFULL_NAME = txtuFULL_NAME.Text; obj.GRID_CODE = ddlGridCodeNew.SelectedValue; context.Users.Add(obj); var mrExis = context.MR_CONTROL.Find(obj.CMP_CODE, DateTime.Now.AddMonths(-1).ToString("MMyyyy")); if (mrExis == null) { var mr = new MR_CONTROL(); mr.BMONTH = DateTime.Now.AddMonths(-1); mr.CMP_CODE = obj.CMP_CODE; mr.CREATED_BY = Session["uname"].ToString(); mr.CREATED_DATE = DateTime.Now; mr.MONTH = DateTime.Now.AddMonths(-1).ToString("MMyyyy"); mr.STATUS = "1"; context.MR_CONTROL.Add(mr); } context.SaveChanges(); BindGrid(); lblErrorExp.Text = "User added successfully!"; lblErrorExp.ForeColor = System.Drawing.Color.Green; } } else { lblErrorExp.Text = "Cannot add another Admin user!"; lblErrorExp.ForeColor = System.Drawing.Color.Red; } } else if (e.CommandName == "Cancel" || e.CommandName == "CancelNew") { GVEmployee.EditIndex = -1; BindGrid(); lblErrorExp.Text = ""; } }
public static string GetGridByCode(int gCode) { MMR_CP22Entities1 context = new MMR_CP22Entities1(); var gridObj = context.TBL_GRID_STATION.Find(gCode); if (gridObj != null) { return(gridObj.GRID_STATION_NAME + "(" + gridObj.GRID_STATION_CODE + ")"); } return("Undefind"); }
public static string GetRoleByRID(int rID) { MMR_CP22Entities1 context = new MMR_CP22Entities1(); var userObj = context.Roles.Find(rID); if (userObj != null) { return(userObj.rName); } return("Undefind"); }
private List <CP22_FORMB> GetDataPreEnter() { using (MMR_CP22Entities1 context = new MMR_CP22Entities1()) { if (context.CP22_FORMB.Count() > 0) { if (txtMonth.Text.Length > 0 && txtDivCode.Text.Length > 0 && txtCcCode.Text.Length > 0) { return(context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.DIVCODE == txtDivCode.Text && em.CC_CODE == txtCcCode.Text).ToList()); } } } return(null); }
protected void GVEmployee_RowDeleting(object sender, GridViewDeleteEventArgs e) { int uID = Convert.ToInt32(GVEmployee.DataKeys[e.RowIndex].Value); using (MMR_CP22Entities1 context = new MMR_CP22Entities1()) { User obj = context.Users.First(x => x.uID == uID); context.Users.Remove(obj); context.SaveChanges(); BindGrid(); lblErrorExp.Text = "User deleted successfully!"; lblErrorExp.ForeColor = System.Drawing.Color.Green; } }
public static VW_USER isUserAuthetic(string name, string pwd) { VW_USER uObj = new VW_USER(); MMR_CP22Entities1 _context = new MMR_CP22Entities1(); var pe = _context.VW_USER.Where(s => s.uName == name && s.uPassword == pwd ).ToList(); if (pe.Count > 0) { uObj = pe.First(); uObj.uPassword = "******"; } return(uObj); }
public static HttpResponseMessage ExportPreEnter(string month, string gridCode) { MMR_CP22Entities1 entities = new MMR_CP22Entities1(); var _context = new MMR_CP22Entities1(); int iGridCode = int.Parse(gridCode); List <VW_PRE_ENTER> pe = _context.VW_PRE_ENTER.Where(s => s.MONTH == month && s.GRID_CODE == iGridCode ).ToList <VW_PRE_ENTER>(); StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}{1}", "billing_month, grid_code, grid_name, feeder_code, feeder_name, prev_kwh_reading, prv_kvarh_reading, prv_meter_status, multiplying_factor, meter_range", Environment.NewLine); foreach (VW_PRE_ENTER row in pe) { sb.AppendFormat( "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}" , row.MONTH != null ? row.MONTH.ToString() : "" , row.GRID_CODE != 0 ? row.GRID_CODE.ToString() : "" , row.GRID_NAME != null ? row.GRID_NAME.ToString() : "" , row.FEEDER_CODE != null ? row.FEEDER_CODE.ToString() : "" , row.FEEDER_NAME != null ? row.FEEDER_NAME.ToString() : "" , row.PREV_KWH_READING != null ? row.PREV_KWH_READING.ToString() : "" , row.PREV_KVARH_READING != null ? row.PREV_KVARH_READING.ToString() : "" , row.PREV_METER_STATUS != null ? row.PREV_METER_STATUS.ToString() : "" , row.M_FACTOR != null ? row.M_FACTOR.ToString() : "" , row.RANGE != null ? row.RANGE.ToString() : "" , Environment.NewLine.ToString()); } MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); writer.Write(sb.ToString()); writer.Flush(); stream.Position = 0; string fName = month + "_" + gridCode + "_Export.csv"; HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/csv"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fName }; return(result); }
void BindGrid() { using (MMR_CP22Entities1 context = new MMR_CP22Entities1()) { if (context.Users.Count() > 0) { GVEmployee.DataSource = (from em in context.Users.OrderBy(u => u.uID) select new { em.uID, em.uName, em.uPassword, em.uStatus, em.rID, em.CMP_CODE, em.uFULL_NAME, em.GRID_CODE } ).ToList(); GVEmployee.DataBind(); } else { GVEmployee.DataSource = null; GVEmployee.DataBind(); } } }
protected void gvReading_RowDeleting(object sender, GridViewDeleteEventArgs e) { string month = gvReading.DataKeys[e.RowIndex].Values[0].ToString(); string feeder = gvReading.DataKeys[e.RowIndex].Values[1].ToString(); using (MMR_CP22Entities1 context = new MMR_CP22Entities1()) { CP22_FORMB obj = context.CP22_FORMB.Where(s => s.MONTH == month && s.FEEDER == feeder ).FirstOrDefault(); context.CP22_FORMB.Remove(obj); context.SaveChanges(); string snapFolderPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/Snaps/"); string kwhSnapPath = snapFolderPath + obj.MONTH + "_" + obj.GRID_CODE + "_" + obj.FEEDER + "_kwh.jpg"; string kvarhSnapPath = snapFolderPath + obj.MONTH + "_" + obj.GRID_CODE + "_" + obj.FEEDER + "_kvarh.jpg"; ImageDeleteFromFolder(obj.MONTH + "_" + obj.GRID_CODE + "_" + obj.FEEDER + "_kwh.jpg", kwhSnapPath); ImageDeleteFromFolder(obj.MONTH + "_" + obj.GRID_CODE + "_" + obj.FEEDER + "_kwh.jpg", kvarhSnapPath); BindGrid(); lblErrorExp.Text = "Deleted successfully."; } }
protected void GVEmployee_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GVEmployee.Rows[e.RowIndex]; TextBox txtName = row.FindControl("txtEmpName") as TextBox; TextBox txtPassword = row.FindControl("txtPassword") as TextBox; DropDownList ddlStatus = row.FindControl("ddlStatus") as DropDownList; DropDownList ddlRole = row.FindControl("ddlRole") as DropDownList; DropDownList ddlCompany = row.FindControl("ddlCompany") as DropDownList; TextBox txtuFULL_NAME = row.FindControl("txtuFULL_NAME") as TextBox; DropDownList ddlGridCode = row.FindControl("ddlGridCode") as DropDownList; if (ddlRole.SelectedValue != "1") { using (MMR_CP22Entities1 context = new MMR_CP22Entities1()) { int uID = Convert.ToInt32(GVEmployee.DataKeys[e.RowIndex].Value); User obj = context.Users.First(x => x.uID == uID); obj.uName = txtName.Text; obj.uPassword = txtPassword.Text; obj.uStatus = bool.Parse(ddlStatus.SelectedValue); obj.rID = int.Parse(ddlRole.SelectedValue); obj.CMP_CODE = ddlCompany.SelectedValue; obj.uFULL_NAME = txtuFULL_NAME.Text; obj.GRID_CODE = ddlGridCode.SelectedValue; context.SaveChanges(); GVEmployee.EditIndex = -1; BindGrid(); lblErrorExp.Text = "User updated successfully!"; lblErrorExp.ForeColor = System.Drawing.Color.Green; } } else { lblErrorExp.Text = "Cannot add another Admin user!"; lblErrorExp.ForeColor = System.Drawing.Color.Red; } }
private bool CheckPEExistance() { bool exists = false; using (MMR_CP22Entities1 context = new MMR_CP22Entities1()) { if (context.CP22_FORMB.Count() > 0) { if (txtMonth.Text.Length > 0 && txtDivCode.Text.Length > 0 && txtCcCode.Text.Length > 0) { var peObj = context.CP22_FORMB.Where(s => s.MONTH == txtMonth.Text && s.DIVCODE == txtDivCode.Text && s.CC_CODE == txtCcCode.Text ).ToList(); if (peObj.Count > 0) { exists = true; } } } } return(exists); }
private List <CP22_FORMB> GetDataFormB() { using (MMR_CP22Entities1 _context = new MMR_CP22Entities1()) { if (_context.CP22_FORMB.Count() > 0) { if (txtMonth.Text.Length > 0 && txtGridCode.Text.Length == 0 && txtGridName.Text.Length == 0 && txtFeederCode.Text.Length == 0 && txtFeederName.Text.Length == 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtGridCode.Text.Length > 0 && txtGridName.Text.Length == 0 && txtFeederCode.Text.Length == 0 && txtFeederName.Text.Length == 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.GRID_CODE == txtGridCode.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtGridCode.Text.Length > 0 && txtGridName.Text.Length > 0 && txtFeederCode.Text.Length == 0 && txtFeederName.Text.Length == 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.GRID_CODE == txtGridCode.Text && em.GRID_NAME == txtGridName.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtGridCode.Text.Length > 0 && txtGridName.Text.Length > 0 && txtFeederCode.Text.Length > 0 && txtFeederName.Text.Length == 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.GRID_CODE == txtGridCode.Text && em.GRID_NAME == txtGridName.Text && em.FEEDER == txtFeederCode.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtGridCode.Text.Length > 0 && txtGridName.Text.Length > 0 && txtFeederCode.Text.Length > 0 && txtFeederName.Text.Length > 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.GRID_CODE == txtGridCode.Text && em.GRID_NAME == txtGridName.Text && em.FEEDER == txtFeederCode.Text && em.FEEDER_NAME == txtFeederName.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length == 0 && txtGridCode.Text.Length > 0 && txtGridName.Text.Length > 0 && txtFeederCode.Text.Length > 0 && txtFeederName.Text.Length > 0) { return(_context.CP22_FORMB.Where(em => em.GRID_CODE == txtGridCode.Text && em.GRID_NAME == txtGridName.Text && em.FEEDER == txtFeederCode.Text && em.FEEDER_NAME == txtFeederName.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length == 0 && txtGridCode.Text.Length == 0 && txtGridName.Text.Length > 0 && txtFeederCode.Text.Length > 0 && txtFeederName.Text.Length > 0) { return(_context.CP22_FORMB.Where(em => em.GRID_NAME == txtGridName.Text && em.FEEDER == txtFeederCode.Text && em.FEEDER_NAME == txtFeederName.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length == 0 && txtGridCode.Text.Length == 0 && txtGridName.Text.Length == 0 && txtFeederCode.Text.Length > 0 && txtFeederName.Text.Length == 0) { return(_context.CP22_FORMB.Where(em => em.FEEDER == txtFeederCode.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length == 0 && txtGridCode.Text.Length == 0 && txtGridName.Text.Length == 0 && txtFeederCode.Text.Length == 0 && txtFeederName.Text.Length > 0) { return(_context.CP22_FORMB.Where(em => em.FEEDER_NAME == txtFeederName.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtGridCode.Text.Length > 0 && txtGridName.Text.Length == 0 && txtFeederCode.Text.Length >= 0 && txtFeederName.Text.Length == 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.GRID_CODE == txtGridCode.Text && em.FEEDER == txtFeederCode.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtGridCode.Text.Length == 0 && txtGridName.Text.Length >= 0 && txtFeederCode.Text.Length == 0 && txtFeederName.Text.Length == 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.GRID_NAME == txtGridName.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtFeederCode.Text.Length > 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.FEEDER == txtFeederCode.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtFeederName.Text.Length > 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.FEEDER_NAME.Contains(txtFeederName.Text.Trim()) && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtGridCode.Text.Length > 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.GRID_CODE == txtGridCode.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtGridCode.Text.Length > 0 && txtFeederCode.Text.Length > 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.GRID_CODE == txtGridCode.Text && em.FEEDER == txtFeederCode.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtFeederName.Text.Length > 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.FEEDER_NAME == txtFeederName.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else if (txtMonth.Text.Length > 0 && txtGridName.Text.Length > 0) { return(_context.CP22_FORMB.Where(em => em.MONTH == txtMonth.Text && em.GRID_NAME == txtGridName.Text && em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } else { return(_context.CP22_FORMB.Where(em => em.POSTED_FLAG == rblPosted.SelectedValue).ToList()); } } } return(null); }
protected void Page_Load(object sender, EventArgs e) { //return; //System.Drawing.Image kwhImg = System.Drawing.Image.FromFile(Server.MapPath("~/Images/selectedtab.GIF")); //byte[] arrKwh; //MemoryStream mskwh = new MemoryStream(); //kwhImg.Save(mskwh, System.Drawing.Imaging.ImageFormat.Jpeg); //arrKwh = mskwh.ToArray(); //System.Drawing.Image imgKvh = System.Drawing.Image.FromFile(Server.MapPath("~/Images/unselectedtab.GIF")); // byte[] arrKvh; // MemoryStream msKvh = new MemoryStream(); // imgKvh.Save(msKvh, System.Drawing.Imaging.ImageFormat.Jpeg); // arrKvh = msKvh.ToArray(); //// MemoryStream ms1 = new MemoryStream(arr); //// System.Drawing.Image i = System.Drawing.Image.FromStream(ms1, true, true); //// i.Save(Server.MapPath("~/Images/Snaps/test.gif")); if (Session["auth"] != null && Session["auth"].ToString() == "1") { return; } else { Response.Redirect("~/Login.aspx", false); } var _context = new MMR_CP22Entities1(); var FrmBRow = _context.CP22_FORMB.Find("082019", "200123"); if (FrmBRow != null) { _context.SaveChanges(); try { //MemoryStream ms = new MemoryStream(arrKwh); MemoryStream ms = new MemoryStream(Convert.FromBase64String("R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==")); System.Drawing.Image i = System.Drawing.Image.FromStream(ms, true, true); i.Save(Server.MapPath("~/Images/Snaps/kwh.jpg")); } catch (Exception ex) { lblError.Text = ex.ToString(); } try { MemoryStream ms = new MemoryStream(Convert.FromBase64String("R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==")); System.Drawing.Image i = System.Drawing.Image.FromStream(ms, true, true); i.Save(Server.MapPath("~/Images/Snaps/kvh.jpg")); } catch (Exception ex) { lblError.Text += ex.ToString(); } } return; if (Session["auth"] != null && Session["auth"].ToString() == "1") { ; } else { Response.Redirect("~/Login.aspx"); } }
public static string SaveReadings(List <MonReadingSnap> mrs, string snapFolderPath) { string result = "Unkown"; try { int recUpdated = 0; var _context = new MMR_CP22Entities1(); foreach (var fdr in mrs) { var FrmBRow = _context.CP22_FORMB.Find(fdr.month, fdr.feeder_code); if (FrmBRow != null) { //update FrmBRow.FIN_READ = fdr.cur_kwh_reading != null?decimal.Parse(fdr.cur_kwh_reading) : 0; FrmBRow.KWH_SNAP = fdr.kwh_snap != null ? fdr.kwh_snap : null; FrmBRow.FIN_KVARH_READ = fdr.cur_kvarh_reading != null?decimal.Parse(fdr.cur_kvarh_reading) : 0; FrmBRow.D_UNITS = fdr.cur_kwh_reading != null?decimal.Parse(fdr.cur_kwh_reading) - FrmBRow.PREV_READ : 0; FrmBRow.STATUS_CODE = fdr.cur_meter_status != null?fdr.cur_meter_status.Substring(0, 1) : null; FrmBRow.MFACTOR = fdr.cur_mf != null?decimal.Parse(fdr.cur_mf) : 1; FrmBRow.METER_RANGE = fdr.cur_meter_range != null?byte.Parse(fdr.cur_meter_range) : Byte.MinValue; FrmBRow.KVARH_SNAP = fdr.kvarh_snap != null ? fdr.kvarh_snap : null; FrmBRow.LATITUDE = fdr.latitude != null ? fdr.latitude : null; FrmBRow.LONGITUDE = fdr.longitude != null ? fdr.longitude : null; FrmBRow.MODIFIED_BY = fdr.mr_name != null ? fdr.mr_name : null; DateTime dtime = DateTime.Now; if (fdr.time_stamp != null) { DateTime.TryParseExact(fdr.time_stamp, "dd-MM-yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dtime); } FrmBRow.MODIFIED_ON = dtime; _context.SaveChanges(); //kwh snap creation at path ~/Images/Snaps/ SaveSnap(fdr.kwh_snap, snapFolderPath + fdr.month + "_" + fdr.grid_code + "_" + fdr.feeder_code + "_kwh.jpg"); //kvarh snap creation at path ~/Images/Snaps/ SaveSnap(fdr.kvarh_snap, snapFolderPath + fdr.month + "_" + fdr.grid_code + "_" + fdr.feeder_code + "_kvarh.jpg"); recUpdated++; } } result = recUpdated.ToString() + " Updated Successfully"; } catch (DbEntityValidationException e) { StringBuilder sb = new StringBuilder(); foreach (var eve in e.EntityValidationErrors) { sb.AppendFormat("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) { sb.AppendFormat("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } result = sb.ToString(); } catch (Exception ex) { result = ex.ToString(); } return(result); }
public static string CreatePreEnter(string bmonth, string SDivCode, string CcCode, VW_USER user) { string status = "UnKnown"; try { string conStr = System.Configuration.ConfigurationManager.ConnectionStrings["hesco"].ToString(); DBUtil dbUtil = new DBUtil(conStr); DataTable dt = dbUtil.GetCP22MasterData(bmonth, SDivCode, CcCode); var _context = new MMR_CP22Entities1(); if (dt != null && dt.Rows.Count > 0) { int recNO = 0; foreach (DataRow dr in dt.Rows) { try { /* * Insert Into Cp22_Formb("MONTH", Bmonth, Feeder, Feeder_Name, Mfactor, Prev_Read, PREV_KVARH_READ, Meter_Range, Sdiv_1, Share_1, Fdrsdiv, Fdrcircle, Proof_Listing_Flag, Posted_Flag, Divcode, U_Name, Cp_No, Cc_Code, Record_No, Created_On, Created_By,Type,Main_Feeder,METER_NO,STATUS_CODE) * Values(Vmonth, P_Month, Vfdrcode, Vfdrname, Vmfactor, Vprev_Reading, vPREV_KVARH_READING_A, Vmeter_Range, Vfdrsdiv , '100.00', Vfdrsdiv, Vcircle, 'N', 'N', Vdivcode, Vu_Name, Vcp_No, Vcc_Code, Vrecord_No, Systimestamp, 'PREENTER',Vtype,Vmain_Feeder,vMTR_NO,'P'); */ CP22_FORMB formB = new CP22_FORMB(); formB.MONTH = dr["Vmonth"].ToString(); formB.BMONTH = DateTime.ParseExact(dr["vPMonth"].ToString(), "MMyyyy", System.Globalization.CultureInfo.InvariantCulture); formB.FEEDER = dr["Vfdrcode"].ToString(); formB.FEEDER_NAME = dr["Vfdrname"].ToString(); formB.MFACTOR = decimal.Parse(dr["Vmfactor"].ToString()); formB.PREV_READ = decimal.Parse(dr["Vprev_Reading"].ToString()); formB.PREV_KVARH_READ = !string.IsNullOrEmpty(dr["vPREV_KVARH_READING_A"].ToString()) ? decimal.Parse(dr["vPREV_KVARH_READING_A"].ToString()) : 0; formB.METER_RANGE = !string.IsNullOrEmpty(dr["vMTR_RANGE"].ToString()) ? byte.Parse(dr["vMTR_RANGE"].ToString()) : new byte(); formB.SDIV_1 = dr["Vfdrsdiv"].ToString(); formB.SHARE_1 = 100; formB.FDRSDIV = dr["Vfdrsdiv"].ToString(); formB.FDRCIRCLE = dr["Vcircle"].ToString(); formB.PROOF_LISTING_FLAG = "N"; formB.POSTED_FLAG = "N"; formB.DIVCODE = SDivCode; formB.U_NAME = user.uName; formB.CP_NO = "CP22"; formB.CC_CODE = CcCode; formB.RECORD_NO = recNO + 1; formB.CREATED_ON = DateTime.Now; formB.CREATED_BY = "PREENTER-MMR"; formB.TYPE = dr["Vtype"].ToString(); formB.MAIN_FEEDER = dr["vMAIN_FEEDER"].ToString(); formB.METER_NO = dr["vMTR_NO"].ToString(); formB.STATUS_CODE = "P"; formB.GRID_CODE = user.GRID_CODE; formB.GRID_NAME = user.GRID_NAME; _context.CP22_FORMB.Add(formB); recNO++; } catch (Exception ex) { } } _context.SaveChanges(); status = recNO.ToString() + " / " + dt.Rows.Count.ToString() + " created successfully"; } else { status = "No data found for given criteria!"; } } catch (DbEntityValidationException e) { StringBuilder sb = new StringBuilder(); foreach (var eve in e.EntityValidationErrors) { sb.AppendFormat("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) { sb.AppendFormat("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } status = sb.ToString(); } catch (Exception ex) { status = ex.ToString(); } return(status); }
protected void GVEmployee_RowDataBound(object sender, GridViewRowEventArgs e) { MMR_CP22Entities1 context = new MMR_CP22Entities1(); LinkButton lbtnPassword = e.Row.FindControl("lbtnPassword") as LinkButton; DropDownList ddlRole = e.Row.FindControl("ddlRole") as DropDownList; DropDownList ddlStatus = e.Row.FindControl("ddlStatus") as DropDownList; DropDownList ddlCompany = e.Row.FindControl("ddlCompany") as DropDownList; DropDownList ddlGridCode = e.Row.FindControl("ddlGridCode") as DropDownList; DropDownList ddlGridCodeNew = e.Row.FindControl("ddlGridCodeNew") as DropDownList; Label lblCMP_CODE = e.Row.FindControl("lblCMP_CODE") as Label; Label lblStatus = e.Row.FindControl("lblStatus") as Label; Label lblrID = e.Row.FindControl("lblrID") as Label; Label lblGRID_CODE = e.Row.FindControl("lblGRID_CODE") as Label; if (e.Row.RowType == DataControlRowType.Footer) { if (context.TBL_GRID_STATION.Count() > 0) { if (ddlGridCodeNew != null) { ddlGridCodeNew.DataSource = (from em in context.TBL_GRID_STATION select new { em.GRID_STATION_CODE, em.GRID_STATION_NAME }).ToList(); ddlGridCodeNew.DataTextField = "GRID_STATION_NAME"; ddlGridCodeNew.DataValueField = "GRID_STATION_CODE"; ddlGridCodeNew.DataBind(); ddlGridCodeNew.Items.Add(new ListItem("Select Grid", "")); ddlGridCodeNew.SelectedValue = ""; } } } if (e.Row.RowType == DataControlRowType.DataRow) { int uID = Convert.ToInt32(GVEmployee.DataKeys[e.Row.RowIndex].Value); User obj = context.Users.First(x => x.uID == uID); if (lbtnPassword != null) { lbtnPassword.Attributes.Add("onClick", "return false;"); if (Session["rid"].ToString() == "1" || (Session["rid"].ToString() != "1" && obj.rID != 1)) { lbtnPassword.OnClientClick = "javascript:alert('Password is : " + obj.uPassword + "');"; } } if (ddlRole != null) { ddlRole.SelectedValue = obj.rID.ToString(); } if (ddlStatus != null) { ddlStatus.SelectedValue = obj.uStatus.ToString(); } if (ddlCompany != null) { ddlCompany.SelectedValue = obj.CMP_CODE; } if (context.TBL_GRID_STATION.Count() > 0) { if (ddlGridCode != null) { ddlGridCode.DataSource = (from em in context.TBL_GRID_STATION select new { em.GRID_STATION_CODE, em.GRID_STATION_NAME }).ToList(); ddlGridCode.DataTextField = "GRID_STATION_NAME"; ddlGridCode.DataValueField = "GRID_STATION_CODE"; ddlGridCode.DataBind(); ddlGridCode.Items.Add(new ListItem("Select Grid", "")); ddlGridCode.SelectedValue = obj.GRID_CODE; } } if (lblGRID_CODE != null) { lblGRID_CODE.Text = Util.GetGridByCode(int.Parse(obj.GRID_CODE)); } if (lblCMP_CODE != null) { lblCMP_CODE.Text = Util.GetCompNameByCode(obj.CMP_CODE) + "(" + obj.CMP_CODE + ")"; } if (lblStatus != null) { lblStatus.Text = obj.uStatus == true ? "Active" : "InActive"; } if (lblrID != null) { lblrID.Text = Util.GetRoleByRID(obj.rID); } if (obj.rID == 1) { LinkButton lnkEdit = e.Row.FindControl("lnkEdit") as LinkButton; lnkEdit.Visible = false; LinkButton lnkDelete = e.Row.FindControl("lnkDelete") as LinkButton; lnkDelete.Visible = false; } } }