private void GetFormul(int colorId) { using (SqlConnection dbConnection = DbHelper.GetConnection()) { SqlCommand com = new SqlCommand("GetCodeInfo", dbConnection) { CommandType = CommandType.StoredProcedure }; com.Parameters.AddWithValue("@colorId", colorId); SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); try { da.Fill(ds); DataRow colorInfo = ds.Tables[0].Rows[0]; formulTable = ds.Tables[1]; lblColorCode.Text = colorInfo["Code"].ToString(); lblUnit.Text = colorInfo["Name"].ToString(); lblBase.Text = colorInfo["BaseName"].ToString(); lblMake.Text = colorInfo["Car"].ToString(); lblColorType.Text = colorInfo["Type"].ToString(); lblAccuracy.Text = colorInfo["accuracy"].ToString(); lblUsage.Text = colorInfo["usage"].ToString(); lblLastUpdate.Text = colorInfo["LastUpdate"] is DBNull ? "-" : DbHelper.GregorianToShamsi(DateTime.Parse(colorInfo["LastUpdate"].ToString())); var comment = colorInfo["Comment"].ToString(); if (!string.IsNullOrEmpty(comment)) { lblComment.Text = Regex.Replace(comment, @"(?:\r\n *){1,2} *", "<br>"); } if (formulTable.Rows.Count > 0) { FormulGrid.DataSource = formulTable; FormulGrid.DataBind(); float total = 0; foreach (DataRow drFormul in formulTable.Rows) { total += float.Parse(drFormul["Weight"].ToString()); } lblTotal.Text = lblUnit.Text.Contains("gr") ? string.Format("{0:0.#}", total) : string.Format("{0:0.##}", total); } else { lblMessage.Text = "فرمولی برای این نوع رنگ وارد نشده."; } } catch (Exception ex) { lblMessage.Text = "خطا" + ex.Message; } txtBuildBase.Focus(); } }
protected void rblBase_SelectedIndexChanged(object sender, EventArgs e) { using (SqlConnection dbConnection = DbHelper.GetConnection()) { SqlCommand com = new SqlCommand("GetCodeInfoByUnitId", dbConnection) { CommandType = CommandType.StoredProcedure }; com.Parameters.AddWithValue("@code", lblColorCode.Text); com.Parameters.AddWithValue("@unitId", int.Parse(((ListControl)sender).SelectedValue)); SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); try { da.Fill(ds); formulTable = ds.Tables[0]; if (formulTable.Rows.Count > 0) { FormulGrid.DataSource = formulTable; FormulGrid.DataBind(); float total = 0; foreach (DataRow drFormul in formulTable.Rows) { total += float.Parse(drFormul["Weight"].ToString()); } lblTotal.Text = lblUnit.Text.Contains("gr") ? string.Format("{0:0.#}", total) : string.Format("{0:0.##}", total); } else { lblMessage.Text = "فرمولی برای این نوع رنگ وارد نشده."; } } catch (Exception ex) { lblMessage.Text = "خطا" + ex.Message; } txtBuildBase.Focus(); } }
private void Calculate() { var total = 0f; for (int i = 0; i < formulTable.Rows.Count; i++) { var weitgh = float.Parse(formulTable.Rows[i]["Weight"].ToString()); var buildBase = float.Parse(lblTotal.Text); var newBase = float.Parse(txtBuildBase.Text.Trim()); var newWeight = lblUnit.Text.ToLower().Contains("gr") ? Math.Round(weitgh * newBase / buildBase, 1) : Math.Round(weitgh * newBase / buildBase, 2); formulTable.Rows[i]["Weight"] = newWeight.ToString(); total += float.Parse(formulTable.Rows[i]["Weight"].ToString()); } FormulGrid.DataSource = formulTable; FormulGrid.DataBind(); lblTotal.Text = lblUnit.Text.ToLower().Contains("gr") ? string.Format("{0:0.#}", total) : string.Format("{0:0.##}", total); txtEasyMix.Text = ""; }
private void Mix() { var total = 0f; if (string.IsNullOrEmpty(txtEasyMix.Text.Trim())) { return; } var newValue = float.Parse(txtEasyMix.Text.Trim()); var oldValue = float.Parse(hfSelectedWeight.Value); var rate = newValue / oldValue; for (int i = 0; i < formulTable.Rows.Count; i++) { var newWeight = lblUnit.Text.ToLower().Contains("gr") ? Math.Round(float.Parse(formulTable.Rows[i]["weight"].ToString()) * rate, 1) : Math.Round(float.Parse(formulTable.Rows[i]["weight"].ToString()) * rate, 2); formulTable.Rows[i]["weight"] = newWeight.ToString(); total += float.Parse(formulTable.Rows[i]["weight"].ToString()); } FormulGrid.DataSource = formulTable; FormulGrid.DataBind(); lblTotal.Text = total.ToString(); }