예제 #1
0
        public bool FromDataGridView(DataGridView datagridview)
        {
            List<string> clmnnames = new List<string>();
            foreach (DataGridViewColumn clmn in datagridview.Columns)
            {
                clmnnames.Add(clmn.Name);
            }

            int partnoindex = 0;
            if (!clmnnames.Contains("件号"))
            {
                System.Windows.Forms.MessageBox.Show("Didn't find part no!");
                return false;
            }
            else
            {
                partnoindex = clmnnames.IndexOf("件号");
                clmnnames.RemoveAt(partnoindex);
            }

            foreach (DataGridViewRow datarow in datagridview.Rows)
            {
                string partno = datarow.Cells[partnoindex].Value as string;
                if(string.IsNullOrEmpty(partno))
                    continue;
                PartObject part = new PartObject(datarow.Cells[partnoindex].Value as string);
                foreach (string clmnname in clmnnames)
                {
                    object cellvalue = datarow.Cells[clmnname].Value;
                    part.PartProperties.Add(clmnname, cellvalue == null ||
                        cellvalue is System.DBNull? string.Empty : cellvalue);
                }
                this.Parts.Add(part);
            }
            return true;
        }
예제 #2
0
 public bool FromMongoDocument(BsonDocument mongodoc)
 {
     SerialNumber = mongodoc.GetValue("MotorSerialNumber").AsString;
     BsonDocument partsdoc = mongodoc.GetValue("Parts").AsBsonDocument;
     foreach (BsonValue partvar in partsdoc.Values)
     {
         BsonDocument partdoc = partvar as BsonDocument;
         PartObject part = new PartObject(string.Empty);
         part.FromMongoDocument(partdoc);
         Parts.Add(part);
     }
     return true;
 }