在NotePad的表中获取最后记录的空值 [英] Getting Empty Value for Last Record in Table in NotePad

查看:100
本文介绍了在NotePad的表中获取最后记录的空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的解决方案。但是我遇到了一些问题。问题描述:上面是记事本格式。我有2个表。第一张表将保存订单信息。第二张表将保存表值信息。我得到完整的信息,但每个表值的最后记录我得到空。请帮助我。



hi , here is my solution.But iam facing some problem in this. Problem Descripption : above is the Notepad format.i have 2 table . 1st table wil save Order info. 2nd table wil saves Table values info. iam getting complete info but last record for every table value iam getting Empty.Please help me on this.

------------------------------------------------------------------------------------------------------------------------------------
       | From          | To            |                                                         |                    |
Wrh    | Zone          | Zone          | Item                                               Rev. | Quantity (Str.Un.) |    Picked
Miss.  | Location      | Location      | Description/Remark              Inventory Date     Pack.|                    |   Quantity
Seq.   | Row/Level/Bin | Row/Level/Bin | Lot                                                Def. |                    |
-------+---------------+---------------+---------------------------------------------------------+--------------------+-------------
Run             : BGLKAMAN                                                     Delivery Date: 23122013 00:00
Order Origin    : Sales
Order           : NOK000017
Ship To Type    : Business Partner
Ship To Code    : BPS000191
Position Number :   70
859001 |              |               |          NOK-00807G4                                     |                    |
   1   |BULK          | STAGE         | CARE A COVER & TOUCH ASSY        20-12-13 10:21:48       |      8000.0000 ea  |
     5 |              |               |                                                          |                    |
       |              |               |                                                          |                    |
Position Number :  100
859001 |              |               |          NOK-00808W4                                     |                    |
   1   |BULK          | STAGE         | CARE WINDOW FRAME ASSEMBL        20-12-13 10:22:09       |     11000.0000 ea  |
    10 |              |               |                                                          |                    |
       |              |               |                                                          |                    |
Position Number :  110
859001 |              |               |          NOK-00809K8                                     |                    |
   1   |BULK          | STAGE         | CARE DISPLAY MODULE ASSY         20-12-13 10:22:33       |     12000.0000 ea  |
    15 |              |               |                                                          |                    |
       |              |               |                                                          |                    |
Position Number :  120
859001 |              |               |          NOK-00809K9                                     |                    |
   1   |BULK          | STAGE         | CARE USB PWB ACF ASSEMBLY        20-12-13 10:22:51       |     13000.0000 ea  |
    20 |              |               |                                                          |                    |
       |              |               |                                                          |                    |


Reprint                                                               CHECKED      :

Date   : 20-12-13 [11:06, Asi]                           PICKING LIST BY ORDER NUMBER                               Page      :    2
Company   :  859

------------------------------------------------------------------------------------------------------------------------------------
       | From          | To            |                                                         |                    |
Wrh    | Zone          | Zone          | Item                                               Rev. | Quantity (Str.Un.) |    Picked
Miss.  | Location      | Location      | Description/Remark              Inventory Date     Pack.|                    |   Quantity
Seq.   | Row/Level/Bin | Row/Level/Bin | Lot                                                Def. |                    |
-------+---------------+---------------+---------------------------------------------------------+--------------------+-------------
Run             : BGLKAMAN                                                     Delivery Date: 24122013 00:00
Order Origin    : Sales
Order           : NOK000029
Ship To Type    : Business Partner
Ship To Code    : BPS000191
Position Number :   20
859001 |              |               |          NOK-00801J8                                     |                    |
   1   |BULK          | STAGE         | CARE A COVER AND TOUCH WI        20-12-13 10:23:33       |      2000.0000 ea  |
    25 |              |               |                                                          |                    |
       |              |               |                                                          |                    |
Position Number :   50
859001 |              |               |          NOK-00801S3                                     |                    |
   1   |BULK          | STAGE         | Care A COVER ASSY NCVM GO        20-12-13 10:21:28       |      2000.0000 ea  |
    30 |              |               |                                                          |                    |
       |              |               |                                                          |                    |
Position Number :   60
859001 |              |               |          NOK-00807G4                                     |                    |
   1   |BULK          | STAGE         | CARE A COVER & TOUCH ASSY        20-12-13 10:21:48       |      1000.0000 ea  |
    35 |              |               |                                                          |                    |
       |              |               |                                                          |                    |
Position Number :   70
859001 |              |               |          NOK-00808W4                                     |                    |
   1   |BULK          | STAGE         | CARE WINDOW FRAME ASSEMBL        20-12-13 10:22:09       |      2000.0000 ea  |
    40 |              |               |                                                          |                    |
       |              |               |                                                          |                    |
Position Number :   80
859001 |              |               |          NOK-00809K8                                     |                    |
   1   |BULK          | STAGE         | CARE DISPLAY MODULE ASSY         20-12-13 10:22:33       |      3000.0000 ea  |
    45 |              |               |                                                          |                    |
       |              |               |                                                          |                    |
Position Number :   90
859001 |              |               |          NOK-00809K9                                     |                    |
   1   |BULK          | STAGE         | CARE USB PWB ACF ASSEMBLY        20-12-13 10:22:51       |      3000.0000 ea  |
    50 |              |               |                                                          |                    |
       |              |               |                                                          |                    |










private void button1_Click(object sender, EventArgs e)
{
   var record = new RootModel();
   record.RootID = Guid.NewGuid().ToString();
   var table = new RootCollectionModel();
   try
   {
      OpenFileDialog fd = new OpenFileDialog();
      fd.Multiselect = false;
      fd.Filter = "Text File|*.txt";
      DialogResult result = fd.ShowDialog();
      if (result == System.Windows.Forms.DialogResult.OK)
      {
         bool start = false;
         string ExtraData = "";
         var lines = File.ReadAllLines(fd.FileName);
         if (lines != null)
         {
            foreach (string fullline in lines)
            {
               var line = fullline.Trim();
               if (line != "")
               {
                  if (line.StartsWith("Run"))
                  {
                     var str = line.Split(new string[] { "     " }, StringSplitOptions.RemoveEmptyEntries)[1];
                     record.Run = ReturnValue(str);
                  }
                  else if (line.StartsWith("Order Origin"))
                  {
                     record.Order_Origin = ReturnValue(line);
                  }
                  else if (line.StartsWith("Order"))
                  {
                     record.Order = ReturnValue(line);
                  }
                  else if (line.StartsWith("Ship To Type"))
                  {
                     record.Ship_To_Type = ReturnValue(line);
                  }
                  else if (line.StartsWith("Ship To Code"))
                  {
                     record.Ship_To_Code = ReturnValue(line);
                  }
                  else if (line.StartsWith("Position Number"))
                  {
                     ExtraData = ExtraData.Trim();
                     if (ExtraData != "")
                     {
                        record.PositionData[record.PositionData.Count - 1].ExtraData = ExtraData.Split(new string[] { "|"}, StringSplitOptions.None).Select(s => s.Trim()).ToList();
                        ExtraData = "";
                     }
                     record.PositionData.Add(new DataModel()
                        {
                           DataID = Guid.NewGuid().ToString(),
                           RootID = record.RootID,
                           Position_Number = ReturnValue(line),
                        });

                     start = true;
                  }
                  else if (line.StartsWith("Reprint"))
                  {
                     table.RootModels.Add(record);
                     record = new RootModel();
                     record.RootID = Guid.NewGuid().ToString();
                     start = false;
                     ExtraData = "";
                  }
                  else
                  {
                     if (start)
                     {
                        ExtraData += line;
                     }
                  }
               }
            }
         }
      }
      //   Check the table object here for the total captured information from the notepad.
      // U can write the desired coding to save the data into the database.
      string query = "";
      foreach (RootModel root in table.RootModels)
      {
         query = "insert into OrderInfo(ID,Run,Order_Origin,Order_Number,Ship_To_Type,Ship_To_Code) values('"
                        + root.RootID + "','" + root.Run + "','" + root.Order_Origin + "','" + root.Order + "','" + root.Ship_To_Type + "','" + root.Ship_To_Code + "')";
         //insert into db
         DM.ExecuteNonQuery(query);

         foreach (DataModel data in root.PositionData)
         {
            query = "insert into OrderList(Id,OrderID,Position_Number,ExtraData0,ExtraData1,ExtraData2) values('"
                            + data.DataID + "','" + data.RootID + "','" + data.Position_Number + "','" + data.ExtraData[0] + "','" + data.ExtraData[1] + "','" + data.ExtraData[2] + "')";
            // +data.DataID + "','" + data.RootID + "','" + data.Position_Number  + "')";
            //insert into db
            DM.ExecuteNonQuery(query);
         }
      }
   }
   catch
   {
   }
}

private string ReturnValue(string line)
{
   try
   {
      var str = line.Split(new string[] { ":" }, StringSplitOptions.None)[1].Trim();
      return str;
   }
   catch
   {
      return "";
   }
}

推荐答案

This is a \"Text File\", not a \"Notepad\". One is a file, the other is an application that edits text files. There is no such thing as a \"Notepad format\". Don’t use the terms interchangeably.



With a cursory glance at your code, you check to see if the line is blank:

This is a "Text File", not a "Notepad". One is a file, the other is an application that edits text files. There is no such thing as a "Notepad format". Don't use the terms interchangeably.

With a cursory glance at your code, you check to see if the line is blank:
if (line != "")



But you don’t check to see if the line contains nothing but white space, like tabs and space characters. That line should read


But you don't check to see if the line contains nothing but white space, like tabs and space characters. That line should read

if (!string.IsNullOrWhiteSpace(line))


这篇关于在NotePad的表中获取最后记录的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆