Ejemplo n.º 1
0
        public bool CheckIfExistDoubleBomWithPart(string model, string descrLike, string bomNodeType, string bomNodeType2)
        {
            try
            {
                bool ret = false;

                ITableAndFields tf1 = null;
                ITableAndFields tf2 = null;
                ITableAndFields tf3 = null;
                ITableAndFields tf4 = null;
                ITableAndFields[] tafa = null;

                MethodBase mthObj = MethodBase.GetCurrentMethod();
                int tk = mthObj.MetadataToken;
                SQLContextNew sqlCtx = null;
                lock (mthObj)
                {
                    if (!SQLCache.PeerTheSQL(tk, out sqlCtx))
                    {
                        tf1 = new TableAndFields<_Metas.ModelBOM_NEW>();
                        var cond1 = new _Metas.ModelBOM_NEW();
                        cond1.flag = 1;
                        cond1.material = model;
                        tf1.Conditions.Add(new EqualCondition<_Metas.ModelBOM_NEW>(cond1));
                        tf1.AddRangeToGetFieldNames(_Metas.ModelBOM_NEW.fn_id);

                        tf2 = new TableAndFields<_Metas.Part_NEW>();
                        var cond2 = new _Metas.Part_NEW();
                        cond2.flag = 1;
                        cond2.bomNodeType = bomNodeType;
                        tf2.Conditions.Add(new EqualCondition<_Metas.Part_NEW>(cond2));
                        var cond21 = new _Metas.Part_NEW();
                        cond21.descr = "%" + descrLike + "%";
                        tf2.Conditions.Add(new LikeCondition<_Metas.Part_NEW>(cond21));
                        tf2.ClearToGetFieldNames();

                        tf3 = new TableAndFields<_Metas.ModelBOM_NEW>();
                        var cond3 = new _Metas.ModelBOM_NEW();
                        cond3.flag = 1;
                        tf3.Conditions.Add(new EqualCondition<_Metas.ModelBOM_NEW>(cond3));
                        tf3.ClearToGetFieldNames();

                        tf4 = new TableAndFields<_Metas.Part_NEW>();
                        var cond4 = new _Metas.Part_NEW();
                        cond4.flag = 1;
                        cond4.bomNodeType = bomNodeType2;
                        tf4.Conditions.Add(new EqualCondition<_Metas.Part_NEW>(cond4));
                        tf4.ClearToGetFieldNames();

                        tafa = new ITableAndFields[] { tf1, tf2, tf3, tf4 };

                        TableConnectionCollection tblCnnts = new TableConnectionCollection(
                            new TableConnectionItem<_Metas.ModelBOM_NEW, _Metas.Part_NEW>(tf1, _Metas.ModelBOM_NEW.fn_component, tf2, _Metas.Part_NEW.fn_partNo),
                            new TableConnectionItem<_Metas.Part_NEW, _Metas.ModelBOM_NEW>(tf2, _Metas.Part_NEW.fn_partNo, tf3, _Metas.ModelBOM_NEW.fn_material),
                            new TableConnectionItem<_Metas.ModelBOM_NEW, _Metas.Part_NEW>(tf3, _Metas.ModelBOM_NEW.fn_component, tf4, _Metas.Part_NEW.fn_partNo)
                            );

                        sqlCtx = FuncNew.GetConditionedJoinedSelect(tk, "COUNT", tafa, tblCnnts);

                        sqlCtx.Param(g.DecAlias(tf1.Alias, _Metas.ModelBOM_NEW.fn_flag)).Value = cond1.flag;
                        sqlCtx.Param(g.DecAlias(tf2.Alias, _Metas.Part_NEW.fn_flag)).Value = cond2.flag;
                        sqlCtx.Param(g.DecAlias(tf3.Alias, _Metas.ModelBOM_NEW.fn_flag)).Value = cond3.flag;
                        sqlCtx.Param(g.DecAlias(tf4.Alias, _Metas.Part_NEW.fn_flag)).Value = cond4.flag;
                    }
                }
                tafa = sqlCtx.TableFields;
                tf1 = tafa[0];
                tf2 = tafa[1];
                tf3 = tafa[2];
                tf4 = tafa[3];

                sqlCtx.Param(g.DecAlias(tf1.Alias, _Metas.ModelBOM_NEW.fn_material)).Value = model;
                sqlCtx.Param(g.DecAlias(tf2.Alias, _Metas.Part_NEW.fn_bomNodeType)).Value = bomNodeType;
                sqlCtx.Param(g.DecAlias(tf2.Alias, _Metas.Part_NEW.fn_descr)).Value = "%" + descrLike + "%";
                sqlCtx.Param(g.DecAlias(tf4.Alias, _Metas.Part_NEW.fn_bomNodeType)).Value = bomNodeType2;

                using (SqlDataReader sqlR = _Schema.SqlHelper.ExecuteReader(_Schema.SqlHelper.ConnectionString_BOM, CommandType.Text, sqlCtx.Sentence, sqlCtx.Params))
                {
                    if (sqlR != null && sqlR.Read())
                    {
                        int cnt = g.GetValue_Int32(sqlR, sqlCtx.Indexes("COUNT"));
                        ret = cnt > 0 ? true : false;
                    }
                }
                return ret;
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public bool CheckExistMaterialByPno(string pno)
        {
            try
            {
                bool ret = false;

                ITableAndFields tf1 = null;
                ITableAndFields tf2 = null;
                ITableAndFields[] tafa = null;

                MethodBase mthObj = MethodBase.GetCurrentMethod();
                int tk = mthObj.MetadataToken;
                SQLContextNew sqlCtx = null;
                lock (mthObj)
                {
                    if (!SQLCache.PeerTheSQL(tk, out sqlCtx))
                    {
                        tf1 = new TableAndFields<_Metas.Pak_Chn_Tw_Light>();
                        tf1.ClearToGetFieldNames();

                        tf2 = new TableAndFields<_Metas.ModelBOM_NEW>();
                        _Metas.ModelBOM_NEW cond = new _Metas.ModelBOM_NEW();
                        cond.material = pno;
                        cond.flag = 1;
                        tf2.Conditions.Add(new EqualCondition<_Metas.ModelBOM_NEW>(cond));
                        tf2.AddRangeToGetFieldNames(_Metas.ModelBOM_NEW.fn_material);
                        tf2.SubDBCalalog = _Schema.SqlHelper.DB_GetData;

                        tafa = new ITableAndFields[] { tf1, tf2 };

                        TableConnectionCollection tblCnnts = new TableConnectionCollection(
                            new TableConnectionItem<_Metas.Pak_Chn_Tw_Light, _Metas.ModelBOM_NEW>(tf1, _Metas.Pak_Chn_Tw_Light.fn_partNo, tf2, _Metas.ModelBOM_NEW.fn_component));

                        sqlCtx = FuncNew.GetConditionedJoinedSelect(tk, "COUNT", tafa, tblCnnts);

                        sqlCtx.Param(g.DecAlias(tf2.Alias, _Metas.ModelBOM_NEW.fn_flag)).Value = cond.flag;
                    }
                }
                tafa = sqlCtx.TableFields;
                tf1 = tafa[0];
                tf2 = tafa[1];

                sqlCtx.Param(g.DecAlias(tf2.Alias, _Metas.ModelBOM_NEW.fn_material)).Value = pno;

                using (SqlDataReader sqlR = _Schema.SqlHelper.ExecuteReader(_Schema.SqlHelper.ConnectionString_PAK, CommandType.Text, sqlCtx.Sentence, sqlCtx.Params))
                {
                    if (sqlR != null && sqlR.Read())
                    {
                        int cnt = g.GetValue_Int32(sqlR, sqlCtx.Indexes("COUNT"));
                        ret = cnt > 0 ? true : false;
                    }
                }
                return ret;
            }
            catch (Exception)
            {
                throw;
            }
        }