Exemplo n.º 1
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];
                    CollapsePillars collapsePillars = CollapsePillars.FindOneByCollapsePillarsName(collapsePillarsName);
                    if (collapsePillars == null)
                    {
                        collapsePillars = new CollapsePillars
                        {
                            Xtype               = "0",
                            BindingId           = IDGenerator.NewBindingID(),
                            CollapsePillarsName = collapsePillarsName
                        };
                    }
                    else
                    {
                        collapsePillars.CollapsePillarsName = collapsePillarsName;
                    }

                    var collapsePillarsPoints = new List <CollapsePillarsPoint>();
                    //添加关键点
                    for (int i = 0; i < file.Length - 1; i++)
                    {
                        var collapsePillarsPoint = new CollapsePillarsPoint
                        {
                            CoordinateX     = Convert.ToDouble(file[i].Split(',')[0]),
                            CoordinateY     = Convert.ToDouble(file[i].Split(',')[1]),
                            CoordinateZ     = 0.0,
                            BindingId       = IDGenerator.NewBindingID(),
                            CollapsePillars = collapsePillars
                        };
                        collapsePillarsPoints.Add(collapsePillarsPoint);
                    }
                    collapsePillars.CollapsePillarsPoints = collapsePillarsPoints;
                    collapsePillars.Save();
                    ModifyXlz(collapsePillarsPoints, collapsePillars.Id.ToString());
                    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;
                }
            }
            SendMessengToServer();
            Alert.alert("导入成功!");
        }
Exemplo n.º 2
0
        /// <summary>
        ///     提交按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            CollapsePillars collapsePillars = CollapsePillars.FindOneByCollapsePillarsName(txtCollapsePillarsName.Text);

            if (collapsePillars == null)
            {
                collapsePillars = new CollapsePillars
                {
                    CollapsePillarsName = txtCollapsePillarsName.Text,
                    Discribe            = txtDescribe.Text,
                    Xtype     = radioBtnX.Checked ? "0" : "1",
                    BindingId = IDGenerator.NewBindingID()
                };
            }
            else
            {
                collapsePillars.CollapsePillarsName = txtCollapsePillarsName.Text;
                collapsePillars.Discribe            = txtDescribe.Text;
                collapsePillars.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);
                }
            }

            //验证
            if (!Check())
            {
                DialogResult = DialogResult.None;
                return;
            }

            var collapsePillarsPoints = new List <CollapsePillarsPoint>();

            //添加关键点
            for (int i = 0; i < dgrdvCoordinate.RowCount - 1; i++)
            {
                var collapsePillarsPoint = new CollapsePillarsPoint
                {
                    CoordinateX     = Convert.ToDouble(dgrdvCoordinate[0, i].Value),
                    CoordinateY     = Convert.ToDouble(dgrdvCoordinate[1, i].Value),
                    CoordinateZ     = Convert.ToDouble(dgrdvCoordinate[2, i].Value),
                    BindingId       = IDGenerator.NewBindingID(),
                    CollapsePillars = collapsePillars
                };
                collapsePillarsPoints.Add(collapsePillarsPoint);
            }
            collapsePillars.CollapsePillarsPoints = collapsePillarsPoints;
            collapsePillars.Save();
            ModifyXlz(collapsePillarsPoints, collapsePillars.Id.ToString());
            SendMessengToServer();
            DialogResult = DialogResult.OK;
        }