Solved

Newbie needs help passing variables and clean-up.

Posted on 2003-11-14
3
237 Views
Last Modified: 2010-04-16
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();
                        
               
                  }


            }
      }
}
0
Comment
Question by:dcass
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
ptmcomp earned 500 total points
ID: 9753941
The problem is that ArrayList has no type information about orditem. You have to cast the items back to orditem to access members of the items.

                         ArrayList ordItems = new ArrayList();
                         string sModel;
                         foreach (DataRow dr in dtConfDtl.Rows)
                         {
                              try
                              {  
                                   orditem myOrdItem;

                                   myOrdItem = new ordItem(ordItems.Count, dr, DNID);
                                   ordItems.Add(myOrdItem);
                                   if (myOrdItem.sModel != null)
                                        this.Model = myOrdItem.sModel;
                              }
                              catch (System.UnauthorizedAccessException)
                              {
                              }
                         }

Note: Please read about naming conventions in C# and use properties to access private members. Public member variables are seen as dirty programming. This is not necessary to make it work but it helps others to read the code.

Change this:

          public class ordItem
          {
               private int index;
               ...
               private double Part_Quantity;
               public string sModel;
               public string sModelDesc;

to this:

          public class OrdItem
          {
               private int index;
               ...
               private double part_Quantity;
               private string model;
               private string modelDesc;

               // use properties to access private stuff
               public string ModelDesc
               {
                   get
                   {
                       return modelDesc;
                   }
               }
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9753946
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)
0
 

Author Comment

by:dcass
ID: 9765646
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.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question