コード例 #1
0
        /// <summary>
        ///     提交按钮
        /// </summary>
        /// <params name="sender"></params>
        /// <params name="e"></params>
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            var collapsePillar =
                CollapsePillar.FindAllByProperty("name", txtCollapsePillarsName.Text).FirstOrDefault();
            if (collapsePillar == null)
            {
                collapsePillar = new CollapsePillar
                {
                    name = txtCollapsePillarsName.Text,
                    discribe = txtDescribe.Text,
                    xtype = radioBtnX.Checked ? "0" : "1",
                    bid = IdGenerator.NewBindingId()
                };
            }
            else
            {
                collapsePillar.name = txtCollapsePillarsName.Text;
                collapsePillar.discribe = txtDescribe.Text;
                collapsePillar.xtype = radioBtnX.Checked ? "0" : "1";
            }

            //实体赋值
            //去除无用空行
            for (int i = 0; i < dgrdvCoordinate.RowCount - 1; i++)
            {
                if (dgrdvCoordinate.Rows[i].Cells[0].Value == null &&
                    dgrdvCoordinate.Rows[i].Cells[1].Value == null &&
                    dgrdvCoordinate.Rows[i].Cells[2].Value == null)
                {
                    dgrdvCoordinate.Rows.RemoveAt(i);
                }
            }
            collapsePillar.Save();

            //添加关键点
            List<CollapsePillarPoint> collapsePillarPoints = new List<CollapsePillarPoint>();
            for (int i = 0; i < dgrdvCoordinate.RowCount - 1; i++)
            {

                var collapsePillarPoint = new CollapsePillarPoint
                {
                    coordinate_x = Convert.ToDouble(dgrdvCoordinate[0, i].Value),
                    coordinate_y = Convert.ToDouble(dgrdvCoordinate[1, i].Value),
                    coordinate_z = Convert.ToDouble(dgrdvCoordinate[2, i].Value),
                    bid = IdGenerator.NewBindingId(),
                    collapse_pillar = collapsePillar
                };
                collapsePillarPoints.Add(collapsePillarPoint);
                collapsePillarPoint.Save();
            }

            ModifyXlz(collapsePillarPoints, collapsePillar.bid);
            DialogResult = DialogResult.OK;
        }
コード例 #2
0
        private void btnMultImport_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                RestoreDirectory = true,
                Filter = @"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*",
                Multiselect = true
            };
            if (ofd.ShowDialog() != DialogResult.OK) return;
            _errorMsg = @"失败文件名:";
            pbCount.Maximum = ofd.FileNames.Length;
            pbCount.Value = 0;
            lblTotal.Text = ofd.FileNames.Length.ToString(CultureInfo.InvariantCulture);
            foreach (var fileName in ofd.FileNames)
            {
                try
                {
                    string[] file = File.ReadAllLines(fileName);
                    var collapsePillarsName =
                        fileName.Substring(fileName.LastIndexOf(@"\", StringComparison.Ordinal) + 1).Split('.')[0];
                    CollapsePillar collapsePillar = CollapsePillar.FindAllByProperty("name", collapsePillarsName).FirstOrDefault();
                    if (collapsePillar == null)
                    {
                        collapsePillar = new CollapsePillar
                        {
                            xtype = "0",
                            bid = IdGenerator.NewBindingId(),
                            name = collapsePillarsName
                        };
                    }
                    else
                    {
                        collapsePillar.name = collapsePillarsName;
                    }

                    var collapsePillarsPoints = new List<CollapsePillarPoint>();
                    //添加关键点
                    for (int i = 0; i < file.Length - 1; i++)
                    {
                        var collapsePillarsPoint = new CollapsePillarPoint
                        {
                            coordinate_x = Convert.ToDouble(file[i].Split(',')[0]),
                            coordinate_y = Convert.ToDouble(file[i].Split(',')[1]),
                            coordinate_z = 0.0,
                            bid = IdGenerator.NewBindingId(),
                            collapse_pillar = collapsePillar
                        };
                        collapsePillarsPoints.Add(collapsePillarsPoint);
                    }
                    collapsePillar.collapse_pillar_points = collapsePillarsPoints;
                    collapsePillar.Save();
                    ModifyXlz(collapsePillarsPoints, collapsePillar.bid);
                    lblSuccessed.Text = lblSuccessed.Text =
                        (Convert.ToInt32(lblSuccessed.Text) + 1).ToString(CultureInfo.InvariantCulture);
                    pbCount.Value++;
                }
                catch (Exception)
                {
                    lblError.Text =
                      (Convert.ToInt32(lblError.Text) + 1).ToString(CultureInfo.InvariantCulture);
                    lblSuccessed.Text =
                        (Convert.ToInt32(lblSuccessed.Text) - 1).ToString(CultureInfo.InvariantCulture);
                    _errorMsg += fileName.Substring(fileName.LastIndexOf(@"\", StringComparison.Ordinal) + 1) + "\n";
                    btnDetails.Enabled = true;
                }

            }
            Alert.AlertMsg("导入成功!");
        }