Пример #1
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            GraphOpt.IsTopologyInit = false;

            string suffixName     = "", //新图形后缀名
                   SGraphFileName = "", //原图形路径及图形名称
                   GraphFileName  = "", //新图形名称
                   distFileName   = ""; //新图形路径及图形名称

            try
            {
                if (textGraphName.Text.Length < 1)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("请输入图形文件名称!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (comboBoxType.SelectedItem == null)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("请选择图形类型!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (comboBoxType.SelectedItem.ToString() == "动态图")
                {
                    if (textFileName.Text.Length < 1)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("请选择图形文件底图!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                //if (comboBoxType.SelectedItem.ToString() == "SVG组态图")
                //{
                //    if (textSCGFileName.Text.Length < 1)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show("请输入本地目录SVG底图文件名称!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //        return;
                //    }
                //}
                short Type = 0;
                if (comboBoxType.SelectedItem.ToString() == "拓扑图")
                {
                    Type = 1;
                }
                if (comboBoxType.SelectedItem.ToString() == "SVG组态图")
                {
                    Type = 3;
                }

                suffixName     = textFileName.Text.Substring(textFileName.Text.LastIndexOf(".") + 1, textFileName.Text.Length - textFileName.Text.LastIndexOf(".") - 1);
                SGraphFileName = Application.StartupPath + "\\mx\\dwg\\" + textGraphName.Text;
                if (comboBoxType.SelectedItem.ToString() == "动态图")
                {
                    if (textGraphName.Text.Contains("."))
                    {
                        GraphFileName = textGraphName.Text.Substring(0, textGraphName.Text.LastIndexOf('.')) + "." + suffixName;
                    }
                    else//未输入后缀名时,直接用输入的名称+后缀名
                    {
                        GraphFileName = textGraphName.Text + "." + suffixName;
                    }
                }
                else
                {
                    GraphFileName = textGraphName.Text;
                }
                distFileName = Application.StartupPath + "\\mx\\dwg\\" + GraphFileName;

                //图形保存到数据库中
                if (this.Text == "新建图形")
                {
                    //修改应急联动图形
                    if (!string.IsNullOrWhiteSpace(this.EmergencyLinkageGraphicsId))
                    {
                        GraphOpt.UpdateEmergencyLinkageGraphicsRequest(this.EmergencyLinkageGraphicsId);
                    }
                    if (Type == 0)
                    {
                        //查找目录下是否具有同名文件
                        if (File.Exists(distFileName))
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("当前图形已存在,请进行编辑操作!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        string bz3 = "0", bz4 = "0";
                        if (this.checkEdit2.Checked == true && this.checkEdit2.Text == "通风系统默认图形")
                        {
                            bz3 = "1";
                            bz4 = "1";//通风系统图与应急联动图同时选择  20171221
                            if (!string.IsNullOrWhiteSpace(this.SysetemDefaultGraphicsId))
                            {
                                GraphOpt.UpdateSystemDefaultGraphics("0", this.SysetemDefaultGraphicsId);
                            }
                        }
                        else if (this.checkEdit2.Checked == true && this.checkEdit2.Text == "拓扑定义默认图形")
                        {
                            bz3 = "2";
                            if (!string.IsNullOrWhiteSpace(this.SysetemDefaultGraphicsId))
                            {
                                GraphOpt.UpdateSystemDefaultGraphics("0", this.SysetemDefaultGraphicsId);
                            }
                        }

                        GraphOpt.GraphInsert(GraphFileName, Type, bz3, bz4, File.ReadAllBytes(textFileName.Text));
                    }
                    else
                    {
                        //查找数据库中是否有相同图形
                        GraphicsbaseinfInfo GraphicsbaseinfDTO_ = GraphOpt.getGraphicDto(GraphFileName);
                        if (GraphicsbaseinfDTO_ != null)
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("当前图形已存在,请进行编辑操作!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        else
                        {
                            if (comboBoxType.SelectedItem.ToString() == "SVG组态图")
                            {
                                string bz4 = "0";
                                //if (this.checkEdit3.Checked == true)
                                //{
                                //    bz4 = "1";
                                //}
                                //else if (this.checkEdit4.Checked == true)
                                //{
                                //    bz4 = "0";
                                //}
                                //GraphOpt.GraphInsert(GraphFileName, Type, bz4, null, "SVGLoad.html", textSCGFileName.Text);
                            }
                            else
                            {
                                string bz3 = "0", bz4 = "0";
                                if (this.checkEdit2.Checked == true && this.checkEdit2.Text == "通风系统默认图形")
                                {
                                    if (!string.IsNullOrWhiteSpace(this.SysetemDefaultGraphicsId))
                                    {
                                        GraphOpt.UpdateSystemDefaultGraphics("0", this.SysetemDefaultGraphicsId);
                                    }
                                    bz3 = "1";
                                    bz4 = "1";//通风系统图与应急联动图同时选择  20171221
                                }
                                else if (this.checkEdit2.Checked == true && this.checkEdit2.Text == "拓扑定义默认图形")
                                {
                                    if (!string.IsNullOrWhiteSpace(this.SysetemDefaultGraphicsId))
                                    {
                                        GraphOpt.UpdateSystemDefaultGraphics("0", this.SysetemDefaultGraphicsId);
                                    }
                                    bz3 = "2";
                                }
                                //if (this.checkEdit3.Checked == true)
                                //{
                                //    bz4 = "1";
                                //}
                                //else if (this.checkEdit4.Checked == true)
                                //{
                                //    bz4 = "0";
                                //}
                                GraphOpt.IsTopologyInit = true;
                                GraphOpt.GraphInsert(GraphFileName, Type, bz3, bz4, null);
                            }
                        }
                    }
                }
                else if (this.Text == "图形编辑")
                {
                    if (SGraphFileName != textFileName.Text)
                    {
                        //删除原来的图形
                        if (File.Exists(SGraphFileName))
                        {
                            File.Delete(SGraphFileName);
                        }
                    }
                    if (comboBoxType.SelectedItem.ToString() == "SVG组态图")
                    {
                        GraphOpt.GraphUpdate(textGraphName.Text, GraphFileName, Type, File.ReadAllBytes(textFileName.Text), "SVGLoad.html", textGraphName.Text);
                    }
                    else
                    {
                        string bz3 = "0", bz4 = "0";
                        if (this.checkEdit2.Checked == true && this.checkEdit2.Text == "通风系统默认图形")
                        {
                            bz3 = "1";
                            bz4 = "1";//通风系统图与应急联动图同时选择  20171221
                        }
                        else if (this.checkEdit2.Checked == true && this.checkEdit2.Text == "拓扑定义默认图形")
                        {
                            bz3 = "2";
                        }
                        //if (this.checkEdit3.Checked == true)
                        //{
                        //    bz4 = "1";
                        //}
                        //else if (this.checkEdit4.Checked == true)
                        //{
                        //    bz4 = "0";
                        //}

                        if (Type == 0)
                        {
                            //更新动态图形
                            GraphOpt.GraphUpdate(textGraphName.Text, GraphFileName, Type, bz3, bz4, File.ReadAllBytes(textFileName.Text));
                        }
                        else if (Type == 1)
                        {
                            //修改拓扑图形
                            GraphOpt.GraphUpdate(textGraphName.Text, GraphFileName, Type, bz3, bz4, null);
                        }
                    }
                }
                if (Type == 0)//只有动态图才进行底图保存
                {
                    if (SGraphFileName != textFileName.Text)
                    {
                        //保存本地
                        File.Copy(textFileName.Text, distFileName);
                    }
                }



                DevExpress.XtraEditors.XtraMessageBox.Show("系统默认图形上传成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                LogHelper.Error("GraphicsAdd_simpleButton2_Click" + ex.Message + ex.StackTrace);
            }
        }