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."; } }
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); }