예제 #1
0
        public static object ChooseAmbiguousSupplyOrComponent(DataAccess.Component[] components, Supply[] supplies, string supplyNoOrComponentName)
        {
            if ((components == null || components.Length == 0) && (supplies == null || supplies.Length == 0))
            {
                return(null);
            }
            FormChooseAmbiguousSupplyOrComponent form = new FormChooseAmbiguousSupplyOrComponent();

            if (components != null && components.Length > 0)
            {
                form.listBox.Items.AddRange((from c in components
                                             select new ItemAndString()
                {
                    Item = c,
                    String = c.Name
                }).ToArray());
            }
            if (supplies != null && supplies.Length > 0)
            {
                form.listBox.Items.AddRange((from s in supplies
                                             select new ItemAndString()
                {
                    Item = s,
                    String = s.No
                }).ToArray());
            }
            //form.listBox.SelectedIndex = 0;
            form.label1.Text = string.Format("您输入的零件\"{0}\"不明确,请选择下列零件中的一个", supplyNoOrComponentName);
            form.ShowDialog();
            return(form.selectedItem);
        }
예제 #2
0
        public static bool GetSupplyOrComponentAmbiguous(string supplyNoOrComponentName, out DataAccess.Component component, out Supply supply, out string errorMessage, int supplierID = -1, WMSEntities wmsEntities = null)
        {
            if (wmsEntities == null)
            {
                wmsEntities = new WMSEntities();
            }
            //如果输入的名字是空的,直接抛出异常。这儿不允许传入空的
            if (string.IsNullOrWhiteSpace(supplyNoOrComponentName))
            {
                throw new Exception("GetSupplyOrComponent()函数不允许传入空的零件名字(代号)!空格也不行!请使用string.IsNullOrWhiteSpace()自行判空");
            }
            //首先精确查询,如果没有,再模糊查询
            component = (from c in wmsEntities.Component
                         where c.Name == supplyNoOrComponentName &&
                         (from s in wmsEntities.Supply
                          where s.ComponentID == c.ID &&
                          s.ProjectID == GlobalData.ProjectID &&
                          s.WarehouseID == GlobalData.WarehouseID &&
                          s.SupplierID == (supplierID == -1 ? s.SupplierID : supplierID)
                          select s).Count() > 0
                         select c).FirstOrDefault();
            supply = (from s in wmsEntities.Supply
                      where s.No == supplyNoOrComponentName &&
                      s.ProjectID == GlobalData.ProjectID &&
                      s.WarehouseID == GlobalData.WarehouseID &&
                      s.SupplierID == (supplierID == -1 ? s.SupplierID : supplierID) &&
                      s.IsHistory == 0
                      select s).FirstOrDefault();
            if (component == null && supply == null)
            {
                //模糊查询供货
                Supply[] supplies = (from s in wmsEntities.Supply
                                     where s.No.Contains(supplyNoOrComponentName) &&
                                     s.ProjectID == GlobalData.ProjectID &&
                                     s.WarehouseID == GlobalData.WarehouseID &&
                                     s.SupplierID == (supplierID == -1 ? s.SupplierID : supplierID) &&
                                     s.IsHistory == 0
                                     select s).ToArray();
                //模糊查询零件
                DataAccess.Component[] components = (from c in wmsEntities.Component
                                                     where c.Name.Contains(supplyNoOrComponentName) &&
                                                     (from s in wmsEntities.Supply
                                                      where s.ComponentID == c.ID &&
                                                      s.ProjectID == GlobalData.ProjectID &&
                                                      s.WarehouseID == GlobalData.WarehouseID &&
                                                      s.SupplierID == (supplierID == -1 ? s.SupplierID : supplierID)
                                                      select s).Count() > 0
                                                     select c).ToArray();

                if (supplies.Length + components.Length == 0)
                {
                    component    = null;
                    supply       = null;
                    errorMessage = "未找到零件:" + supplyNoOrComponentName;
                    return(false);
                }
                //Supply或Component不唯一的情况
                if (supplies.Length + components.Length != 1)
                {
                    object selectedObj =
                        FormChooseAmbiguousSupplyOrComponent.ChooseAmbiguousSupplyOrComponent(
                            components,
                            supplies,
                            supplyNoOrComponentName);
                    if (selectedObj == null)
                    {
                        errorMessage = "用户取消了导入";
                        return(false);
                    }
                    else if (selectedObj is DataAccess.Component)
                    {
                        component = selectedObj as DataAccess.Component;
                    }
                    else if (selectedObj is Supply)
                    {
                        supply = selectedObj as Supply;
                    }
                    else
                    {
                        throw new Exception("FormChooseAmbiguousSupplyOrComponent返回值类型错误");
                    }
                    errorMessage = null;
                    return(true);
                }

                //如果搜索到唯一的零件/供货,则确定就是它。
                if (supplies.Length > 0)
                {
                    supply = supplies[0];
                }
                else
                {
                    component = components[0];
                }
                errorMessage = null;
                return(true);
            }
            errorMessage = null;
            return(true);
        }