Esempio n. 1
0
        public void LoadStatistics(Sys_Statistics_Item select)
        {
            ComboModules.Items.Clear();
            Statistics = StatisticsHelperClient.GetStatisticsList();
            if (Statistics == null || Statistics.Rows.Count == 0)
            {
                return;
            }

            ComboModules.SelectedIndexChanged -= new EventHandler(ComboModules_SelectedIndexChanged);
            {
                for (var i = 0; i < Statistics.Rows.Count; i++)
                {
                    var row = Statistics.Rows[i];
                    ComboModules.Items.Add(row["ItemName"] as string);
                }

                if (select == null)
                {
                    ComboModules.SelectedIndex = 0;
                }
                else
                {
                    ComboModules.SelectedItem = select.Name;
                }
            }
            ComboModules.SelectedIndexChanged += new EventHandler(ComboModules_SelectedIndexChanged);
        }
Esempio n. 2
0
        private void TableModules_CellClick(object sender, CellClickEventArgs e)
        {
            switch (e.Column)
            {
            case 1:
                var cell   = this.TableModules.ActiveSheet.Cells[e.Row, e.Column];
                var idCell = this.TableModules.ActiveSheet.Cells[e.Row, 0];
                if (Convert.ToString(cell.Tag) == "#")
                {
                    return;
                }

                var id = new Guid(Convert.ToString(idCell.Tag));

                if (MessageBox.Show("删除后将不可恢复, 是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var result = StatisticsHelperClient.RemoveStatisticsReference(CurrentStatistics.ID, id);
                    if (string.IsNullOrEmpty(result))
                    {
                        this.ComboModules_SelectedIndexChanged(this, EventArgs.Empty);
                        MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show(result, "删除错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                break;
            }
        }
Esempio n. 3
0
        private void ButtonDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要删除该分类吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                StatisticsHelperClient.DeleteStatistics(new Guid[] { CurrentStatistics.ID });

                MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                LoadStatistics(null);
            }
        }
Esempio n. 4
0
        private void ButtonModify_Click(object sender, EventArgs e)
        {
            var form = new NewStatistics(CurrentStatistics);

            if (form.ShowDialog() == DialogResult.OK)
            {
                var model = form.Result;

                var result = StatisticsHelperClient.ModifyStatistics(model);
                if (string.IsNullOrEmpty(result))
                {
                    MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadStatistics(model);
                    ComboModules.SelectedItem = model.Name;
                }
            }
        }
Esempio n. 5
0
        private void Reload()
        {
            TreeAll.Nodes.Clear();
            TreeMerge.Nodes.Clear();

            var factories = StatisticsHelperClient.GetFactories("FactoryID, FactoryName", "FactoryName ASC");

            if (factories == null || factories.Rows.Count == 0)
            {
                TreeAll.Nodes.Add("没有数据");
                return;
            }

            foreach (DataRow row in factories.Rows)
            {
                TreeAll.Nodes.Add(Convert.ToString(row["FactoryID"]), Convert.ToString(row["FactoryName"]));
            }
        }
Esempio n. 6
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            if (TreeMerge.Nodes.Count == 0)
            {
                MessageBox.Show("请从所有厂家选择要合并的厂家后再执行此操作", "提示", MessageBoxButtons.OK);
                return;
            }

            var node    = TreeMerge.Nodes[0];
            var factory = StatisticsHelperClient.GetFactory("*", new Guid(node.Name));

            if (factory == null)
            {
                MessageBox.Show("获取厂家信息时失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            var ids = new List <string>();

            foreach (TreeNode n in TreeMerge.Nodes)
            {
                ids.Add(n.Name);
            }

            var editor = new FactoryEditor(factory, true);

            editor.Saving += new EventHandler(delegate(object o, EventArgs se)
            {
                var result = StatisticsHelperClient.MergeFactory(ids.ToArray(), editor.Factory);
                if (string.IsNullOrEmpty(result))
                {
                    MessageBox.Show("合并成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    TreeAll.Nodes.Insert(0, editor.Factory.FactoryID.ToString(), editor.Factory.FactoryName);
                    TreeMerge.Nodes.Clear();
                }
                else
                {
                    MessageBox.Show(result, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            });

            editor.Show();
        }
Esempio n. 7
0
        private Sys_Statistics_Item SaveNewStatistics()
        {
            var form = new NewStatistics();

            if (form.ShowDialog() == DialogResult.OK)
            {
                var model  = form.Result;
                var result = StatisticsHelperClient.NewStatistics(model);
                if (string.IsNullOrEmpty(result) == false)
                {
                    MessageBox.Show(result, "添加统计项失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(null);
                }

                LoadStatistics(model);

                return(model);
            }

            return(null);
        }
Esempio n. 8
0
        private void ComboModules_SelectedIndexChanged(object sender, EventArgs e)
        {
            var SetCurrentModule = true;

            Modules         = null;
            NeedSynchronous = false;
            TableModules_Sheet1.Rows.Count = 0;
            LinkModifyStatistics.Enabled   = false;
            LinkDeleteStatistics.Enabled   = false;

            var sheet = CloneSheet(TableModules.ActiveSheet, 0);

            if (Statistics != null && Statistics.Rows.Count > 0)
            {
                var row = Statistics.Rows[ComboModules.SelectedIndex];
                CurrentStatistics = new Sys_Statistics_Item()
                {
                    ID      = new Guid(Convert.ToString(row["ItemID"])),
                    Columns = Convert.ToString(row["Columns"]),
                    Name    = Convert.ToString(row["ItemName"]),
                    Type    = Convert.ToInt32(row["ItemType"]),
                    Weight  = Convert.ToInt32(row["Weight"]),
                    Status  = 1
                };

                LinkDeleteStatistics.Enabled = true;
                LinkModifyStatistics.Enabled = true;
                Modules            = StatisticsHelperClient.GetStatisticsModules(CurrentStatistics.ID);
                Modules.PrimaryKey = new DataColumn[] { Modules.Columns["ModuleID"] };
                if (Modules != null && Modules.Rows.Count > 0)
                {
                    var currentModuleID = Guid.Empty;
                    if (CurrentModule != null)
                    {
                        currentModuleID = CurrentModule.ID;
                    }

                    sheet.Rows.Count = Modules.Rows.Count;
                    for (var i = 0; i < Modules.Rows.Count; i++)
                    {
                        row = Modules.Rows[i];

                        var id = new Guid(Convert.ToString(row["ModuleID"]));
                        if (currentModuleID == id)
                        {
                            SetCurrentModule = false;
                        }

                        sheet.Cells[i, 0].Value = row["Name"];
                        sheet.Cells[i, 0].Tag   = row["ModuleID"];
                    }
                }
            }

            if (SetCurrentModule)
            {
                LoadCurrentModule(sheet);
            }

            TableModules.Sheets.Clear();
            TableModules.Sheets.Add(sheet);
        }
Esempio n. 9
0
        private bool SaveSetting(Sys_Statistics_Item statistics)
        {
            var statisticsID      = statistics.ID;
            var selectionModuleID = GetSelectionModuleID();

            if (statisticsID == Guid.Empty || selectionModuleID == Guid.Empty)
            {
                return(false);
            }

            var statisticsSettings = new List <StatisticsSetting>();

            try
            {
                var settting = JsonConvert.DeserializeObject <List <StatisticsSetting> >(CurrentStatistics.Columns);
                if (settting != null)
                {
                    statisticsSettings = settting;
                }
            }
            catch (Exception)
            {
                var m = JsonConvert.DeserializeObject <Dictionary <string, string> >(CurrentStatistics.Columns);
                foreach (var key in m.Keys)
                {
                    statisticsSettings.Add(new StatisticsSetting()
                    {
                        ItemName  = key,
                        BindField = m[key],
                    });
                }
            }
            StatisticsModuleSetting model = null;
            StatisticsSetting       item  = null;
            var settings = new List <StatisticsModuleSetting>();

            for (var i = 0; i < this.TableStatistics.ActiveSheet.Rows.Count; i++)
            {
                model = new StatisticsModuleSetting();
                item  = new StatisticsSetting();
                var itemName  = TableStatistics.ActiveSheet.Cells[i, 0].Value;
                var itemType  = TableStatistics.ActiveSheet.Cells[i, 1].Value;
                var sheetName = TableStatistics.ActiveSheet.Cells[i, 2].Value;
                var sheetID   = TableStatistics.ActiveSheet.Cells[i, 2].Tag;
                var cellName  = TableStatistics.ActiveSheet.Cells[i, 3].Value;
                if (itemName == null || itemType == null)
                {
                    continue;
                }

                var itn = Convert.ToString(itemName);
                var it  = Map[Convert.ToString(itemType)];
                var sn  = Convert.ToString(sheetName);
                var si  = new Guid(Convert.ToString(sheetID));
                var cn  = Convert.ToString(cellName);

                model.BindField          = it;
                model.StatisticsItemName = itn;
                model.CellName           = cn;
                model.SheetName          = sn;
                model.SheetID            = si;

                item = statisticsSettings.Find(m => m.BindField == it);
                if (item == null)
                {
                    item = new StatisticsSetting();
                    statisticsSettings.Add(item);
                }

                item.BindField = it;
                item.ItemName  = itn;
                settings.Add(model);
            }

            var map    = JsonConvert.SerializeObject(settings);
            var result = StatisticsHelperClient.UpdateStatisticsMapOnModule(selectionModuleID, map);

            if (string.IsNullOrEmpty(result) == false)
            {
                MessageBox.Show(result, "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            statistics.Columns = JsonConvert.SerializeObject(statisticsSettings);
            result             = StatisticsHelperClient.ModifyStatistics(statistics);
            if (string.IsNullOrEmpty(result) == false)
            {
                MessageBox.Show(result, "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            if (NeedSynchronous)
            {
                result = StatisticsHelperClient.SynchronousStatistics(statistics.ID, statisticsSettings);
            }

            result = StatisticsHelperClient.NewStatisticsReference(statistics.ID, selectionModuleID);
            if (string.IsNullOrEmpty(result) == false)
            {
                MessageBox.Show(result, "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            return(true);
        }