Пример #1
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;
                }
            }
        }
Пример #2
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);
        }