Beispiel #1
0
        public IModel GetModelByWhereSql(string whereSql)
        {
            string sql =
                "select LFUSSId,ModuleTreeId,Length,Width," +
                "SuNo,SuDia,SuDis,SidePanel,Japan from LFUSS";

            sql += whereSql;
            SqlDataReader objReader = SQLHelper.GetReader(sql);
            LFUSS         objModel  = null;

            if (objReader.Read())
            {
                objModel = new LFUSS()
                {
                    LFUSSId      = Convert.ToInt32(objReader["LFUSSId"]),
                    ModuleTreeId = Convert.ToInt32(objReader["ModuleTreeId"]),
                    //最好不要用=null去判断,提示类型转换错误
                    Length = objReader["Length"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["Length"]),
                    Width  = objReader["Width"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["Width"]),
                    SuNo   = objReader["SuNo"].ToString().Length == 0 ? 0 : Convert.ToInt32(objReader["SuNo"]),
                    SuDia  = objReader["SuDia"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["SuDia"]),
                    SuDis  = objReader["SuDis"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["SuDis"]),

                    SidePanel = objReader["SidePanel"].ToString().Length == 0 ? "" : objReader["SidePanel"].ToString(),
                    Japan     = objReader["Japan"].ToString().Length == 0 ? "" : objReader["Japan"].ToString()
                };
            }
            objReader.Close();
            return(objModel);
        }
Beispiel #2
0
        public int EditModel(IModel model)
        {
            LFUSS objModel = (LFUSS)model;
            //编写带参数的SQL语句
            StringBuilder sqlBuilder = new StringBuilder();

            sqlBuilder.Append("Update LFUSS set Length=@Length,Width=@Width,SuNo=@SuNo,SuDia=@SuDia,SuDis=@SuDis,");
            sqlBuilder.Append("SidePanel=@SidePanel,Japan=@Japan where LFUSSId=@LFUSSId");
            //定义参数数组
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@Length", objModel.Length),
                new SqlParameter("@Width", objModel.Width),
                new SqlParameter("@SuNo", objModel.SuNo),
                new SqlParameter("@SuDia", objModel.SuDia),
                new SqlParameter("@SuDis", objModel.SuDis),
                new SqlParameter("@SidePanel", objModel.SidePanel),
                new SqlParameter("@Japan", objModel.Japan),
                new SqlParameter("@LFUSSId", objModel.LFUSSId)
            };
            try
            {
                return(SQLHelper.Update(sqlBuilder.ToString(), param));
            }
            catch (SqlException ex)
            {
                throw new Exception("数据库操作出现异常:" + ex.Message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        public FrmLFUSS(Drawing drawing, ModuleTree tree) : this()
        {
            objLFUSS = (LFUSS)objLFUSSService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString());
            if (objLFUSS == null)
            {
                return;
            }
            this.Text = drawing.ODPNo + " / Item: " + drawing.Item + " / Module: " + tree.Module + " - " + tree.CategoryName;
            Category objCategory = objCategoryService.GetCategoryByCategoryId(tree.CategoryId.ToString());

            pbModelImage.Image = objCategory.ModelImage.Length == 0
                ? Image.FromFile("NoPic.png")
                : (Image) new SerializeObjectToString().DeserializeObject(objCategory.ModelImage);
            FillData();
        }
Beispiel #4
0
        private void btnEditData_Click(object sender, EventArgs e)
        {
            #region 数据验证
            //必填项目
            if (pbModelImage.Tag.ToString().Length == 0)
            {
                return;
            }
            if (!DataValidate.IsDecimal(txtLength.Text.Trim()) || Convert.ToDecimal(txtLength.Text.Trim()) < 200m)
            {
                MessageBox.Show("请认真检查散流器长度", "提示信息");
                txtLength.Focus();
                txtLength.SelectAll();
                return;
            }
            if (!DataValidate.IsDecimal(txtWidth.Text.Trim()) || Convert.ToDecimal(txtWidth.Text.Trim()) < 200m)
            {
                MessageBox.Show("请认真检查散流器宽度", "提示信息");
                txtWidth.Focus();
                txtWidth.SelectAll();
                return;
            }
            if (cobSidePanel.SelectedIndex == -1)
            {
                MessageBox.Show("请选择散流器侧板", "提示信息");
                cobSidePanel.Focus();
                return;
            }
            if (cobSuDia.SelectedIndex == -1)
            {
                MessageBox.Show("请选择均流桶直径", "提示信息");
                cobSuDia.Focus();
                return;
            }
            if (cobSuNo.SelectedIndex == -1)
            {
                MessageBox.Show("请选择均流桶数量", "提示信息");
                cobSuNo.Focus();
                return;
            }
            else if (cobSuNo.SelectedIndex > 0 && (!DataValidate.IsDecimal(txtSuDis.Text.Trim()) || Convert.ToDecimal(txtSuDis.Text.Trim()) < 250m))
            {
                MessageBox.Show("请认真检查均流桶间距", "提示信息");
                txtSuDis.Focus();
                txtSuDis.SelectAll();
                return;
            }
            if (cobJapan.SelectedIndex == -1)
            {
                MessageBox.Show("请选择是否为日本项目", "提示信息");
                cobJapan.Focus();
                return;
            }
            #endregion
            //封装对象
            LFUSS objLFUSS = new LFUSS()
            {
                LFUSSId   = Convert.ToInt32(pbModelImage.Tag),
                SidePanel = cobSidePanel.Text,

                SuNo  = Convert.ToInt32(cobSuNo.Text),
                SuDia = Convert.ToDecimal(cobSuDia.Text.Trim()),
                Japan = cobJapan.Text,

                Length = Convert.ToDecimal(txtLength.Text.Trim()),
                Width  = Convert.ToDecimal(txtWidth.Text.Trim()),
                SuDis  = Convert.ToDecimal(txtSuDis.Text.Trim())
            };
            //提交修改
            try
            {
                if (objLFUSSService.EditModel(objLFUSS) == 1)
                {
                    MessageBox.Show("制图数据修改成功", "提示信息");
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #5
0
        public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath)
        {
            //创建项目模型存放地址
            string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName;

            if (!Directory.Exists(itemPath))
            {
                Directory.CreateDirectory(itemPath);
            }
            else
            {
                DialogResult result =
                    MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息",
                                    MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return;
                }
            }
            //Pack的后缀
            string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6);
            //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack
            //packango后需要接收打包完成的地址,参数为后缀
            string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm";

            if (!File.Exists(packedAssyPath))
            {
                packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath);
            }

            //查询参数
            LFUSS item = (LFUSS)objLFUSSService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString());

            swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令
            int warnings = 0;
            int errors   = 0;

            suffix = "_" + suffix;//后缀
            ModelDoc2         swModel = default(ModelDoc2);
            ModelDoc2         swPart  = default(ModelDoc2);
            AssemblyDoc       swAssy  = default(AssemblyDoc);
            Component2        swComp;
            Feature           swFeat        = default(Feature);
            object            configNames   = null;
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            bool   status     = false;
            string compReName = string.Empty;

            //打开Pack后的模型
            swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY,
                                     (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2;
            swAssy = swModel as AssemblyDoc;                                                  //装配体
            string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称

            swModelDocExt = (ModelDocExtension)swModel.Extension;
            //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错
            swModel.ForceRebuild3(true);
            //TopOnly参数设置成true,只重建顶层,不重建零件内部

            /*注意SolidWorks单位是m,计算是应当/1000m
             * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了
             * (int)不进行四舍五入,Convert.ToInt32会四舍五入
             */
            //-----------计算中间值,----------
            decimal lfuPanel = 0m;

            if (item.SidePanel == "NO")
            {
                lfuPanel = item.Length - 1m;
            }
            else if (item.SidePanel == "BOTH")
            {
                lfuPanel = item.Length - 7m;
            }
            else
            {
                lfuPanel = item.Length - 4m;
            }

            try
            {
                //----------Top Level----------
                if (item.SidePanel == "MIDDLE" || item.SidePanel == "NO")
                {
                    swModel.Parameter("D1@Distance6").SystemValue = 0.5m / 1000m;
                }
                else
                {
                    swModel.Parameter("D1@Distance6").SystemValue = 3.5m / 1000m;
                }

                //----------散流器主体----------
                //重命名装配体内部
                compReName = "FNCA0016[LFUSS-" + tree.Module + "]{" + (int)item.Length + "}(" + (int)item.Width + ")";
                status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCA0016-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                if (status)
                {
                    swModelDocExt.RenameDocument(compReName);
                }
                swModel.ClearSelection2(true);
                status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                swModel.ClearSelection2(true);
                if (status)
                {
                    swComp = swAssy.GetComponentByName(compReName + "-1");
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Base-Flange1").SystemValue = item.Length / 1000m;
                    swPart.Parameter("D1@Sketch1").SystemValue      = item.Width / 2000m;
                    swPart.Parameter("D3@Sketch2").SystemValue      = item.SuDia / 1000m;
                    swPart.Parameter("D2@Sketch2").SystemValue      =
                        (item.SuDis * (item.SuNo / 2m - 1m) + item.SuDis / 2m) / 1000m;
                    if (item.SuNo < 2)
                    {
                        swFeat = swComp.FeatureByName("LPattern1");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("LPattern1");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D1@LPattern1").SystemValue = item.SuNo;
                        swPart.Parameter("D3@LPattern1").SystemValue = item.SuDis / 1000m;
                    }
                    swFeat = swComp.FeatureByName("Cut-Extrude12");
                    if (item.Japan == "YES")
                    {
                        swFeat.SetSuppression2(0, 2, configNames);                      //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(1, 2, configNames);  //参数1:1解压,0压缩
                    }
                }
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2900600019-1"));
                swPart = swComp.GetModelDoc2();//打开零件
                swPart.Parameter("D1@Boss-Extrude1").SystemValue = (item.Length - 7m) / 1000m;

                //----------散流器网控板----------
                //重命名装配体内部
                compReName = "FNCA0018[LFUP-" + tree.Module + "]{" + (int)lfuPanel + "}(" + (int)(item.Width - 38m) + ")";
                status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCA0018[LFUP-]{}()-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                if (status)
                {
                    swModelDocExt.RenameDocument(compReName);
                }
                swModel.ClearSelection2(true);
                status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                swModel.ClearSelection2(true);
                if (status)
                {
                    swComp = swAssy.GetComponentByName(compReName + "-1");
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Skizze2").SystemValue = lfuPanel / 1000m;
                    swPart.Parameter("D1@Skizze2").SystemValue = (item.Width - 38m) / 1000m;
                }
                if (item.SidePanel == "NO")
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0017-1"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2900600020-1"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0017-2"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2900600020-2"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0028-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0028-2"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Sketch1").SystemValue = (item.Width / 2m - 1.5m) / 1000m;
                }
                else if (item.SidePanel == "BOTH")
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0017-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Sketch1").SystemValue = (item.Width / 2m - 1.5m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2900600020-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Boss-Extrude1").SystemValue = item.Width / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0017-2"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2900600020-2"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0028-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0028-2"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0017-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Sketch1").SystemValue = (item.Width / 2m - 1.5m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2900600020-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Boss-Extrude1").SystemValue = item.Width / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0017-2"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2900600020-2"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0028-1"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0028-2"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Sketch1").SystemValue = (item.Width / 2m - 1.5m) / 1000m;
                }
                if (item.Japan == "YES")
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern1");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9"));
                    swComp.SetSuppression2(2);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern1");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                }

                swModel.ForceRebuild3(true);    //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
                swModel.Save();                 //保存,很耗时间
                swApp.CloseDoc(packedAssyPath); //关闭,很快
            }
            catch (Exception ex)
            {
                throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
        }