Exemplo n.º 1
0
        //Сохранение одной ссылки
        private void SaveLink(Comment c, Shape sh, RecDao rp, RecDao rc, RecDao rs, Worksheet sheet)
        {
            var dic = (sh == null ? c.Text() : sh.Title).ToPropertyDicS();

            if (dic != null && dic.ContainsKey("Field") && dic.ContainsKey("Project") && dic.ContainsKey("Code"))
            {
                LinkType linkType = dic["LinkType"].ToLinkType();
                var      projcode = dic["Project"];
                string   parcode  = dic["Code"];
                if (Projects.ContainsKey(projcode))
                {
                    ReportProjectForLinks proj  = Projects[projcode];
                    ReportParam           param = null;
                    if (proj.IsSave)
                    {
                        //Сохранение
                        if (proj.Params.ContainsKey(parcode))
                        {
                            param = proj.Params[parcode];
                        }
                        else
                        {
                            rp.AddNew();
                            param = new ReportParam(projcode, new ArchiveParam(parcode, DataType.String, null,
                                                                               new CalcParamBase(parcode, dic["CellComment"]), new CalcParamBase(dic["Field"])))
                            {
                                Id = rp.GetInt("ParamId")
                            };
                            rp.Put("Project", projcode);
                            rp.Put("Code", parcode);
                            rp.Put("CodeParam", parcode);
                            rp.Put("DataType", DataType.String.ToRussian());
                            rp.Put("IsUsed", true);
                            rp.Put("IsHandInput", false);
                            proj.Params.Add(parcode, param);
                            rp.Update();
                        }
                    }
                    else if (proj.Params.ContainsKey(parcode))
                    {
                        param = proj.Params[parcode];
                        if (linkType == LinkType.HandInput)
                        {
                            //Ручной ввод
                            param.IsHandInput = true;
                            proj.IsHandInput  = true;
                        }
                        else
                        {
                            //Обычное получние данных
                            param.IsUsed = true;
                            proj.IsUsed  = true;
                        }
                    }

                    if (param != null)
                    {
                        var itype = IntervalType.Empty;
                        if (proj.CalcMode == CalcModeType.Internal)
                        {
                            if (linkType == LinkType.Result || linkType == LinkType.MomentsList)
                            {
                                itype = IntervalType.Single;
                            }
                        }
                        else
                        {
                            switch (linkType)
                            {
                            case LinkType.Combined:
                            case LinkType.CombinedList:
                                if (dic.ContainsKey("LengthMinute") || dic.ContainsKey("PartBeginMinute") ||
                                    dic.ContainsKey("PartEndMinute"))
                                {
                                    itype = IntervalType.Base;
                                }
                                else if (dic.ContainsKey("LengthHour") || dic.ContainsKey("PartBeginHour") ||
                                         dic.ContainsKey("PartEndHour"))
                                {
                                    itype = IntervalType.Hour;
                                }
                                else if (dic.ContainsKey("LengthDay") || dic.ContainsKey("PartByTime"))
                                {
                                    itype = IntervalType.Day;
                                }
                                else
                                {
                                    itype = IntervalType.Combined;
                                }
                                break;

                            case LinkType.Absolute:
                            case LinkType.AbsoluteEdit:
                                itype = IntervalType.Absolute;
                                break;

                            case LinkType.AbsoluteCombined:
                                itype = IntervalType.AbsoluteCombined;
                                break;

                            case LinkType.AbsoluteList:
                                if (dic.ContainsKey("LengthMinute") && dic["LengthMinute"].ToInt() != 0)
                                {
                                    itype = IntervalType.AbsoluteListBase;
                                }
                                else if (dic.ContainsKey("LengthHour") && dic["LengthHour"].ToInt() != 0)
                                {
                                    itype = IntervalType.AbsoluteListHour;
                                }
                                else
                                {
                                    itype = IntervalType.AbsoluteListDay;
                                }
                                break;

                            case LinkType.MomentsList:
                            case LinkType.Result:
                                itype = IntervalType.Moments;
                                break;
                            }
                        }
                        if (!param.IntervalTypes.Contains(itype))
                        {
                            param.IntervalTypes.Add(itype);
                        }

                        if (sh == null)
                        {
                            //Добавление в таблицу Cells
                            rc.AddNew();
                            rc.Put("Page", sheet.Name);
                            rc.Put("Y", ((Range)c.Parent).Row);
                            rc.Put("X", ((Range)c.Parent).Column);
                            rc.Put("LinkType", linkType.ToEnglish());
                            rc.Put("LinkField", dic["Field"]);
                            if (dic.ContainsKey("AllowEdit"))
                            {
                                rc.Put("AllowEdit", dic["AllowEdit"] == "True");
                            }
                            string prop = "";
                            foreach (var k in dic.Keys)
                            {
                                if (k != "LinkType" && k != "Field" && k != "Project" && k != "Code")
                                {
                                    prop += k + "=" + dic[k] + ";";
                                }
                            }
                            rc.Put("Properties", prop);
                            rc.Put("ParamId", param.Id);
                            rc.Put("IntervalType", itype.ToRussian());
                            rc.Put("SaveCode", dic["SaveCode"]);
                            rc.Update();
                        }
                        else
                        {
                            //Добавление в таблицу Shapes
                            rs.AddNew();
                            rs.Put("Page", sheet.Name);
                            rs.Put("ShapeId", sh.ID);
                            rs.Put("ShapeType", sh.Type.ToEnglish());
                            if (sh.Type == MsoShapeType.msoGroup)
                            {
                                rs.Put("Formula", sh.AlternativeText);
                            }
                            rs.Put("LinkType", linkType.ToEnglish());
                            rs.Put("LinkField", dic["Field"]);
                            string prop = "";
                            foreach (var k in dic.Keys)
                            {
                                if (k != "LinkType" && k != "Field" && k != "Project" && k != "Code")
                                {
                                    prop += k + "=" + dic[k] + ";";
                                }
                            }
                            rs.Put("Properties", prop);
                            rs.Put("ParamId", param.Id);
                            rs.Put("IntervalType", itype.ToRussian());
                            rs.Update();
                        }
                    }
                }
            }
        }