public bool SaveConfigFile(Models.RegDataModel reg, string filePath) { bool result = false; try { //Registry.SetValue($@"HKEY_LOCAL_MACHINE\Software\BarayFormsCopier\", "Server1", reg.server1); //Registry.SetValue($@"HKEY_LOCAL_MACHINE\Software\BarayFormsCopier\", "DB1", reg.db1); //Registry.SetValue($@"HKEY_LOCAL_MACHINE\Software\BarayFormsCopier\", "Server2", reg.server2); //Registry.SetValue($@"HKEY_LOCAL_MACHINE\Software\BarayFormsCopier\", "DB2", reg.db2); if (File.Exists(filePath)) { File.Delete(filePath); } using (StreamWriter s = new StreamWriter(filePath)) { s.WriteLine(reg.Server1); s.WriteLine(reg.Db1); s.WriteLine(reg.Server2); s.WriteLine(reg.Db2); s.Close(); } result = true; } catch (Exception ex) { System.Diagnostics.Debug.Print("SetValues Error : " + ex.Message); result = false; } return(result); }
private void btnStart_Click(object sender, EventArgs e) { Func <object, int> CInt = (a) => { return(Convert.ToInt32(a)); }; btnStart.Enabled = false; pb.Value = 0; DialogResult mResult = 0; string sResult = ""; int iResult = -1; var opm = new Models.OutputParamaterModel(); // Saving Registry Values : var reg = new Models.RegDataModel(txtServer1.Text.Trim(), txtDB1.Text.Trim(), txtServer2.Text.Trim(), txtDB2.Text.Trim()); using (var a = new FileAccess()) { a.SaveConfigFile(reg, configFilePath); }; if (cmbFTID1.SelectedItem == null) { MessageBox.Show(Messages.cFormTypeNotSelected, Messages.cErr, MessageBoxButtons.OK, MessageBoxIcon.Warning); formState(true); return; } formState(false); //pb.Visible = true; lblWait.Visible = true; int ftId = -1; string[] tName = null; IList <int> ftIds = new List <int>(); int newftId = -1; IList <int> newftIds = new List <int>(); string[] newtName = null; DateTime today = System.DateTime.Today; string pvToday = ""; // Fetching Data & Check Routines : using (DA d1 = new DA(txtServer1.Text.Trim(), txtDB1.Text.Trim())) { using (DA d2 = new DA(txtServer2.Text.Trim(), txtDB2.Text.Trim())) { if (!d1.Connected()) { MessageBox.Show(Messages.cDbConnFailed + " 1", Messages.cErr, MessageBoxButtons.OK, MessageBoxIcon.Stop); formState(true); return; } if (!d2.Connected()) { MessageBox.Show(Messages.cDbConnFailed + " 2", Messages.cErr, MessageBoxButtons.OK, MessageBoxIcon.Stop); formState(true); return; } // Test SomeThing : //var o = new List<Models.OutputParamaterModel>(); //sResult = (d1.ExecProcedure("spTestOutput", new string[] { "@ID", "@O" }, // new object[] { -1, -1 }, // new ParameterDirection[] { ParameterDirection.Input, ParameterDirection.InputOutput }, ref o) ?? "").ToString(); // today = (DateTime)d2.GetValueFromTable("GetDate()", "", ""); pvToday = d2.GetValueFromTable("dbo.GetParsDate(GetDate())", "", "").ToString(); ftId = CInt(cmbFTID1.SelectedItem.ToString().Split('-')[0].Trim()); newftId = CInt(d2.GetValueFromTable("ID", "tblGreenFormTypeL", "ID = " + ftId.ToString(), false)); if (newftId > 0) { mResult = MessageBox.Show(Messages.cFormTypeExistsInDB2 + "\n\n" + Messages.cCreateNewFormTypeIDInDB2, Messages.cErr, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (mResult == DialogResult.No) { MessageBox.Show(Messages.cRemoveCurrentFormTypeIDInDB2, Messages.cErr, MessageBoxButtons.OK, MessageBoxIcon.Stop); formState(true); return; } } // Ask User To Continue : mResult = MessageBox.Show(Messages.cFormCopyConfirmation, Messages.cErr, MessageBoxButtons.YesNo, MessageBoxIcon.Question); //, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign); if (mResult == DialogResult.No) { formState(true); return; } // Begin Copying New Form : newftId = (int)d2.GetValueFromTable("IsNull(Max(ID), 0) + 1", "tblGreenFormTypeL", ""); // GreenFormTables : tName = d1.GetTablesNames(ftId).ToArray(); ftIds = d1.GetFormTypeIDs(ftId).ToArray(); newtName = tName; // Add New Tables To Target DB : foreach (var item in tName) { string script = d1.GetTableScript(item); sResult = d2.ExecSQL(script); if (sResult != "") { MessageBox.Show(Messages.cErrorOccured + "\n\n" + sResult, Messages.cErr, MessageBoxButtons.OK, MessageBoxIcon.Error); // Removing InComplete Added Objects : foreach (var i in tName.Reverse <string>()) { System.Diagnostics.Debug.Print(d2.RemoveObjectByName(i)); } formState(true); return; } } // Executing spMGRUpdateGreenTables : System.Diagnostics.Debug.Print((d2.ExecProcedure("spMGRUpdateGreenTables", new string[] { "@TableName", "@DROPPINGVIEW" }, new object[] { "", 0 }) ?? "").ToString()); List <Models.OutputParamaterModel> p = null; foreach (var item in tName) { p = new List <Models.OutputParamaterModel>(); sResult = (d2.ExecProcedure("spGreenFormBuilder", new string[] { "@TableName", "@CreatorID", "@CreateDate", "@PVCreateDate", "@FormTypeID" }, new object[] { item, 1, today, pvToday, -1 }, new ParameterDirection[] { ParameterDirection.Input, ParameterDirection.Input, ParameterDirection.Input, ParameterDirection.Input, ParameterDirection.InputOutput }, ref p) ?? "").ToString(); if (sResult == "") { opm = p.Where(x => x.ParamName == "@FormTypeID").FirstOrDefault <Models.OutputParamaterModel>(); //opm = (from x in p // where x.ParamName == "@FormTypeID" // select x).ToList<Models.OutputParamaterModel>().FirstOrDefault(); if (opm != null) { iResult = CInt(opm.ParamValue); if (iResult <= 0) { // Form Created... MessageBox.Show(iResult.ToString()); } else { // Add New Created FormTypeIDs To Collection... newftIds.Add(CInt(d2.GetValueFromTable("Max(ID)", "tblGreenFormTypeL", ""))); } } } else { // Removing Added Tables : foreach (var i in newftIds) { sResult = d2.GetValueFromTable("FormTypeID", "tblGreenFormTables", "").ToString(); System.Diagnostics.Debug.Print(d2.RemoveObjectByName(sResult)); System.Diagnostics.Debug.Print(d2.ExecProcedure("spMGRDeleteTableOfForm", new string[] { "@PrimaryTableName", "@FormID", "@Dropping" }, new object[] { sResult, i, 1 }).ToString()); } formState(true); MessageBox.Show(Messages.cErrorOccured + sResult, Messages.cErr, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // Continue : // Successful : MessageBox.Show(Messages.cSuccessfull, "", MessageBoxButtons.OK, MessageBoxIcon.Information); formState(true); } } }