Ejemplo n.º 1
0
 private void btnLoad_Click(object sender, EventArgs e)
 {
     try
     {
         var result = MessageBox.Show("Current content will be overwrite!\nChoose YES to confirm, Choose NO to abort.",
                                      "Load Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         if (DialogResult.No == result)
         {
             return;
         }
         var dlg = new OpenFileDialog()
         {
             Filter = "json text|*.json|plain text|*.txt|All files(*.*)|*.*"
         };
         var load = dlg.ShowDialog();
         if (DialogResult.OK == load)
         {
             using (StreamReader sr = File.OpenText(dlg.FileName))
             {
                 var obj = BISpecification.Deserialize(sr.ReadToEnd());
                 sr.Close();
                 LoadBISpecification(obj);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 2
0
 private void LoadBISpecification(BISpecification biSpec)
 {
     tbPlan.Text     = biSpec.Plan;
     tbVersion.Text  = biSpec.Version;
     tbDriver.Text   = biSpec.Driver;
     tbSpan.Text     = biSpec.Span;
     tbInterval.Text = biSpec.Interval;
     configTable.Rows.Clear();
     specTable.Rows.Clear();
     foreach (var item in biSpec.Configuration)
     {
         var row = configTable.NewRow();
         row["Item"]  = item.Item;
         row["Value"] = item.Value;
         configTable.Rows.Add(row);
     }
     foreach (var item in biSpec.Specification)
     {
         var row = specTable.NewRow();
         row["Item"]   = item.Item;
         row["Type"]   = item.Type;
         row["LBound"] = item.LBound;
         row["UBound"] = item.UBound;
         specTable.Rows.Add(row);
     }
 }
Ejemplo n.º 3
0
 public static string Serialize(BISpecification obj)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(BISpecification));
         json.WriteObject(stream, obj);
         return(Encoding.UTF8.GetString(stream.ToArray()));
     }
 }
Ejemplo n.º 4
0
        public void CommitSpecification(BISpecification spec)
        {
            string updateValidFlagStatement = "UPDATE [BI_Specification] SET [Validation]=0 WHERE [Plan]='<Plan>' AND [Validation]=1\n".Replace("<Plan>", spec.Plan);
            string insertNewSpecStatement   = "INSERT [BI_Specification] ([Plan],[Version],[Content],[Load_Time],[Validation]) VALUES ('<Plan>','<Version>','<Content>',GETDATE(),1)\n"
                                              .Replace("<Plan>", spec.Plan).Replace("<Version>", spec.Version).Replace("<Content>", BISpecification.Serialize(spec));
            string cmd = "set xact_abort on\nbegin tran\n<statement>\ncommit tran\ngo".Replace("<statement>", updateValidFlagStatement + insertNewSpecStatement);

            Execute(cmd);
        }
Ejemplo n.º 5
0
        private BISpecification GenerateBISpecification()
        {
            if (string.IsNullOrEmpty(tbPlan.Text))
            {
                throw new Exception("PLAN cannot be empty!");
            }
            if (string.IsNullOrEmpty(tbVersion.Text))
            {
                throw new Exception("VERSION cannot be empty!");
            }
            if (string.IsNullOrEmpty(tbDriver.Text))
            {
                throw new Exception("DRIVER cannot be empty!");
            }
            double.Parse(tbSpan.Text);
            double.Parse(tbInterval.Text);
            var ret = new BISpecification();

            ret.Plan          = tbPlan.Text;
            ret.Version       = tbVersion.Text;
            ret.Driver        = tbDriver.Text;
            ret.Span          = tbSpan.Text;
            ret.Interval      = tbInterval.Text;
            ret.Configuration = new List <ConditionItem>();
            foreach (DataRow row in configTable.Rows)
            {
                ret.Configuration.Add(new ConditionItem()
                {
                    Item = row["Item"].ToString(), Value = row["Value"].ToString()
                });
            }
            ret.Specification = new List <SpecItem>();
            foreach (DataRow row in specTable.Rows)
            {
                ret.Specification.Add(new SpecItem()
                {
                    Item   = row["Item"].ToString(),
                    Type   = row["Type"].ToString(),
                    LBound = row["LBound"].ToString(),
                    UBound = row["UBound"].ToString(),
                });
            }
            return(ret);
        }
Ejemplo n.º 6
0
 private void btnLoadFromList_Click(object sender, EventArgs e)
 {
     try
     {
         var result = MessageBox.Show("Current content will be overwrite!\nChoose YES to confirm, Choose NO to abort.",
                                      "Load Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         if (DialogResult.No == result)
         {
             return;
         }
         string content = (string)dgvSpecificationList.SelectedRows[0].Cells["Content"].Value;
         LoadBISpecification(BISpecification.Deserialize(content));
         this.tabControl1.SelectTab(this.tabPage1);
         this.tabPage1.Show();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 7
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         var obj = GenerateBISpecification();
         using (var dlg = new SaveFileDialog()
         {
             DefaultExt = "json"
         })
         {
             dlg.ShowDialog();
             using (StreamWriter sw = File.CreateText(dlg.FileName))
             {
                 sw.Write(BISpecification.Serialize(obj));
                 sw.Close();
             }
         }
         MessageBox.Show("Save File Successful!");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }