Exemplo n.º 1
0
        public IModel GetModelByWhereSql(string whereSql)
        {
            string sql =
                "select LKS258HCLId,ModuleTreeId,Length,HCLSide,HCLSideLeft,HCLSideRight from LKS258HCL";

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

            if (objReader.Read())
            {
                objModel = new LKS258HCL()
                {
                    LKS258HCLId  = Convert.ToInt32(objReader["LKS258HCLId"]),
                    ModuleTreeId = Convert.ToInt32(objReader["ModuleTreeId"]),
                    //最好不要用=null去判断,提示类型转换错误
                    Length       = objReader["Length"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["Length"]),
                    HCLSide      = objReader["HCLSide"].ToString().Length == 0 ? "" : objReader["HCLSide"].ToString(),
                    HCLSideLeft  = objReader["HCLSideLeft"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["HCLSideLeft"]),
                    HCLSideRight = objReader["HCLSideRight"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["HCLSideRight"]),
                };
            }
            objReader.Close();
            return(objModel);
        }
Exemplo n.º 2
0
        public int EditModel(IModel model)
        {
            LKS258HCL objModel = (LKS258HCL)model;
            //编写带参数的SQL语句
            StringBuilder sqlBuilder = new StringBuilder();

            sqlBuilder.Append("Update LKS258HCL set Length=@Length,HCLSide=@HCLSide,HCLSideLeft=@HCLSideLeft,HCLSideRight=@HCLSideRight where LKS258HCLId=@LKS258HCLId");
            //定义参数数组
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@Length", objModel.Length),
                new SqlParameter("@HCLSide", objModel.HCLSide),
                new SqlParameter("@HCLSideLeft", objModel.HCLSideLeft),
                new SqlParameter("@HCLSideRight", objModel.HCLSideRight),

                new SqlParameter("@LKS258HCLId", objModel.LKS258HCLId)
            };
            try
            {
                return(SQLHelper.Update(sqlBuilder.ToString(), param));
            }
            catch (SqlException ex)
            {
                throw new Exception("数据库操作出现异常:" + ex.Message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public FrmLKS258HCL(Drawing drawing, ModuleTree tree) : this()
        {
            objLKS258HCL = (LKS258HCL)objLKS258HCLService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString());
            if (objLKS258HCL == 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();
        }
Exemplo n.º 4
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);

            //查询参数
            LKS258HCL item = (LKS258HCL)objLKS258HCLService.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会四舍五入
            */
            //-----------计算中间值,----------

            try
            {
                //----------Top Level----------
                //镀锌板
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0084-1"));
                if (item.HCLSide == "NO") swComp.SetSuppression2(0); //2解压缩,0压缩.
                else swComp.SetSuppression2(2); //2解压缩,0压缩.
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0084-11"));
                if (item.HCLSide == "NO") swComp.SetSuppression2(0); //2解压缩,0压缩.
                else swComp.SetSuppression2(2); //2解压缩,0压缩.
                if (item.HCLSide == "NO")
                {
                    swFeat = swAssy.FeatureByName("LocalLPattern3");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                else if (item.HCLSide == "BOTH")
                {
                    swFeat = swAssy.FeatureByName("LocalLPattern3");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern3").SystemValue = 4;
                }
                else
                {
                    swFeat = swAssy.FeatureByName("LocalLPattern3");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern3").SystemValue = 2;
                }
                //----------HCL侧板----------
                switch (item.HCLSide)
                {
                    case "LEFT":
                        //重命名装配体内部
                        compReName = "FNCE0082[HCLSP-" + tree.Module + "]{" + ((int)item.HCLSideLeft - 3) + "}";
                        status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0082[HCLSP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                        if (status)
                        {
                            swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0082[HCLSP-]{}-1"));
                            swComp.SetSuppression2(2); //2解压缩,0压缩.
                            status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0082[HCLSP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                            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");
                            swComp.SetSuppression2(2); //2解压缩,0压缩.
                            swPart = swComp.GetModelDoc2();//打开零件
                            swPart.Parameter("D1@Sketch1").SystemValue = (item.HCLSideLeft - 3m) / 1000m;
                        }
                        swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0083[HCLSP-]{}-1"));
                        swComp.SetSuppression2(0); //2解压缩,0压缩.
                        break;
                    case "RIGHT":
                        swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0082[HCLSP-]{}-1"));
                        swComp.SetSuppression2(0); //2解压缩,0压缩.
                                                   //重命名装配体内部
                        compReName = "FNCE0083[HCLSP-" + tree.Module + "]{" + ((int)item.HCLSideRight - 3) + "}";
                        status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0083[HCLSP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                        if (status)
                        {
                            swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0083[HCLSP-]{}-1"));
                            swComp.SetSuppression2(2); //2解压缩,0压缩.
                            status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0083[HCLSP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                            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");
                            swComp.SetSuppression2(2); //2解压缩,0压缩.
                            swPart = swComp.GetModelDoc2();//打开零件
                            swPart.Parameter("D1@Sketch1").SystemValue = (item.HCLSideRight - 3m) / 1000m;
                        }
                        break;
                    case "BOTH":
                        //重命名装配体内部
                        compReName = "FNCE0082[HCLSP-" + tree.Module + "]{" + ((int)item.HCLSideLeft - 3) + "}";
                        status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0082[HCLSP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                        if (status)
                        {
                            swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0082[HCLSP-]{}-1"));
                            swComp.SetSuppression2(2); //2解压缩,0压缩.
                            status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0082[HCLSP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                            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");
                            swComp.SetSuppression2(2); //2解压缩,0压缩.
                            swPart = swComp.GetModelDoc2();//打开零件
                            swPart.Parameter("D1@Sketch1").SystemValue = (item.HCLSideLeft - 3m) / 1000m;
                        }
                        //重命名装配体内部
                        compReName = "FNCE0083[HCLSP-" + tree.Module + "]{" + ((int)item.HCLSideRight - 3) + "}";
                        status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0083[HCLSP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                        if (status)
                        {
                            swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0083[HCLSP-]{}-1"));
                            swComp.SetSuppression2(2); //2解压缩,0压缩.
                            status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0083[HCLSP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                            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");
                            swComp.SetSuppression2(2); //2解压缩,0压缩.
                            swPart = swComp.GetModelDoc2();//打开零件
                            swPart.Parameter("D1@Sketch1").SystemValue = (item.HCLSideRight - 3m) / 1000m;
                        }
                        break;
                    default:
                        swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0082[HCLSP-]{}-1"));
                        swComp.SetSuppression2(0); //2解压缩,0压缩.
                        swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0083[HCLSP-]{}-1"));
                        swComp.SetSuppression2(0); //2解压缩,0压缩.
                        break;
                }

                //----------灯腔主体----------
                //重命名装配体内部
                compReName = "FNCL0036[LKS258HCL-" + tree.Module + "]{" + (int)item.Length + "}";
                status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCL0036-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@Skizze1").SystemValue = item.Length / 1000m;
                    //HCL侧板磁铁孔
                    if (item.HCLSide == "LEFT" || item.HCLSide == "BOTH")
                    {
                        swFeat = swComp.FeatureByName("Cut-Extrude5");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D5@Sketch22").SystemValue = (item.HCLSideLeft - 103) / 1000m;
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("Cut-Extrude5");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    if (item.HCLSide == "RIGHT" || item.HCLSide == "BOTH")
                    {
                        swFeat = swComp.FeatureByName("Cut-Extrude6");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D6@Sketch23").SystemValue = (item.HCLSideRight - 103) / 1000m;
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("Cut-Extrude6");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                }

                //支撑条

                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0034-1"));
                swPart = swComp.GetModelDoc2();//打开零件
                switch (item.HCLSide)
                {
                    case "LEFT":
                        swPart.Parameter("D1@Skizze1").SystemValue = (item.Length - item.HCLSideLeft) / 1000m;
                        swModel.Parameter("D1@Distance8").SystemValue = item.HCLSideLeft / 1000m;
                        break;
                    case "RIGHT":
                        swPart.Parameter("D1@Skizze1").SystemValue = (item.Length - item.HCLSideRight) / 1000m;
                        swModel.Parameter("D1@Distance8").SystemValue = 0m;
                        break;
                    case "BOTH":
                        swPart.Parameter("D1@Skizze1").SystemValue = (item.Length - item.HCLSideLeft - item.HCLSideRight) / 1000m;
                        swModel.Parameter("D1@Distance8").SystemValue = item.HCLSideLeft / 1000m;
                        break;
                    default:
                        swPart.Parameter("D1@Skizze1").SystemValue = item.Length / 1000m;
                        swModel.Parameter("D1@Distance8").SystemValue = 0m;
                        break;
                }

                swModel.ForceRebuild3(true);//设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
                swModel.Save();//保存,很耗时间
                swApp.CloseDoc(packedAssyPath);//关闭,很快
            }
            catch (Exception ex)
            {
                throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
        }
Exemplo n.º 5
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()) < 100m)
            {
                MessageBox.Show("请认真检查灯腔长度", "提示信息");
                txtLength.Focus();
                txtLength.SelectAll();
                return;
            }

            //其他配置
            if (cobHCLSide.SelectedIndex == -1)
            {
                MessageBox.Show("请选择HCL侧板位置", "提示信息");
                cobHCLSide.Focus();
                return;
            }
            if ((cobHCLSide.SelectedIndex == 0 || cobHCLSide.SelectedIndex == 2) && (!DataValidate.IsDecimal(txtHCLSideLeft.Text.Trim()) || Convert.ToDecimal(txtHCLSideLeft.Text.Trim()) < 10m))
            {
                MessageBox.Show("请认真检查左HCL侧板长度", "提示信息");
                txtHCLSideLeft.Focus();
                txtHCLSideLeft.SelectAll();
                return;
            }
            if ((cobHCLSide.SelectedIndex == 1 || cobHCLSide.SelectedIndex == 2) && (!DataValidate.IsDecimal(txtHCLSideRight.Text.Trim()) || Convert.ToDecimal(txtHCLSideRight.Text.Trim()) < 10m))
            {
                MessageBox.Show("请认真检查右HCL侧板长度", "提示信息");
                txtHCLSideRight.Focus();
                txtHCLSideRight.SelectAll();
                return;
            }


            #endregion
            //封装对象
            LKS258HCL objLKS258HCL = new LKS258HCL()
            {
                LKS258HCLId  = Convert.ToInt32(pbModelImage.Tag),
                HCLSide      = cobHCLSide.Text,
                HCLSideLeft  = Convert.ToDecimal(txtHCLSideLeft.Text.Trim()),
                HCLSideRight = Convert.ToDecimal(txtHCLSideRight.Text.Trim()),
                Length       = Convert.ToDecimal(txtLength.Text.Trim())
            };
            //提交修改
            try
            {
                if (objLKS258HCLService.EditModel(objLKS258HCL) == 1)
                {
                    MessageBox.Show("制图数据修改成功", "提示信息");
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }