private String BuildInsertCommand(Expenditure_Material MExpenditure) { String command; StringBuilder sb = new StringBuilder(); sb.AppendFormat("Values({0}, '{1}' ,{2})", MExpenditure.ExpenditureNum, MExpenditure.NumMaterial, MExpenditure.Amount); String prefix = "INSERT INTO GLN_Expenditure_Material " + "(ExpenditureNum,NumMaterial,Amount) "; command = prefix + sb.ToString(); return(command); }
///Post שני public int InsertMExpenditureToDB(Expenditure_Material MExpenditure) { SqlConnection con; SqlCommand cmd; try { con = Connect("DBConnectionString"); // create the connection } catch (Exception ex) { // write to log throw (ex); } try { String cStr = ""; //String cStr = ""; int numEffected = 0; cStr = BuildInsertCommand(MExpenditure); // helper method to build the insert string cmd = CreateCommand(cStr, con); // create the command numEffected += cmd.ExecuteNonQuery(); // execute the command return(numEffected); } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { // close the db connection con.Close(); } } }
public List <Expenditure_Material> returnExM(string mispar) { List <Expenditure_Material> SCL = new List <Expenditure_Material>(); SqlConnection con = null; try { con = Connect("DBConnectionString"); // create a connection to the database using the connection String defined in the web config file String selectSTR = "SELECT * FROM GLN_Expenditure_Material where ExpenditureNum='" + mispar + "'"; SqlCommand cmd = new SqlCommand(selectSTR, con); // get a reader SqlDataReader dr = cmd.ExecuteReader();//(CommandBehavior.CloseConnection); // CommandBehavior.CloseConnection: the connection will be closed after reading has reached the end while (dr.Read()) { // Read till the end of the data into a row Expenditure_Material a = new Expenditure_Material(); a.ExpenditureNum = Convert.ToInt32(dr["ExpenditureNum"]); a.NumMaterial = (string)(dr["NumMaterial"]); a.Amount = Convert.ToInt32(dr["Amount"]); SCL.Add(a); } dr.Close(); } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { con.Close(); } } return(SCL); }
[Route("api/ExpenditureProducts/insertMExpenditure")] //הכנסת סוג חומר(מס הוצאה,מקט פנימי וכמות) public void postMExpenditure([FromBody] Expenditure_Material MExpenditure) { Expenditure_Material O = new Expenditure_Material(); O.insert(MExpenditure); }
public List <Expenditure_Material> Get(string mispar) { Expenditure_Material ex = new Expenditure_Material(); return(ex.returnExM(mispar)); }