Link to home
Start Free TrialLog in
Avatar of dcass
dcassFlag for United States of America

asked on

Newbie needs help passing variables and clean-up.

Newbie needs help passing variables from inside a class.  It's a web service and I can't get "Model" back from the class to update a table.  Any help is appreciated and I know this code is terrible so any clean-up suggestions are appreciated.  The purpose is to read the first table to see if this order has already been updated to the table.  If it has not, then it gets the header record and then the detail records from the "from" table.  It then updates the detail records in the "to" table from the array (in the class) and gathers the Model ordered from one of the detail records, saving it in sModel.   Then it's time to update the header record in the "to" table with the model, but since it's outside of the class, I can't retrieve it from the class, even though I can see it in debug in ordItems _items.
I'll give 250 points for passing the variable and 250 for clean-up suggestions (in code).

            [WebMethod]
            public string UpdtConfWG(string DNID)
            {

                  //  Check to see if already updated
                  SqlConnection conWG = dbAccess.getSqlConnection("WebOrder");
                  string sqlWG = "select * from db3l2p1 where Var2="+DNID;
                  bool WGHdr = dbAccess.getFirstRecord(conWG, sqlWG);
           

                  // if not found in WG database, continue
                  if (WGHdr)
                  {
                        // Need configurator table record (header)
                        SqlConnection con = dbAccess.getSqlConnection("Config");
                        string sqlHdr = "select * from configuration where CONF_ID = (" + DNID + ")";
                        object[] confHdr = dbAccess.readFirstRecord(con, sqlHdr);
                        string USERID = confHdr[1].ToString();
                        double BASEPRICE = Convert.ToDouble(confHdr[2]);
                        string CONF_DATE = confHdr[3].ToString();
                        string CONF_DESC = confHdr[4].ToString();
                        string CUSTOMER_NAME = confHdr[5].ToString();
                        string CONF_STATUS = confHdr[7].ToString();
                        if (CONF_STATUS == "3")
                        {
                              double CONF_TOTAL = Convert.ToDouble(confHdr[8]);
                              int MAPICS_ORDER = Convert.ToInt16(confHdr[9]);
                              string SHIPPING_INSTRUCTION = confHdr[12].ToString();
                              string TERM = confHdr[13].ToString();
                              string DEALER_PO_NUM = confHdr[14].ToString();                        

                              // configuration_tree table records (detail)
                              //SqlConnection conDtl = dbAccess.getSqlConnection("Config");
                              string sqlDtl = "select * from cf_get_conf_Info(" + DNID + ")";
                              string confTable2 = "Configuration";
                              DataTable dtConfDtl = dbAccess.getDataTable(con, confTable2, sqlDtl);            
                  

                              ArrayList ordItems = new ArrayList();
                    string sModel;
                              foreach (DataRow dr in dtConfDtl.Rows)
                              {
                                    try
                                    {  
                                          ordItems.Add(new ordItem(ordItems.Count, dr, DNID));
                                          //Here is where my problem is - I need the model from the class
                                          //  this won't compile, but I can see it in debug in ordItems _item
                                          //Error for next line: 'System.Collections.ArrayList' does not contain a definition for 'sModel'
                                          if (ordItems.sModel != null)
                            //Error for next line: An object reference is required for the nonstatic field, method, or property 'WebOrderUpdates.CSIWebOrderUpdts.ordItem.sModel"
                                        if (ordItem.sModel != null)
                                                this.Model = ordItem.sModel;
                                    }
                                    catch (System.UnauthorizedAccessException)
                                    {
                                    }
                              }

                              //WebOrderUpdates.ordItems oi = ordItems;
                              //string sModel = ((ordItems)[4].ToString());
                              //string sModel = "";//ordItems[4].sModel;
                              string sModelDesc = "";//ordItem[4];
                              sqlHdr = "INSERT INTO db3l2p1 (Division,Location,DNID,DNMacID,DealerNumber,DealerPO,Terms,ModelDesc,OrderDate,Status)"
                                    + " VALUES ('BlountFied','ZEB',"+DNID+",'"+Model+"','"+USERID+"','"+DEALER_PO_NUM+"','"+TERM+"','"+sModelDesc+"','"+CONF_DATE+"','10'" ;
                              SqlConnection conHdr = dbAccess.getSqlConnection("WebOrder");
                              SqlCommand oInsertCommand = new SqlCommand(sqlHdr);
                              oInsertCommand.Connection = conHdr;
                              oInsertCommand.ExecuteScalar();
                              conHdr.Close();

                              return "Update Completed";
                        }

                  return "Update Completed";

                  }

      return "Update Completed";

}      


            public class ordItem
            {
                  private int index;
                  private string Equipment_Name;
                  private string Equipment_Description;
                  private string Order_Code;
                  private string Mapics_Num;
                  private string Equipment_Code;
                  private int Quantity_Item;
                  private double Price;
                  private string Part_Name;
                  private string Part_Description;
                  private string WGPN;
                  private string WGPNT;
                  private double Part_Quantity;
                  public string sModel;
                  public string sModelDesc;
                  

                  public ordItem(int index, DataRow dr, string DNID)
                  {
                        this.index = index;
                        Equipment_Name = dr[0].ToString();
                        Equipment_Description = dr[1].ToString();
                        Order_Code = dr[2].ToString();
                        Mapics_Num = Convert.ToString(dr[3]);
                        Equipment_Code = dr[4].ToString();
                        Quantity_Item = Convert.ToInt16(dr[5]);
                        Price = Convert.ToDouble(dr[6]);
                        Part_Name = dr[7].ToString();
                        Part_Description = dr[8].ToString();
                        WGPN = dr[9].ToString();
                        WGPNT = dr[10].ToString();
                        Part_Quantity = Convert.ToDouble(dr[11]);
                        string sModel;
                        bool isStatic = false;
                        string sqlDtl;
                        
                        if (WGPNT == "HL")
                        {
                              sModel = Equipment_Name;
                              //Model = Equipment_Name;
                              sModelDesc = Equipment_Description;
                              sqlDtl = "INSERT INTO db3l2p2 (Var0,Var1,Var2,Var3,Var4,Var5,Var6,Var9)"
                                    + " VALUES ("+DNID+","+this.index+",'"+Order_Code+"','"+Equipment_Description+"',"+Quantity_Item+",'"+Equipment_Name+"','"+WGPN+"',"+Price+")" ;
                        }
                        else
                        {
                              sqlDtl = "INSERT INTO db3l2p2 (Var0,Var1,Var2,Var3,Var4,Var5,Var6,Var9)"
                                    + " VALUES ("+DNID+","+this.index+",'"+Order_Code+"','"+Equipment_Name+"',"+Quantity_Item+",'"+Equipment_Code+"','"+WGPN+"',"+Price+")" ;
                        }

                //public string dSQL { get {return sql;} }
                        SqlConnection conDtl = dbAccess.getSqlConnection("WebOrder");
                        SqlCommand oInsertCommand = new SqlCommand(sqlDtl);
                        oInsertCommand.Connection = conDtl;
                        oInsertCommand.ExecuteScalar();
                        conDtl.Close();
                        
               
                  }


            }
      }
}
ASKER CERTIFIED SOLUTION
Avatar of ptmcomp
ptmcomp
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This line:
  if (ordItems.sModel != null)
cannot work since you cannot access a property of a single item on an array. How should the system know which of the items you want to access.

This would work:
  if (((orditem)ordItems[0]).sModel != null)
Avatar of dcass

ASKER

The first anwer worked just fine.
However, I would like to make put both update into a table and update with a Fill statement instead of the update I have here.
Wouldn't that be cleaner?  That would fulfill my other question for the points.
Thanks in advance.