コード例 #1
0
ファイル: Calculations.cs プロジェクト: igprog/ppweb
    public MyCalculation GetMyCalculation(ClientsData.NewClientData client)
    {
        MyCalculation x = new MyCalculation();

        try {
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(client.userId, userDataBase))) {
                connection.Open();
                string sql = @"SELECT myRecommendedEnergyIntake, myRecommendedEnergyExpenditure FROM clients WHERE clientId = @ClientId";
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    command.Parameters.Add(new SQLiteParameter("ClientId", client.clientId));
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            int?myRecommendedEnergyIntake      = reader.GetValue(0) == DBNull.Value ? 0 : string.IsNullOrWhiteSpace(reader.GetString(0)) ? 0 : Convert.ToInt32(reader.GetString(0));
                            int?myRecommendedEnergyExpenditure = reader.GetValue(1) == DBNull.Value ? 0 : string.IsNullOrWhiteSpace(reader.GetString(1)) ? 0 : Convert.ToInt32(reader.GetString(1));
                            if (myRecommendedEnergyIntake > 0 || myRecommendedEnergyExpenditure > 0)
                            {
                                x.recommendedEnergyIntake      = myRecommendedEnergyIntake;
                                x.recommendedEnergyExpenditure = myRecommendedEnergyExpenditure;
                            }
                            else
                            {
                                x = GetJsonFile(client.userId, client.clientId); // old sistem: data saved in json file
                            }
                        }
                    }
                }
            }
            return(x);
        } catch (Exception e) {
            L.SendErrorLog(e, client.clientId, client.userId, "Calculations", "GetMyCalculation");
            return(x);
        }
    }
コード例 #2
0
ファイル: Program.cs プロジェクト: sergei2679/CS-PROJECTS
        static void Main(string[] args)
        {
            int           a = 20, b = 10;
            MyCalculation demo = new MyCalculation();

            demo.addition(a, b);
            demo.subtraction(a, b);
            demo.multiplication(a, b);


            Console.ReadLine();
        }
コード例 #3
0
        //private void Calculation(object sender, EventArgs e)
        //{

        //}

        private void button1_Click(object sender, EventArgs e)
        {
            string num1 = textBox1.Text;
            string num2 = textBox2.Text;
            float  resultNum1, resultNum2;
            bool   num1Parse = float.TryParse(num1, out resultNum1);
            bool   num2Parse = float.TryParse(num2, out resultNum2);

            if (num1Parse && num2Parse)
            {
                MyCalculation add = new MyCalculation(Add);
                label1.Text = (add.Invoke(resultNum1, resultNum2).ToString());
            }
            else
            {
                MessageBox.Show("請務必輸入數字!!");
            }
        }
コード例 #4
0
ファイル: Calculations.cs プロジェクト: igprog/ppweb
    public MyCalculation GetJsonFile(string userId, string clientId)
    {
        MyCalculation x = new MyCalculation();

        try {
            string path = string.Format("~/App_Data/users/{0}/clients/{1}/{2}.json", userId, clientId, myCalculation);
            if (File.Exists(Server.MapPath(path)))
            {
                var json = JsonConvert.DeserializeObject <NewCalculation>(File.ReadAllText(Server.MapPath(path)));
                if (json != null)
                {
                    x.recommendedEnergyIntake      = json.recommendedEnergyIntake;
                    x.recommendedEnergyExpenditure = json.recommendedEnergyExpenditure;
                }
            }
            return(x);
        } catch (Exception e) {
            L.SendErrorLog(e, clientId, userId, "Calculations", "GetJsonFile");
            return(x);
        }
    }
コード例 #5
0
ファイル: Calculations.cs プロジェクト: igprog/ppweb
    public void SaveMyCalculation(string userId, string clientId, MyCalculation myCalculation)
    {
        try {
            if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(clientId))
            {
                return;
            }
            string sql = string.Format(@"BEGIN;
                                        UPDATE clients SET myRecommendedEnergyIntake = '{0}', myRecommendedEnergyExpenditure = '{1}' WHERE clientId = '{2}';
                                        COMMIT;", myCalculation.recommendedEnergyIntake, myCalculation.recommendedEnergyExpenditure, clientId);
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, userDataBase))) {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    command.ExecuteNonQuery();
                }
            }

            Files F = new Files();
            F.DeleteClientJsonFile(userId, clientId, "myCalculation");
        } catch (Exception e) {
            L.SendErrorLog(e, clientId, userId, "Calculations", "SaveMyCalculation");
        }
    }
コード例 #6
0
 public static void Main(string[] args)
 {
     Console.WriteLine("Value of PI is: " + MyCalculation.PI);
     Console.WriteLine("Cube of 3 is: " + MyCalculation.cube(3));
 }