private void Cost_TextChanged(object sender, TextChangedEventArgs e) { this.SalaryGrossText.IsEnabled = false; double SalaryGross, PIT; try { SalaryGross = Double.Parse(this.SalaryGrossText.Text); double pension_contribution = Math.Round(SalaryGross * 0.0976, 2); double renta_contribution = Math.Round(SalaryGross * 0.015, 2); double disease_contribution = Math.Round(SalaryGross * 0.0245, 2); this.PensionBox.Text = pension_contribution.ToString(); this.RentaBox.Text = renta_contribution.ToString(); this.DiseaseBox.Text = disease_contribution.ToString(); SalaryGross -= pension_contribution + renta_contribution + disease_contribution; double health_contribution = Math.Round(SalaryGross * 0.09, 2); double health_contribution_income = Math.Round(SalaryGross * 0.0775, 2); // 7,75% this.HealthCareBox.Text = health_contribution.ToString(); SalaryGross -= cost_of_getting_income; SalaryGross = Math.Round(SalaryGross, 0); if (SalaryGross * 12 < 85528) { PIT = Math.Round(Math.Round((SalaryGross) * 0.18, 2) - pit_2 - health_contribution_income, 0); if (PIT < 0) { PIT = 0; } this.Tax_1Box.Text = PIT.ToString(); } else { PIT = SalaryGross; //TODO 32% podatku } SalaryGross = Double.Parse(this.SalaryGrossText.Text); this.SalaryNetText.Text = (SalaryGross - pension_contribution - renta_contribution - disease_contribution - health_contribution - PIT).ToString(); } catch (FormatException) { MessageBox.Show("Popraw dane"); } this.SalaryGrossText.IsEnabled = true; }
public event writecsvdelegate writecsvEvent; //写入数据事件 public void DataAnalysis(byte[] data, int num) //从数据报中解析出有用信息 { if (data[0] == 0xAA && data[1] == 0xAA) //帧头 { if (data[2] == 0X01) { Rol = (short)(((0 ^ data[4]) << 8) ^ data[5]); //将b1赋给s的低8位 Pit = (short)(((0 ^ data[6]) << 8) ^ data[7]); //将b1赋给s的低8位 Yaw = (short)(((0 ^ data[8]) << 8) ^ data[9]); //将b1赋给s的低8位 //WaverolpityawEvent((int)(Rol / 100), (int)(Pit / 100), (int)(Yaw / 100)); } if (data[2] == 0X02) { a_x = (short)(((0 ^ data[4]) << 8) ^ data[5]); a_y = (short)(((0 ^ data[6]) << 8) ^ data[7]); a_z = (short)(((0 ^ data[8]) << 8) ^ data[9]); g_x = (short)(((0 ^ data[10]) << 8) ^ data[11]); g_y = (short)(((0 ^ data[12]) << 8) ^ data[13]); g_z = (short)(((0 ^ data[14]) << 8) ^ data[15]); m_x = (short)(((0 ^ data[16]) << 8) ^ data[17]); m_y = (short)(((0 ^ data[18]) << 8) ^ data[19]); m_z = (short)(((0 ^ data[20]) << 8) ^ data[21]); } if (data[2] == 0X03) { THR = (short)(((0 ^ data[4]) << 8) ^ data[5]); YAW = (short)(((0 ^ data[6]) << 8) ^ data[7]); ROL = (short)(((0 ^ data[8]) << 8) ^ data[9]); PIT = (short)(((0 ^ data[10]) << 8) ^ data[11]); AUX1 = (short)(((0 ^ data[12]) << 8) ^ data[13]); AUX2 = (short)(((0 ^ data[14]) << 8) ^ data[15]); AUX3 = (short)(((0 ^ data[16]) << 8) ^ data[17]); AUX4 = (short)(((0 ^ data[18]) << 8) ^ data[19]); AUX5 = (short)(((0 ^ data[20]) << 8) ^ data[21]); AUX6 = (short)(((0 ^ data[22]) << 8) ^ data[23]); } if (data[2] == 0X07) { Hei = (short)(((0 ^ data[8]) << 8) ^ data[9]); //WaveheightEvent(Hei); } statusshowEvent(Rol, Pit, Yaw); showsensorshowEvent((int)a_x, (int)a_y, (int)a_z, (int)g_x, (int)g_y, (int)g_z, (int)m_x, (int)m_y, (int)m_z); heightshowEvent(Hei); showrecvdataEvent(THR, YAW, ROL, PIT, AUX1, AUX2, AUX3, AUX4, AUX5, AUX6); //WaveAllEvent((int)(Rol / 100), (int)(Pit / 100), (int)(Yaw / 100), Hei, (ROL-1500)/3, (PIT - 1500) / 3, (YAW - 1500) / 3, (THR - 1500) / 3); WaveAllEvent1((int)(Rol / 100), (int)(Pit / 100), (int)(Yaw / 100), Hei, (ROL - 1500) / 3, (PIT - 1500) / 3, (YAW - 1500) / 3, (THR - 1500) / 3); if (writecsvflag == true) { i++; // string fileName = "C:\\Users\\Administrator\\Desktop\\1.csv"; //指定文件保存在 当前项目文件夹中的bin/debug/文件夹中 //// if (!System.IO.File.Exists("C:\\Users\\Administrator\\Desktop\\1.csv")) // StreamWriter sw = new StreamWriter(fileName, true, Encoding.Default); if (i == 1) { ////向文件中输出一行记录 csv文件为逗号分隔符格式文件 同一行中单元格之间用逗号分开 //sw.WriteLine("高度,姓名,年龄"); if (writecsvEvent != null) { writecsvEvent("Rol", "Pit", "Yaw", "Hei", "RCrol", "RCpit", "RCyaw", "RCthr", "TargetHeight"); } } //sw.WriteLine("{0},张三,20", Hei.ToString()); if (writecsvEvent != null) { writecsvEvent(Rol.ToString(), Pit.ToString(), Yaw.ToString(), Hei.ToString(), ROL.ToString(), PIT.ToString(), YAW.ToString(), THR.ToString(), (TargetHeight / 10).ToString()); } } } }