public static string SP_FindPemeriksaanById(string id, out Data.Pemeriksaan p) { p = null; SqlConnection sqlConn = new SqlConnection(); SqlCommand sqlCmd = new SqlCommand(); SqlDataAdapter sqlAdap = new SqlDataAdapter(); try { sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["AMS_StockConnectionString"].ToString(); sqlConn.Open(); sqlCmd.CommandText = "SP_FindPemeriksaanById"; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Connection = sqlConn; SqlParameter parm1 = new SqlParameter("@Id", SqlDbType.Int); parm1.Value = int.Parse(id); parm1.Direction = ParameterDirection.Input; sqlCmd.Parameters.Add(parm1); sqlAdap.SelectCommand = sqlCmd; DataSet ds = new DataSet(); sqlAdap.Fill(ds); DataRow dr = ds.Tables[0].Rows[0]; p = new Data.Pemeriksaan { Id = (int)dr["Id"], LembagaId = dr["LembagaId"].ToString() }; for (int i = 0; i < ds.Tables[1].Rows.Count; i++) { Data.PemeriksaanDetail pd = new Data.PemeriksaanDetail { Id = int.Parse(ds.Tables[1].Rows[i]["Id"].ToString()), StockRegId = int.Parse(ds.Tables[1].Rows[i]["StockRegId"].ToString()), CurrentBalance = int.Parse(ds.Tables[1].Rows[i]["Balance"].ToString()), ParasMenokok = int.Parse(ds.Tables[1].Rows[i]["ParasMenokok"].ToString()), StockId = int.Parse(ds.Tables[1].Rows[i]["StockId"].ToString()), StockCode = ds.Tables[1].Rows[i]["StockRegNo"].ToString(), StockName = ds.Tables[1].Rows[i]["StockDetail"].ToString() }; p.Details.Add(pd); } //DataRow drDetail = ds.Tables[0].Rows[0]; return string.Empty; } catch (Exception err) { return err.Message; } finally { sqlConn.Close(); sqlConn.Dispose(); sqlCmd.Dispose(); } }
public static DataTable ParseToDataTable(Data.Pemeriksaan theObject) { DataTable dat = new DataTable(); Data.Pemeriksaan datos = new Data.Pemeriksaan(); foreach (PropertyInfo info in typeof(Data.Pemeriksaan).GetProperties()) { if (info.PropertyType != typeof(string) && info.PropertyType.GetInterface(typeof(IEnumerable).Name) != null && info.PropertyType.GetInterface(typeof(IEnumerable<>).Name) != null) { continue; } dat.Columns.Add(info.Name, info.PropertyType); } dat.AcceptChanges(); DataRow row = dat.NewRow(); datos = theObject; foreach (var info in datos.GetType().GetProperties()) { if (info.PropertyType != typeof(string) && info.PropertyType.GetInterface(typeof(IEnumerable).Name) != null && info.PropertyType.GetInterface(typeof(IEnumerable<>).Name) != null) { continue; } row[info.Name] = info.GetValue(datos, null); } dat.Rows.Add(row); dat.AcceptChanges(); return dat; }
private void Save(string CurrUser) { try { var glLembagaName = FindControlRecursive(this, "glLembagaName") as ASPxGridLookup; var gvSenaraiStok = FindControlRecursive(this, "gvSenaraiStok") as ASPxGridView; Data.Pemeriksaan p = new Data.Pemeriksaan { LembagaId = glLembagaName.Value.ToString(), }; for (int i = 0; i < gvSenaraiStok.VisibleRowCount; i++) { Data.PemeriksaanDetail sr = new Data.PemeriksaanDetail(); sr.StockRegId = int.Parse(gvSenaraiStok.GetRowValues(i, "Id").ToString()); p.Details.Add(sr); } string err = Core.Stor.PemeriksaanMethods.SP_PemeriksaanSave(int.Parse(CurrUser), p); if (err == "") { cbp_Main.JSProperties["cpErrMsg"] = string.Empty; } else { string errMsg = ConfigurationManager.AppSettings["ErrorMessageStaringSentenceDBError"].ToString(); errMsg = errMsg.Replace("BR", "<br><br>"); cbp_Main.JSProperties["cpErrMsg"] = errMsg + " " + err; } } catch (Exception err) { string errMsg = ConfigurationManager.AppSettings["ErrorMessageStaringSentenceCaughtByExceptions"].ToString(); errMsg = errMsg.Replace("BR", "<br><br>"); cbp_Main.JSProperties["cpErrMsg"] = errMsg + " " + err; } finally { } }