Esempio n. 1
0
        private void BtnImport_Click(object sender, RoutedEventArgs e)
        {
            System.Data.DataTable importdt = new System.Data.DataTable();
            importdt = GetDataFromExcelByCom();
            if (importdt != null)
            {
                if (importdt.Rows.Count != 0)
                {
                    string str;

                    for (int i = 0; i < importdt.Rows.Count; i++)
                    {
                        str = "";
                        string dept_id = list.Where(t => t.DeptName == importdt.Rows[i][0].ToString()).Select(t => t.DeptId).FirstOrDefault();

                        if (dept_id == null || dept_id == "")
                        {
                            load.Close();
                            Toolkit.MessageBox.Show(importdt.Rows[i][0].ToString() + "不是正确的下级部门,请确认后重新导入!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            return;
                        }

                        for (int j = 1; j < importdt.Columns.Count; j++)
                        {
                            string item_id = list.Where(t => t.ItemName == importdt.Columns[j].ColumnName).Select(t => t.ItemId).FirstOrDefault();
                            if (item_id == null || item_id == "")
                            {
                                load.Close();
                                Toolkit.MessageBox.Show(importdt.Columns[j].ColumnName + "不是正确的检测项目,请确认后重新导入!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                                return;
                            }
                            string num = importdt.Rows[i][j].ToString();
                            if (num == null || num == "")
                            {
                                num = '0'.ToString();
                            }
                            str = str + item_id + "," + num + ",";

                            if (j != importdt.Columns.Count - 1)
                            {
                                str = str + "#";
                            }
                        }

                        try
                        {
                            int result = dbOperation.GetDbHelper().ExecuteSql(string.Format("call p_set_task ('{0}','{1}')",
                                                                                            dept_id, str));

                            if (result == 1)
                            {
                            }
                            else
                            {
                                load.Close();
                                Toolkit.MessageBox.Show("任务量设置失败!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            load.Close();
                            Toolkit.MessageBox.Show("任务量设置失败2!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            return;
                        }
                    }

                    load.Close();
                    Toolkit.MessageBox.Show("任务导入设置成功!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    Load_table();
                    return;
                }
                else
                {
                    load.Close();
                    Toolkit.MessageBox.Show("导入excel内容为空,请确认!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
            }
        }
Esempio n. 2
0
        private void BtnImport_Click(object sender, RoutedEventArgs e)
        {
            System.Data.DataTable importdt = new System.Data.DataTable();
            importdt = GetDataFromExcelByCom();
            if (importdt != null)
            {
                if (importdt.Rows.Count != 0)
                {
                    string str;

                    for (int i = 0; i < importdt.Rows.Count; i++)
                    {
                        str = "";
                        string dept_id = list.Where(t => t.DeptName == importdt.Rows[i][0].ToString()).Select(t => t.DeptId).FirstOrDefault();

                        if (dept_id == null || dept_id == "")
                        {
                            load.Close();
                            Toolkit.MessageBox.Show(importdt.Rows[i][0].ToString() + "不是正确的下级部门,请确认后重新导入!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            return;
                        }

                        for (int j = 1; j < importdt.Columns.Count; j++)
                        {
                            string item_id = list.Where(t => t.ItemName == importdt.Columns[j].ColumnName).Select(t => t.ItemId).FirstOrDefault();
                            if (item_id == null || item_id == "")
                            {
                                load.Close();
                                Toolkit.MessageBox.Show(importdt.Columns[j].ColumnName + "不是正确的检测项目,请确认后重新导入!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                                return;
                            }
                            string num = importdt.Rows[i][j].ToString();
                            if (num == null || num == "")
                            {
                                num = '0'.ToString();
                            }
                            str = str + item_id + "," + num + ",";

                            if (j != importdt.Columns.Count - 1)
                            {
                                str = str + "#";
                            }
                        }

                        try
                        {
                            string function = "";
                            switch (dept_type)
                            {
                            case "0": function = "p_set_task_produce";
                                break;

                            case "1": function = "p_set_task_fishery";
                                break;

                            case "2": function = "p_set_task_animal";
                                break;

                            default: break;
                            }

                            int result = sysTaskContract.ExecuteProTask(function, dept_id, str);
                            if (result == 1)
                            {
                            }
                            else
                            {
                                load.Close();
                                Toolkit.MessageBox.Show("任务量设置失败!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            load.Close();
                            Toolkit.MessageBox.Show("任务量设置失败2!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                            return;
                        }
                    }

                    load.Close();
                    Toolkit.MessageBox.Show("任务导入设置成功!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    Load_table();
                    return;
                }
                else
                {
                    load.Close();
                    Toolkit.MessageBox.Show("导入excel内容为空,请确认!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
            }
        }