void btnSave_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(view.txtPartNo.Text))
            {
                if (!String.IsNullOrEmpty(view.txtPartName.Text))
                {
                    try
                    {
                        Part part = new Part()
                        {
                            BrandID = brandId,
                            PartNo = view.txtPartNo.Text,
                            PartName = view.txtPartName.Text,
                            Model = view.txtModel.Text,
                            GSP =  Convert.ToDecimal(view.txtGSP.Text),
                            IMSP = Convert.ToDecimal(view.txtIMSP.Text),

                            Status = 1
                        };
                        partModel.createPart(part, user.UserID);
                        view.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("พบข้อผิดผลาด: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else {
                    view.txtPartName.Focus();
                }
            }
            else {
                view.txtPartNo.Focus();
            }
            return;
        }
Exemple #2
0
        public static List<Part> getPartsByBrandIdPartNo(int brandId, string partNo)
        {
            try
            {
                SQLHelper dbhelper = new SQLHelper();

                List<MySqlParameter> lstParameter = new List<MySqlParameter>();
                lstParameter.Add(new MySqlParameter("_BrandID", brandId));
                lstParameter.Add(new MySqlParameter("_PartNo", partNo));

                var resultSet = dbhelper.executeSP<DataSet>(lstParameter, "SelectPartByBrandIdPartNo");

                List<Part> parts = new List<Part>();
                foreach (DataRow drow in resultSet.Tables[0].Rows)
                {
                    Part part = new Part();

                    part.PartID = Convert.ToInt32(drow["partId"].ToString());
                    part.BrandID = Convert.ToInt32(drow["brandId"].ToString());
                    part.PartNo = drow["partno"].ToString();
                    part.PartName = drow["partname"].ToString();
                    part.Model = drow["model"].ToString();
                    part.GSP = Convert.ToDecimal(drow["gsp"].ToString());
                    part.IMSP = Convert.ToDecimal(drow["imsp"].ToString());
                    part.Status = Convert.ToInt32(drow["status"].ToString());
                    part.LocG = drow["locG"].ToString();
                    part.LocIM = drow["locIM"].ToString();
                    part.Comment = drow["comment"].ToString();
                    part.is_new = false;

                    parts.Add(part);
                }

                return parts;
            }
            catch (Exception e)
            {
                throw e;
            }
        }