Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
J

joost versteegen

@joost versteegen
About
Posts
62
Topics
13
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • filling a column with property value of object
    J joost versteegen

    you can overwrite the ToString function

    C# css tutorial

  • Minimize the risk that (bad) programmers call specific functions?
    J joost versteegen

    make your functions private and call them from the validation layer

    Design and Architecture algorithms question

  • problem with xml code
    J joost versteegen

    I have a problem with the following xml documents. they look like this:

    my c# code:

    public class StructArray
    {
        \[XmlAttribute(AttributeName = "name")\]
        public string Name
        {
            get; set;
        }
    
        \[XmlArray(ElementName = "structDef")\]
        \[XmlArrayItem(ElementName = "item", Type = typeof(StructDefItem))\]
        public List StructDefinition
        {
            get; set;
        }
    
        \[XmlArray(ElementName = "values")\]
        \[XmlArrayItem(ElementName = "item", Type = typeof(StructValueItem))\]
        public List Values
        {
            get; set;
        }
    }
    
    public class StructDefItem
    {
        \[XmlAttribute(AttributeName = "name")\]
        public string Name
        {
            get; set;
        }
    
        \[XmlAttribute(AttributeName = "dataType")\]
        public Int32 DataType
        {
            get; set;
        }
    }
    
    \[XmlInclude(typeof(Tool))\]
    \[XmlInclude(typeof(Component))\]
    public class StructValueItem
    {
    }
    
    public class Tool : StructValueItem
    {
        //\[XmlAttribute(AttributeName = "id")\]
        public string id
        {
            get; set;
        }
    
        //\[XmlAttribute(AttributeName = "state")\]
        public Int32 state
        {
            get; set;
        }
    
        //\[XmlAttribute(AttributeName = "counter")\]
        public Int32 counter
        {
            get; set;
        }
    }
    

    The problem is that the type of object can be all sort of things (in this example a tool or a component), but when I use XmlInclude, the result gives : wich is not allowed, the data comes without xmnls information and

    XML / XSL csharp xml help tutorial

  • finding periods
    J joost versteegen

    i finally figured it out, here's the result:

    DECLARE @PERIOD TABLE (start_time DATETIME, end_time DATETIME)

    INSERT INTO @PERIOD(start_time)
    SELECT t.start_time FROM (
    SELECT act_start_time_utc AS start_time, state_cd AS new_state, LAG(state_cd, 1) OVER (ORDER BY act_start_time_utc ASC) AS last_state
    FROM SRPMES901007.WWMESDB.dbo.job
    WHERE act_start_time_utc IS NOT NULL) AS t
    WHERE t.new_state = 4 AND t.last_state <> 4

    UPDATE period
    SET end_time = (SELECT TOP(1) act_start_time_utc FROM SRPMES901007.WWMESDB.dbo.job WHERE state_cd <> 4 AND act_start_time_utc > period.start_time ORDER BY act_start_time_utc ASC)
    FROM @PERIOD period

    SELECT * FROM @PERIOD ORDER BY start_time ASC

    But the query takes 19 seconds, can it be speeded up?

    Database database help question announcement career

  • finding periods
    J joost versteegen

    given a table job with columns time_utc (datetime) and state (integer), i want to find the periods (start-time and end_time) where the consequetive value of the state column equals 4. i tried to find the start of the periods with the folllowing query, but no success. too many results. can someone please help me? i cannot figure it out.

    SELECT act_start_time_utc, state_cd FROM SRPMES901007.WWMESDB.dbo.job WHERE act_start_time_utc IS NOT NULL ORDER BY act_start_time_utc ASC

    DECLARE @PERIOD TABLE (start_time DATETIME, end_time DATETIME)

    INSERT INTO @PERIOD(start_time)
    SELECT t.start_time/*, t.new_state, t.last_state*/ FROM (
    SELECT act_start_time_utc AS start_time, state_cd AS new_state, LAG(state_cd, 1) OVER (ORDER BY act_start_time_utc ASC) AS last_state
    FROM SRPMES901007.WWMESDB.dbo.job
    WHERE act_start_time_utc IS NOT NULL) AS t
    WHERE t.new_state = 4 AND t.last_state <> 4

    UPDATE period
    SET end_time = (SELECT MIN(act_start_time_utc) endtime FROM SRPMES901007.WWMESDB.dbo.job INNER JOIN @PERIOD period ON job.act_start_time_utc > period.start_time AND state_cd <> 4)
    FROM @PERIOD period

    SELECT * FROM @PERIOD ORDER BY start_time ASC

    Database database help question announcement career

  • update temp table with results from sub query (actually it is a function)
    J joost versteegen

    this works! Thanks.

    Database question announcement database

  • update temp table with results from sub query (actually it is a function)
    J joost versteegen

    wow, ok, i will try it first thing in the morning. thanks.

    Database question announcement database

  • update temp table with results from sub query (actually it is a function)
    J joost versteegen

    thanks. i tried it, but i get the error 'Cannot call methods on table'. too bad. my original looks so inefficient, but it will have to do i guess.

    Database question announcement database

  • update temp table with results from sub query (actually it is a function)
    J joost versteegen

    hi, i am having trouble with a query. how can i update a temp table with results from sub query (actually it is a function)? this works:

    UPDATE @TEMP
    SET
    formula\_name = (SELECT name FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no)),
    formula\_version = (SELECT version FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no))
    FROM @TEMP
    

    but i want something like this:

    UPDATE  @TEMP 
    SET formula\_name = r.name, 
    formula\_version = r.version
    FROM (SELECT name, version FROM dbo.fn\_GetFormulaForJob(wo\_id, oper\_id, seq\_no) r
    

    thanks.

    Database question announcement database

  • USB OVER NETWORK
    J joost versteegen

    Create a small service and install it on PC "A", that accepts or sends xml or json messages over http or tcp. Let the C# program on server "B" ask PC "A" to read te USB device. The messages could optionally be encrypted later.

    C# sysadmin csharp winforms help

  • how to access temp table field in subquery?
    J joost versteegen

    thank you, i will try it

    Database help question database tutorial career

  • how to access temp table field in subquery?
    J joost versteegen

    hi, I get an error : The multi-part identifier "e.ent_name" could not be bound. when trying to access a field from a temp table in a sub-query.

    declare @entities table(ent\_id int, ent\_name varchar(50), startDT datetime)
    
    insert into @entities 
    select ent.ent\_id, ent\_name, prod\_job.act\_start\_time\_local
    from job as prod\_job
    inner join ent as ent on prod\_job.run\_ent\_id = ent.parent\_ent\_id
    where prod\_job.wo\_id = 'B.100077779'
    
    select \* from @entities -- so far so good
    
    select \* from @entities as e 
    inner join 
    (
    	select top(1) act\_finish\_time\_local, oper\_id from job as cleaningJob
    	where cleaningJob.oper\_id like '%'+ e.ent\_name +'%' ----> error
    	order by act\_finish\_time\_local desc
    ) 
    as j on j.act\_finish\_time\_local < e.startDT
    

    how can i fix this? Thanks

    Database help question database tutorial career

  • is there a way to define the signature of a delegate in an interface without defining the signature twice?
    J joost versteegen

    Oke, that makes sense. Thank you.

    C# question

  • is there a way to define the signature of a delegate in an interface without defining the signature twice?
    J joost versteegen

    Thank you for the reply. It is not what I mean; In your solution the ICounterprocessor can raise the event, but it's meant to react on the event, like an observer. Maibe I better forget the whole event stuff, and change to Observer like structure?

    C# question

  • is there a way to define the signature of a delegate in an interface without defining the signature twice?
    J joost versteegen

    Hi, I have the following code:

    class Program
    {
    static void Main(string[] args)
    {
    ProductCounterWatcher w = new ProductCounterWatcher();
    ICounterProcessor p = new PrdStandStillDetector();
    w.OnCounterChanged += p.CounterChanged;
    w.Detect();
    w.OnCounterChanged -= p.CounterChanged;
    }
    }
    //-----------------------------------------------------------------------------------
    public class ProductCounter
    {
    public int Value { get; set; }
    public DateTime Timestamp { get; set; }

    public override string ToString()
    {
      return string.Format("\[ProductCounter:{0},{1}\]", Timestamp, Value);
    }
    

    }
    //-----------------------------------------------------------------------------------
    public interface ICounterProcessor
    {
    void CounterChanged(object source, CounterChangedEventArgs e); // <<<----
    }
    //-----------------------------------------------------------------------------------

    public delegate void CounterChangedHandler(object source, CounterChangedEventArgs e); // <<<----
    //-----------------------------------------------------------------------------------

    public class CounterChangedEventArgs : EventArgs
    {
    public ProductCounter Counter { get; set; }

    public CounterChangedEventArgs(ProductCounter counter)
    {
      this.Counter = counter;
    }
    

    }
    //-----------------------------------------------------------------------------------
    public class PrdStandStillDetector : ICounterProcessor
    {
    public void CounterChanged(object source, CounterChangedEventArgs e)
    {
    }
    }
    //-----------------------------------------------------------------------------------
    public class ProductCounterWatcher
    {
    public CounterChangedHandler OnCounterChanged;

    public void Detect()
    {
      if (OnCounterChanged != null) OnCounterChanged(this, new CounterChangedEventArgs(new ProductCounter() { Timestamp = DateTime.Now, Value = 1 }));
    }
    

    }

    I have to define the procedure signature twice (see <<<--- mark). is there a way to avoid this and thus only define the signature once? Thanks.

    C# question

  • System.IndexOutOfRangeException
    J joost versteegen

    very interesting, thanks a lot!

    C# database help question

  • System.IndexOutOfRangeException
    J joost versteegen

    ok, thanks. I will try.

    C# database help question

  • System.IndexOutOfRangeException
    J joost versteegen

    they are all framework, except maybe OnRowEnter, but the breakpoint i set did not get hit.

    private void dataGridViewDefects_RowEnter(object sender, DataGridViewCellEventArgs e)
    {
    try
    {
    if (_SelectedDrum != null && e.RowIndex > -1) _SelectedDefect = _SelectedDrum.Defects[e.RowIndex];
    }
    catch (Exception exc)
    {
    Logger.LogException(exc);
    }
    }

    the application crashes in the line:

    Application.Run(new TwisterForm());

    C# database help question

  • System.IndexOutOfRangeException
    J joost versteegen

    yes i have, but it does not reach the breakpoint.

    private void dataGridViewDefects\_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
    }
    

    in fact i have the following event procedures, but none of them is the source of the problem (breakpoint not hit when the error occures)

      this.dataGridViewDefects.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridViewDefects\_CellMouseClick);
      this.dataGridViewDefects.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridViewDefects\_CellMouseDoubleClick);
      this.dataGridViewDefects.RowEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridViewDefects\_RowEnter);
      this.dataGridViewDefects.Enter += new System.EventHandler(this.dataGridViewDefects\_Enter);
      this.dataGridViewDefects.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridViewDefects\_KeyDown);
      this.dataGridViewDefects.Leave += new System.EventHandler(this.dataGridViewDefects\_Leave);
    
    C# database help question

  • System.IndexOutOfRangeException
    J joost versteegen

    Hi, I have a weird problem, hopefully someone can shine a light on it? The user gets a list of defects on a product from the database. I put them in a List, like so:

    while (rdr.Read())
    {
    DrumDefect defect = new DrumDefect()
    {
    AVI_Defect = new AVIDefect()
    {
    SequenceNumber = (rdr["AVIProdUDefectSeqNr"] != DBNull.Value) ? int.Parse(rdr["AVIProdUDefectSeqNr"].ToString()) : (rdr["MVIProdUDefectSeqNr"] != DBNull.Value) ? int.Parse(rdr["MVIProdUDefectSeqNr"].ToString()) : -1,
    Code = (rdr["AVIProdUDefectCode"] == DBNull.Value) ? "# 0" : rdr["AVIProdUDefectCode"].ToString(),
    Name = (rdr["AVIProdUDefectName"] == DBNull.Value) ? "NODEFECT" : rdr["AVIProdUDefectName"].ToString(),
    Severity = (rdr["AVISeverityLevelID"] == DBNull.Value) ? DefectSeverity.NODEFECT : (DefectSeverity)int.Parse(rdr["AVISeverityLevelID"].ToString())
    },
    MVI_Defect = new Defect()
    {
    Code = (rdr["MVIProdUDefectCode"] == DBNull.Value) ? "# 0" : rdr["MVIProdUDefectCode"].ToString(),
    Name = (rdr["MVIProdUDefectName"] == DBNull.Value) ? "NODEFECT" : rdr["MVIProdUDefectName"].ToString(),
    Severity = (rdr["MVISeverityLevelID"] == DBNull.Value) ? DefectSeverity.NODEFECT : (DefectSeverity)int.Parse(rdr["MVISeverityLevelID"].ToString())
    },
    FVI_Defect = new Defect()
    };
    list.Add(defect);
    }

    Then I import them in a datagridview like so:

        \_SelectedDrum.Defects = database.GetList();
    
        dataGridViewDefects.DataSource = null;
        dataGridViewDefects.DataSource = \_SelectedDrum.Defects;
        dataGridViewDefects.Refresh();
    

    The user can add a defect, so I add one like this:

     DrumDefect defect = new DrumDefect()
     { 
        AVI\_Defect = new AVIDefect()
        {
          SequenceNumber = -1,
          Code = "# 0",
          Name = "NODEFECT",
          Severity = DefectSeverity.NODEFECT
        },
        MVI\_Defect = new Defect()
        {
          Code = "# 0",
          Name = "NODEFECT",
          Severity = DefectSeverity.NODEFECT
        },
        FVI\_Defect = new Defect()
      };
      \_SelectedDrum.Defects.Add(defect);
    

    it all works fine, except when the database list is empty, the user adds a def

    C# database help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups