protected void btnApprove_Click(object sender, EventArgs e) { btnPay.Visible = true; try { To = Convert.ToInt32(lblTotalAmtPay.Text); Fr = Convert.ToInt32(lblTFromNo.Text); Re = Convert.ToInt32(lblReqAmt.Text); if (Re <= To) { lblMessage1.Text = "Approve All Form " + To.ToString() + " From No." + Fr.ToString() + " Requir " + Re.ToString(); lblToBeAmount.Text = Re.ToString(); lblToBeApprovadNo.Text = Fr.ToString(); } else if (Re > To) { count = 0; Div = Re / Fr; for (int i = 1; i <= Fr + 1; i++) { Re = Re - (int)Div; if (Re <= To) { count = count + i; goto outer; //break; } // continue; // Re = Re - (int)Div; } outer: if (count > Fr) { lblToBeApprovadNo.Text = "0"; lblToBeAmount.Text = "0"; } else { lblToBeApprovadNo.Text = (Fr - count).ToString(); lblToBeAmount.Text = ((Fr - count) * Div).ToString(); } } int ldf = Convert.ToInt32(lblTotalAmtPay.Text) - Convert.ToInt32(lblToBeAmount.Text); lblLTaken.Text = (Convert.ToInt32(lblLTaken.Text) - ldf).ToString(); lblLRem.Text = (Convert.ToInt32(lblLRem.Text) + ldf).ToString(); } catch (Exception ex) { lblMessage1.Text = ex.ToString(); } }
static void TestFr() { Console.WriteLine("TestFr"); Fr x = new Fr(); x.Clear(); assert("0", x.ToString() == "0"); assert("0.IzZero", x.IsZero()); assert("!0.IzOne", !x.IsOne()); x.SetInt(1); assert("1", x.ToString() == "1"); assert("!1.IzZero", !x.IsZero()); assert("1.IzOne", x.IsOne()); x.SetInt(3); assert("3", x.ToString() == "3"); assert("!3.IzZero", !x.IsZero()); assert("!3.IzOne", !x.IsOne()); x.SetInt(-5); x = -x; assert("5", x.ToString() == "5"); x.SetInt(4); x = x * x; assert("16", x.ToString() == "16"); Fr y; y = x.Clone(); assert("x == y", x.Equals(y)); x.SetInt(123); assert("123", x.ToString() == "123"); assert("y != x", !x.Equals(y)); try { x.SetStr("1234567891234x"); Console.WriteLine("x = {0}", x); } catch (Exception e) { Console.WriteLine("exception test OK\n'{0}'", e); } x.SetStr("1234567891234"); assert("1234567891234", x.ToString() == "1234567891234"); }
private void calFreq_Click(object sender, RoutedEventArgs e) { double T1, T2, Fr; string freq, chargeTime, dischargeTime; string[] an = new string[3]; R1 = Convert.ToInt32(slR1.Value); R2 = Convert.ToInt32(slR2.Value); T1 = (R1 + R2) * C1 * 0.693; T2 = R1 * C1 * 0.693; Fr = 1 / ((R1 + (2 * R2)) * C1 * 0.693); chargeTime = T1.ToString("F6"); dischargeTime = T2.ToString("F6"); freq = Fr.ToString("F3"); an[0] = "T1 = " + chargeTime + Environment.NewLine; an[1] = "T2 = " + dischargeTime + Environment.NewLine; an[2] = "Frequency = " + freq; tbOut.Text = an[0] + an[1] + an[2]; }
static void Fridge(List <Technique.Fridge> Fridges) { bool ToMenu = false; while (!ToMenu) { Console.Clear(); foreach (var Fr in Fridges) { Console.WriteLine("Название: " + Fr.Name + ", " + Fr.ToString()); } string Search_Name; Console.WriteLine("Enter name of the device"); Search_Name = Console.ReadLine(); Console.WriteLine(); if (Search_Name == "add") { string name; bool HasName = false; Console.WriteLine("Enter name of the TV"); name = Console.ReadLine(); for (int fr = 0; fr < Fridges.Count; fr++) { if (Fridges[fr].Name != name) { HasName = true; } else { HasName = false; Console.WriteLine("The device whith this name hes already"); Console.WriteLine(""); Console.WriteLine("Press any key for continue"); Console.ReadLine(); } } if (HasName == true) { HasName = false; Technique.Fridge fridge = new Technique.Fridge(name, false, false, 1); Fridges.Add(fridge); } } if (Search_Name == "beak") { ToMenu = true; } for (int fr = 0; fr < Fridges.Count; fr++) { if (Fridges[fr].Name == Search_Name) { Console.WriteLine("Введите команду: "); string commands = Console.ReadLine(); switch (commands) { case "ON": Fridges[fr].ON(); break; case "OFF": Fridges[fr].OFF(); break; case "OnF": Fridges[fr].ONFrize(); break; case "OfF": Fridges[fr].OFFFrize(); break; case "PR": Fridges[fr].Programm(); break; case "del": Fridges.RemoveAt(fr); break; default: Fridges[0].Help(); break; } } } } }
public void SteadyFlowCalculation() { double term1, term2, term3, h_final, z_final, q_final, constant; //double ie_D1, u_st_D1, tau_st_D1, qb_D1, zb_D1, ie_U1, f_x, du_D1_by_dh, dqb_D1_by_dh, dzb__D1_by_dh, dfx_by_dh; //double dTau_D1_by_dh; try { // input Input(); SFM_n_Section = Convert.ToInt32(SFM_L / SFM_del_X); // initial (zb) and boudaryconditions (qb, h, zb) AssingInitialAndBoundaryCondititon(); // calculate h,q,z at each section of (t+1) time step //h0 = SFM_Initial_h + 0.1; h0 = SFM_Boundary_h - 0.05; constant = 1 / (1 - SFM_Porosity) * (SFM_del_t * 3600 / SFM_del_X); for (j = 0; j <= SFM_Total_Time; j++) { ////h0 = SFM_h[j-1,0] - 0.01; //y1 = 0.3; //y1 = SFM_h[j-1, 0] + 0.1; //x1 = 0.63425; //x1 = k1 / (y1 * y1) + y1 + zb - k1 / (SFM_h[j, i - 1] * SFM_h[j, i - 1]) - SFM_h[j, i - 1] - SFM_zb[j, i - 1] + 0.5 * SFM_del_X * (k2 / (Math.Pow(h0, 3.33)) + k2 / (Math.Pow(SFM_h[j, i - 1], 3.33))); h0 = SFM_Boundary_h - 0.05; /* h_final = SFM_h[j, 0]; * q_final = SFM_qb[j, 0]; * z_final = SFM_zb[j, 0];*/ for (i = 1; i <= SFM_n_Section; i++) { if (j == 0) { h0 = SFM_h[j, i - 1]; } else { h0 = SFM_h[j - 1, i]; } bool SolutionFound = false; iterations = 20000; ///do for (int itr = 1; itr <= iterations; itr++) { /*SFM_h[j, i - 1] = h_final; * SFM_zb[j, i - 1] = z_final; * SFM_qb[j, i - 1] = q_final;*/ if (j == 0) { fx = k1 / (h0 * h0) + h0 + SFM_zb[j, i] - k1 / (SFM_h[j, i - 1] * SFM_h[j, i - 1]) - SFM_h[j, i - 1] - SFM_zb[j, i - 1] + 0.5 * SFM_del_X * (k2 / (Math.Pow(h0, 3.33)) + k2 / (Math.Pow(SFM_h[j, i - 1], 3.33))); qb = (k7 * Math.Pow(h0, -3.495)) * (1 - k8 * Math.Pow(h0, 2.33)) * (1 - k9 * Math.Pow(h0, 1.165)); df_by_dh = -2 * k1 * Math.Pow(h0, -3) + 1 + SFM_del_X * 0.5 * k2 * (-3.33) * Math.Pow(h0, -4.33); } else if (j > 0) { zb = SFM_zb[j - 1, i] - constant * (SFM_qb[j - 1, i] - SFM_qb[j - 1, i - 1]); fx = k1 / (h0 * h0) + h0 + zb - k1 / (SFM_h[j, i - 1] * SFM_h[j, i - 1]) - SFM_h[j, i - 1] - SFM_zb[j, i - 1] + 0.5 * SFM_del_X * (k2 / (Math.Pow(h0, 3.33)) + k2 / (Math.Pow(SFM_h[j, i - 1], 3.33))); qb = (k7 * Math.Pow(h0, -3.495)) * (1 - k8 * Math.Pow(h0, 2.33)) * (1 - k9 * Math.Pow(h0, 1.165)); /*term1 = (-3.495 * Math.Pow(h0, -4.495) * k7) * (1 - k8 * Math.Pow(h0, 2.33)) * (1 - k9 * Math.Pow(h0, 1.165)); * term2 = (k7 * Math.Pow(h0, -3.495)) * (-k8 * 2.33 * Math.Pow(h0, 1.33)) * (1 - k9 * Math.Pow(h0, 1.165)); * term3 = (k7 * Math.Pow(h0, -3.495)) * (1 - k8 * Math.Pow(h0, 2.33)) * (-k9 * 1.165 * Math.Pow(h0, 0.165)); * dq_by_dh = term1 + term2 + term3; * * //dz_by_dh = -1 / (1 - SFM_Porosity) * SFM_del_t * 3600 / SFM_del_X * dq_by_dh; * dz_by_dh = -constant * dq_by_dh;*/ //df_by_dh = -2 * k1 * Math.Pow(h0, -3) + 1 + dz_by_dh + SFM_del_X * 0.5 * k2 * (-3.33) * Math.Pow(h0, -4.33); df_by_dh = -2 * k1 * Math.Pow(h0, -3) + 1 + SFM_del_X * 0.5 * k2 * (-3.33) * Math.Pow(h0, -4.33); } //MessageBox.Show("qb = " + qb + "\nzb = " + zb + "\nfx = " + fx + "\nh0 = " + h0); ///qb = (k7 * Math.Pow(h0, -3.495)) * (1 - k8 * Math.Pow(h0, 2.33)) * (1 - k9 * Math.Pow(h0, 1.165)); //zb = SFM_zb[i, j - 1] - 1 / (1 - SFM_Porosity) * (SFM_del_t * 3600 / SFM_del_X) * (qb - SFM_qb[i - 1, j]); ///zb = SFM_zb[j - 1, i] - 1 / (1 - SFM_Porosity) * (SFM_del_t * 3600 / SFM_del_X) * (qb - SFM_qb[j, i-1]); //MessageBox.Show(k7 + "*" + h0 + "^" + (-3.495) + " = " + k7* Math.Pow(h0, -3.495)); // MessageBox.Show( "qb, i = " + qb + " , " + i + " ; " + 1 + " - " + k9 + " * " + Math.Pow(h0, 2.33) + " = " + (1 - k9 * Math.Pow(h0, 1.165))); //fx = k1 / (h0 * h0) + h0 + zb - k1 / (SFM_h[i - 1, j] * SFM_h[i - 1, j]) - SFM_h[i - 1, j] - SFM_zb[i - 1, j] + 0.5 * SFM_del_X * (k2 / (Math.Pow(h0, 3.33)) + k2 / (Math.Pow(SFM_h[i - 1, j], 3.33))); ///fx = k1 / (h0 * h0) + h0 + zb - k1 / (SFM_h[j, i - 1] * SFM_h[j, i - 1]) - SFM_h[j, i - 1] - SFM_zb[j, i - 1] + 0.5 * SFM_del_X * (k2 / (Math.Pow(h0, 3.33)) + k2 / (Math.Pow(SFM_h[j, i - 1], 3.33))); // derivatives //---------------------------------- /*term1 = (-3.495 * Math.Pow(h0, -4.495) * k7) * (1 - k8 * Math.Pow(h0, 2.33)) * (1 - k9 * Math.Pow(h0, 1.165)); * term2 = (k7 * Math.Pow(h0, -3.495)) * (-k8 * 2.33 * Math.Pow(h0, 1.33)) * (1 - k9 * Math.Pow(h0, 1.165)); * term3 = (k7 * Math.Pow(h0, -3.495)) * (1 - k8 * Math.Pow(h0, 2.33)) * (-k9 * 1.165 * Math.Pow(h0, 0.165)); * dq_by_dh = term1 + term2 + term3; * * //dz_by_dh = -1 / (1 - SFM_Porosity) * SFM_del_t * 3600 / SFM_del_X * dq_by_dh; * dz_by_dh = -constant * dq_by_dh; * * df_by_dh = -2 * k1 * Math.Pow(h0, -3) + 1 + dz_by_dh + SFM_del_X *0.5 * k2 * (-3.33) * Math.Pow(h0, -4.33); *///------------------------------- // MessageBox.Show("i = " + i + "\nqb: " + qb + "\nzb: " + zb + "\nterm1: " +term1 + "\nterm2: " +term2+ "\ndf/dh: " + df_by_dh); // MessageBox.Show("Before h0: " + h0); //Method 2: /* ie_D1 = k2 * (Math.Pow(h0, -3.33)); * //MessageBox.Show(k2 + " * " + h0 + " ^ -3.33" + " = " + k2 * (Math.Pow(h0, -3.33))); * u_st_D1 = k5 * Math.Pow(h0, -1.165); * tau_st_D1 = u_st_D1 * u_st_D1 / k4; * //qb_D1 = k3 * Math.Pow(tau_st_D1, 1.5) * (1 - SFM_Tau_C_Star / tau_st_D1) * (1 - SFM_U_C_Star / u_st_D1); * qb_D1 = (k7 * Math.Pow(h0, -3.495)) * (1 - k8 * Math.Pow(h0, 2.33)) * (1 - k9 * Math.Pow(h0, 1.165)); * MessageBox.Show(i + " " + qb_D1); * zb_D1 = SFM_zb[i, j - 1] - 1 / (1 - SFM_Porosity) * SFM_del_t * 3600/ SFM_del_X * (qb_D1 - SFM_qb[i - 1, j]); * ie_U1 = k2 / Math.Pow(SFM_h[i - 1, j], 3.33); * //f_x = k1 / (h0 * h0) + h0 + zb_D1 - k1/(SFM_h[i - 1, j]* SFM_h[i - 1, j]) - SFM_h[i - 1, j] - SFM_zb[i - 1, j] + SFM_del_X * 0.5 * (ie_D1 + ie_U1); * f_x = k1 / (h0 * h0) + h0 + zb_D1 - k1 / (SFM_h[i - 1, j] * SFM_h[i - 1, j]) - SFM_h[i - 1, j] - SFM_zb[i - 1, j]+ SFM_del_X * 0.5 *k2* (1/(h0*h0) + 1/ (SFM_h[i - 1, j] * SFM_h[i - 1, j])); * du_D1_by_dh = -1.165 * k5 * Math.Pow(h0, -2.165); * dTau_D1_by_dh = 1 / k4 * 2 * u_st_D1 * du_D1_by_dh; * term1 = 1.5 * k3 * Math.Pow(tau_st_D1, 0.5) * dTau_D1_by_dh * (1 - SFM_Tau_C_Star / tau_st_D1) * (1 - SFM_U_C_Star / u_st_D1); * term2 = k3 * Math.Pow(tau_st_D1, 1.5) * (-SFM_Tau_C_Star * (-1) * Math.Pow(tau_st_D1, -2)) * dTau_D1_by_dh * (1 - SFM_U_C_Star / u_st_D1); * term3 = k3 * Math.Pow(tau_st_D1, 1.5) * (1 - SFM_Tau_C_Star / tau_st_D1) * (-SFM_U_C_Star * (-1) * Math.Pow(u_st_D1, -2)) * du_D1_by_dh; * dqb_D1_by_dh = term1 + term2 + term3; * dzb__D1_by_dh = -1 / (1 - SFM_Porosity) * SFM_del_t * 3600 / SFM_del_X * dqb_D1_by_dh; * dfx_by_dh = -2 * k1 * Math.Pow(h0, -3) + 1 + dzb__D1_by_dh + SFM_del_X * 0.5 * k2 * (-3.33 * Math.Pow(h0, -4.33)); */ //MessageBox.Show("qb: " + qb_D1 + "\nzb: " + zb_D1 + "\nie_D1: " + ie_D1 + "\nie_U1: " + ie_U1 + "\ndf/dh: " + dfx_by_dh); //Newton Rapshon's Method //h1 = h0 - f_x / dfx_by_dh; // MessageBox.Show("Just h1: " + h1 + "\nf_x = " + fx + "\nSFM_zb[i - 1, j] = " + SFM_zb[i - 1, j] + "\nsfm_qb[i-1,j] = " + SFM_qb[i - 1, j] + "\nzb_D1 = " + zb); h1 = h0 - fx / df_by_dh; h0 = h1; error = Math.Abs(fx); if (error <= myerr) { if (j == 0) { SFM_h[j, i] = h0; SFM_qb[j, i] = qb; } else if (j > 0) { SFM_h[j, i] = h0; SFM_qb[j, i] = qb; SFM_zb[j, i] = zb; } //SFM_zb[j, i] = zb; SolutionFound = true; break; } /* if(itr ==1) * { * //y1 = h0; * //x1 = fx; * * // h0 = 0.3; * y1 = 0.3; * x1 = 0.63425; * h0 = h0 + 0.1; * } * * error = Math.Abs(fx); * * if(itr > 1) * { * x2 = fx; * y2 = h0; * * y = Math.Abs(y1 + (y2 - y1) / (x2 - x1) * (0 - x1)); * * h0 = y; * x1 = x2; * y1 = y2; * } * * if(error <= myerr) * { * h_final = h0; * q_final = qb; * z_final = zb; * * SFM_h[j, i] = h_final; * SFM_qb[j, i] = q_final; * SFM_zb[j, i] = z_final; * * flag = true; * break; * }*/ //MessageBox.Show("h0: " + h0 + "\nh1: " + h1 + "\nError: " + error); } ///while (error > 0.0005); // SFM_h[i, j] = h1; if (SolutionFound == false) { //MessageBox.Show("Couldn't converge for given number of iteration at t = " + j + "for section onwards: " + i); TxtMsg.Text = TxtMsg.Text + "Couldn't converge for given number of iteration at t = " + j + "for section onwards: " + i; break; } ///SFM_h[j, i] = h1; //SFM_qb[i,j] = (k7 * Math.Pow(SFM_h[i, j], -3.495)) * (1 - k8 * Math.Pow(SFM_h[i, j], 2.33)) * (1 - k9 * Math.Pow(SFM_h[i, j], 1.165)); ///SFM_qb[j, i] = (k7 * Math.Pow(SFM_h[j, i], -3.495)) * (1 - k8 * Math.Pow(SFM_h[j, i], 2.33)) * (1 - k9 * Math.Pow(SFM_h[j, i], 1.165)); //SFM_zb[i,j] = SFM_zb[i, j - 1] - 1 / (1 - SFM_Porosity) * (SFM_del_t / SFM_del_X) * (SFM_qb[i, j] - SFM_qb[i - 1, j]); ///SFM_zb[j, i] = SFM_zb[j - 1,i] - 1 / (1 - SFM_Porosity) * (SFM_del_t / SFM_del_X) * (SFM_qb[j, i] - SFM_qb[j, i - 1]); /* u_st_D1 = k5 * Math.Pow(SFM_h[i,j], -1.165); * tau_st_D1 = u_st_D1 * u_st_D1 / k4; * * SFM_qb[i,j] = k3 * Math.Pow(tau_st_D1, 1.5) * (1 - SFM_Tau_C_Star / tau_st_D1) * (1 - SFM_U_C_Star / u_st_D1); * * zb_D1 = SFM_zb[i, j - 1] - 1 / (1 - SFM_Porosity) * SFM_del_t * 3600 / SFM_del_X * (SFM_qb[i, j] - SFM_qb[i - 1, j]);*/ } } TxtMsg.Text = TxtMsg.Text + "Calculation complete !"; Generaterows(); int index = 0; for (j = 0; j <= SFM_Total_Time; j++) { for (i = 0; i <= SFM_n_Section; i++) { // dataGridViewMusking.Rows[index].Cells[2].Value = SFM_h[i, j].ToString("0.0000"); dataGridViewMusking.Rows[index].Cells[2].Value = SFM_h[j, i].ToString("0.000000"); // dataGridViewMusking.Rows[index].Cells[3].Value = SFM_qb[i, j].ToString("0.0000000"); dataGridViewMusking.Rows[index].Cells[3].Value = SFM_qb[j, i].ToString("E4"); // dataGridViewMusking.Rows[index].Cells[4].Value = SFM_zb[i, j].ToString("0.00000"); //MessageBox.Show("zbdsf " + i + " = " + SFM_zb[0, i]); dataGridViewMusking.Rows[index].Cells[4].Value = SFM_zb[j, i].ToString("0.000000"); Fr = (SFM_Q / (SFM_B * SFM_h[j, i])) / (Math.Sqrt(9.81 * SFM_h[j, i])); dataGridViewMusking.Rows[index].Cells[5].Value = Fr.ToString("0.00000"); index++; } } } catch { } }